Class: Dare::Sprite
- Inherits:
-
Object
- Object
- Dare::Sprite
- Defined in:
- lib/dare/sprite.rb
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #draw(x = 0, y = 0) ⇒ Object
-
#initialize(window = Dare.default_canvas) ⇒ Sprite
constructor
A new instance of Sprite.
- #stand ⇒ Object
- #update ⇒ Object
- #walk ⇒ Object
Constructor Details
#initialize(window = Dare.default_canvas) ⇒ Sprite
Returns a new instance of Sprite.
4 5 6 7 8 9 10 11 12 |
# 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 |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
3 4 5 |
# File 'lib/dare/sprite.rb', line 3 def images @images end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/dare/sprite.rb', line 3 def state @state end |
Instance Method Details
#draw(x = 0, y = 0) ⇒ Object
14 15 16 |
# File 'lib/dare/sprite.rb', line 14 def draw(x = 0, y = 0) @images[@current_image].draw(x, y) end |
#stand ⇒ Object
54 55 56 57 |
# File 'lib/dare/sprite.rb', line 54 def stand @current_image = 0 @ticks_on_current_image = 0 end |
#update ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/dare/sprite.rb', line 18 def update if @window. Dare::KbRight walk else stand end end |
#walk ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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 |