Class: RGame::Engine::Components::Velocity

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

Overview

Integrates linear and angular velocity into the node's transform each step. Free-moving entities (rocks, bullets) use it alone; a controller component (or the node's own control hook) writes vx/vy/spin as intent. From Body#integrate.

Instance Attribute Summary collapse

Attributes inherited from RGame::Engine::Component

#node

Instance Method Summary collapse

Methods inherited from RGame::Engine::Component

#context, #control, #draw, #on_attach, #on_detach, #sweep_freed

Methods included from Signal::DSL

#signal

Constructor Details

#initialize(vx: 0.0, vy: 0.0, spin: 0.0) ⇒ Velocity

Returns a new instance of Velocity.



12
13
14
15
16
17
# File 'lib/rgame/engine/components/velocity.rb', line 12

def initialize(vx: 0.0, vy: 0.0, spin: 0.0)
  super()
  @vx = vx
  @vy = vy
  @spin = spin
end

Instance Attribute Details

#spinObject

Returns the value of attribute spin.



10
11
12
# File 'lib/rgame/engine/components/velocity.rb', line 10

def spin
  @spin
end

#vxObject

Returns the value of attribute vx.



10
11
12
# File 'lib/rgame/engine/components/velocity.rb', line 10

def vx
  @vx
end

#vyObject

Returns the value of attribute vy.



10
11
12
# File 'lib/rgame/engine/components/velocity.rb', line 10

def vy
  @vy
end

Instance Method Details

#update(dt) ⇒ Object



19
20
21
22
23
# File 'lib/rgame/engine/components/velocity.rb', line 19

def update(dt)
  node.x += @vx * dt
  node.y += @vy * dt
  node.angle += @spin * dt
end