Class: RGame::Engine::Actor
- Inherits:
-
Object
- Object
- RGame::Engine::Actor
- Defined in:
- lib/rgame/engine/actor.rb
Overview
A character in the world. Composes the pieces it owns — a collision box, an animator, a sprite id (the renderer maps it to a sheet), and a controller that decides movement — rather than baking them in. Pure logic; no graphics.
The controller responds to intent(dt, input) -> [ix, iy] with each axis in
[-1, 1]; PlayerController reads input, AI/scripted controllers ignore it.
Instance Attribute Summary collapse
-
#animator ⇒ Object
readonly
Returns the value of attribute animator.
-
#collision_box ⇒ Object
readonly
Returns the value of attribute collision_box.
-
#sprite_id ⇒ Object
readonly
Returns the value of attribute sprite_id.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#frame ⇒ Object
[row, col, flip_x] for the current frame.
-
#initialize(x:, y:, sprite_id:, collision_box:, animator:, controller:, speed: 120.0) ⇒ Actor
constructor
A new instance of Actor.
- #update(dt, collision_system, input) ⇒ Object
Constructor Details
#initialize(x:, y:, sprite_id:, collision_box:, animator:, controller:, speed: 120.0) ⇒ Actor
Returns a new instance of Actor.
15 16 17 18 19 20 21 22 23 |
# File 'lib/rgame/engine/actor.rb', line 15 def initialize(x:, y:, sprite_id:, collision_box:, animator:, controller:, speed: 120.0) @x = x @y = y @sprite_id = sprite_id @collision_box = collision_box @animator = animator @controller = controller @speed = speed end |
Instance Attribute Details
#animator ⇒ Object (readonly)
Returns the value of attribute animator.
13 14 15 |
# File 'lib/rgame/engine/actor.rb', line 13 def animator @animator end |
#collision_box ⇒ Object (readonly)
Returns the value of attribute collision_box.
13 14 15 |
# File 'lib/rgame/engine/actor.rb', line 13 def collision_box @collision_box end |
#sprite_id ⇒ Object (readonly)
Returns the value of attribute sprite_id.
13 14 15 |
# File 'lib/rgame/engine/actor.rb', line 13 def sprite_id @sprite_id end |
#x ⇒ Object
Returns the value of attribute x.
12 13 14 |
# File 'lib/rgame/engine/actor.rb', line 12 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
12 13 14 |
# File 'lib/rgame/engine/actor.rb', line 12 def y @y end |
Instance Method Details
#frame ⇒ Object
[row, col, flip_x] for the current frame.
35 36 37 |
# File 'lib/rgame/engine/actor.rb', line 35 def frame @animator.frame end |
#update(dt, collision_system, input) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/rgame/engine/actor.rb', line 25 def update(dt, collision_system, input) intent_x, intent_y = @controller.intent(dt, input) collision_system.move(self, intent_x * @speed * dt, intent_y * @speed * dt) @animator.play(walk_animation(intent_x, intent_y)) @animator.update(dt) end |