Skip to content

Instantly share code, notes, and snippets.

@gabebw
Created July 17, 2011 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabebw/1087812 to your computer and use it in GitHub Desktop.
Save gabebw/1087812 to your computer and use it in GitHub Desktop.
Ray Pong 3: We have a ball
require 'rubygems'
require 'ray'
WIDTH = 800
HEIGHT = 800
PADDLE_X_OFFSET = 40
PADDLE_WIDTH = 40
BALL_RADIUS = 20
def paddle(paddle_x_coord, paddle_y_coord)
arguments_array = [paddle_x_coord, paddle_y_coord, PADDLE_WIDTH, HEIGHT / 3]
Ray::Polygon.rectangle(arguments_array, Ray::Color.white)
end
def ball
Ray::Polygon.circle([WIDTH/2, HEIGHT/2], BALL_RADIUS, Ray::Color.white)
end
Ray.game 'Pong', :size => [WIDTH, HEIGHT] do
register { add_hook(:quit, method(:exit!)) }
scene :start do
@left_paddle = paddle(PADDLE_X_OFFSET, 100)
@right_paddle = paddle(WIDTH - (PADDLE_X_OFFSET + PADDLE_WIDTH), 100)
@ball = ball
# Exit when q is pressed
on :key_press, key(:q){ exit! }
render do |win|
win.draw @left_paddle
win.draw @right_paddle
win.draw @ball
end
end
scenes << :start
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment