Created
June 23, 2015 15:51
-
-
Save kaeff/5da3d7c03ef57dd0ec5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 > [email protected] * @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