Skip to content

Instantly share code, notes, and snippets.

Created October 4, 2015 14:36
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 anonymous/8bde45386d90fd4635f1 to your computer and use it in GitHub Desktop.
Save anonymous/8bde45386d90fd4635f1 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'gosu'
class Ball
def initialize(the_window)
@x = 200
@vx = 5
@y = 200
@w = 20
@h = 20
@image = Gosu::Image.new(the_window, "gosuTutorialMedia/ball.png", false)
end
def draw
@image.draw(@x, @y, 1)
end
def update
if @x == the_window.width
@vx = -5
end
if @x == 0
@vx = 5
end
@v = @v + @vx
end
end
class GameWindow < Gosu::Window
attr_reader :width, :height
def initialize
@width = 800
@height = 600
super @width, @height, false
self.caption = "Gosu Tutorial Game"
@ball = Ball.new(self)
end
def update
@ball.update
end
def draw
@ball.draw
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