Skip to content

Instantly share code, notes, and snippets.

@kaeff
Created June 23, 2015 15:51
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 kaeff/5da3d7c03ef57dd0ec5f to your computer and use it in GitHub Desktop.
Save kaeff/5da3d7c03ef57dd0ec5f to your computer and use it in GitHub Desktop.
require 'gosu'
# The game skeleton we built on 16.6. - A ball moving right to left and back, slowly invading the bottom of the screen...
class GameWindow < Gosu::Window
def initialize
super(640, 480)
self.caption = "Gosu Tutorial Game (Interval: #{self.update_interval})"
@ball = Gosu::Image.new('media/ball.png')
@x = 0
@y = 0
@scale = 5
@velocity_x = 5
end
def update
# move ball
@x = @x + @velocity_x
# turn left
if @x > self.width-@ball.width * @scale or @x < 0
# go down one
@y = @y + 1 * @ball.height * @scale
# change direction
@velocity_x = @velocity_x * -1
end
end
def draw
@ball.draw(@x, @y, 0, @scale, @scale)
end
end
window = GameWindow.new
window.show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment