Class: RGame::Engine::Components::PlayerController

Inherits:
RGame::Engine::Component show all
Defined in:
lib/rgame/engine/components/player_controller.rb

Overview

Drives a CharacterBody sibling from two input axes — direct 8-way walking, no inertia (unlike ThrustController). Each frame it copies the axis snapshot into the body's movement intent; the body does the collision-checked move.

Instance Attribute Summary

Attributes inherited from RGame::Engine::Component

#node

Instance Method Summary collapse

Methods inherited from RGame::Engine::Component

#context, #draw, #on_detach, #sweep_freed, #update

Methods included from Signal::DSL

#signal

Constructor Details

#initialize(x_axis: :move_x, y_axis: :move_y) ⇒ PlayerController

Returns a new instance of PlayerController.



10
11
12
13
14
# File 'lib/rgame/engine/components/player_controller.rb', line 10

def initialize(x_axis: :move_x, y_axis: :move_y)
  super()
  @x_axis = x_axis
  @y_axis = y_axis
end

Instance Method Details

#control(actions) ⇒ Object



18
19
20
# File 'lib/rgame/engine/components/player_controller.rb', line 18

def control(actions)
  @body.set_intent(actions.axis(@x_axis), actions.axis(@y_axis))
end

#on_attachObject



16
# File 'lib/rgame/engine/components/player_controller.rb', line 16

def on_attach = @body = node.get_component(CharacterBody)