Class: RubyMan::MovingObject
- Inherits:
-
GridObject
- Object
- GameObject
- GridObject
- RubyMan::MovingObject
- Defined in:
- lib/ruby_man/GameObjects/moving_object.rb
Overview
GridObject with the ability to move smoothly in 4 directions
Direct Known Subclasses
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#speed ⇒ Object
Returns the value of attribute speed.
Attributes inherited from GridObject
#depth, #grid_x, #grid_y, #image_angle, #image_index, #image_speed, #solid, #sprite
Attributes inherited from GameObject
Instance Method Summary collapse
- #change_direction(direction) ⇒ Object
- #collision(_other) ⇒ Object
- #direction_free(direction) ⇒ Object
- #grid_step ⇒ Object
-
#initialize ⇒ MovingObject
constructor
A new instance of MovingObject.
- #pixel_x ⇒ Object
- #pixel_y ⇒ Object
- #update(delta) ⇒ Object
Methods inherited from GridObject
#bbox, #distance_to, #draw, #set_pos
Methods inherited from GameObject
#button_down, #created, #destroy, #destroyed, #draw, persistent
Constructor Details
#initialize ⇒ MovingObject
Returns a new instance of MovingObject.
9 10 11 12 13 14 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 9 def initialize super @direction = Direction.none @phase = 0 @speed = 0 end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
7 8 9 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7 def direction @direction end |
#phase ⇒ Object
Returns the value of attribute phase.
7 8 9 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7 def phase @phase end |
#speed ⇒ Object
Returns the value of attribute speed.
7 8 9 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 7 def speed @speed end |
Instance Method Details
#change_direction(direction) ⇒ Object
33 34 35 36 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 33 def change_direction(direction) @direction = direction @image_angle = direction.to_angle end |
#collision(_other) ⇒ Object
30 31 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 30 def collision(_other) end |
#direction_free(direction) ⇒ Object
38 39 40 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 38 def direction_free(direction) @game.place_free(@grid_x + direction.rel_x, @grid_y + direction.rel_y) end |
#grid_step ⇒ Object
27 28 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 27 def grid_step end |
#pixel_x ⇒ Object
42 43 44 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 42 def pixel_x (@grid_x + @direction.rel_x * @phase) * 32 end |
#pixel_y ⇒ Object
46 47 48 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 46 def pixel_y (@grid_y + @direction.rel_y * @phase) * 32 end |
#update(delta) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby_man/GameObjects/moving_object.rb', line 16 def update(delta) super @phase += @speed * delta while @phase > 1 @phase -= 1 @grid_x += @direction.rel_x @grid_y += @direction.rel_y grid_step end end |