Skip to content

Instantly share code, notes, and snippets.

@takaokouji
Created January 8, 2011 03:58
Show Gist options
  • Select an option

  • Save takaokouji/770531 to your computer and use it in GitHub Desktop.

Select an option

Save takaokouji/770531 to your computer and use it in GitHub Desktop.
Ruby study for Matsue(Japan) junior high school before afternoon.
----- main.rb
require 'dxruby'
require './player'
player = Player.new
Window.loop do
break if Input.keyPush?(K_ESCAPE)
player.move
player.draw
end
----- player.rb
class Player
def initialize
@player_img = Image.load("player.png")
@x = 100
@y = 50
@right_end = Window.width - @player_img.width
@bottom_end = Window.height - @player_img.height
end
def move
@x += Input.x
@y += Input.y
@x = 0 if @x < 0
@y = 0 if @y < 0
@x = @right_end if @x > @right_end
@y = @bottom_end if @y > @bottom_end
end
def draw
Window.draw(@x, @y, @player_img)
end
end
----- to run
run cmd.exe
> cd path¥to¥dir_include_main.rb
> ruby main.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment