require 'gosu' class Window < Gosu::Window def initialize super(300, 400, false) @player1 = Player.new(self) end def update if button_down? Gosu::Button::KbLeft @player1.move_left end if button_down? Gosu::Button::KbRight @player1.move_right end if button_down? Gosu::Button::KbUp @player1.move_up end if button_down? Gosu::Button::KbDown @player1.move_down end end def draw @player1.draw end end class Player def initialize(window) @window = window @icon = Gosu::Image.new(@window, "Starfighter.bmp", true) @x = 125 @y = 175 end def move_left @x = @x - 5 if @x < 0 @x = 0 end end def move_right @x = @x + 5 if @x > @window.width - 50 @x = @window.width - 50 end end def move_up @y = @y - 5 if @y < 0 @y = 0 end end def move_down @y = @y + 5 if @y > @window.height - 50 @y = @window.height - 50 end end def draw @icon.draw(@x, @y, 1) end end window = Window.new window.show