class Dare::Sprite
Attributes
images[RW]
state[RW]
Public Class Methods
new(window = Dare.default_canvas)
click to toggle source
# File lib/dare/sprite.rb, line 4 def initialize(window = Dare.default_canvas) @window = window @images = [] @state = Hash.new {|h,k| h[k] = Dare::AnimationState.new} @current_image = 0 @ticks_on_current_image = 0 @x = 0 @y = 0 end
Public Instance Methods
draw(x = 0, y = 0)
click to toggle source
# File lib/dare/sprite.rb, line 14 def draw(x = 0, y = 0) @images[@current_image].draw(x, y) end
stand()
click to toggle source
# File lib/dare/sprite.rb, line 54 def stand @current_image = 0 @ticks_on_current_image = 0 end
update()
click to toggle source
# File lib/dare/sprite.rb, line 18 def update if @window.button_down? Dare::KbRight walk else stand end end
walk()
click to toggle source
# File lib/dare/sprite.rb, line 26 def walk if @current_image == 0 @current_image = 2 @ticks_on_current_image = 0 elsif @current_image == 2 if @ticks_on_current_image >= 5 @current_image = 3 @ticks_on_current_image = 0 else @ticks_on_current_image += 1 end elsif @current_image == 3 if @ticks_on_current_image >= 5 @current_image = 4 @ticks_on_current_image = 0 else @ticks_on_current_image += 1 end elsif @current_image == 4 if @ticks_on_current_image >= 5 @current_image = 2 @ticks_on_current_image = 0 else @ticks_on_current_image += 1 end end end