Class: RGame::Engine::Components::CircleCollider
- Inherits:
-
RGame::Engine::Component
- Object
- RGame::Engine::Component
- RGame::Engine::Components::CircleCollider
- Defined in:
- lib/rgame/engine/components/circle_collider.rb
Overview
A circular collision shape on a node. It registers itself with the scene's
CollisionWorld system when it enters the tree and unregisters on leaving —
the engine fires both hooks, so a spawned/despawned entity can't leak a
registration. Its world centre is the node's resolved absolute origin; the
layer is an opaque tag the game reads in its on_hit handler to decide what a
contact means (bullet-vs-rock, etc.). See docs/api/systems.md.
Instance Attribute Summary collapse
-
#layer ⇒ Object
readonly
Returns the value of attribute layer.
-
#radius ⇒ Object
radius is writable so a pooled entity (e.g. a multi-tier rock) can retune its shape on reset; CollisionWorld reads it fresh each frame, so no re-registration.
Attributes inherited from RGame::Engine::Component
Instance Method Summary collapse
-
#cx ⇒ Object
World-space centre — the node's resolved absolute origin.
- #cy ⇒ Object
-
#emit_hit(other) ⇒ Object
Called by CollisionWorld on contact (the signal's emit is otherwise private).
-
#initialize(radius:, layer: :default) ⇒ CircleCollider
constructor
A new instance of CircleCollider.
- #on_attach ⇒ Object
- #on_detach ⇒ Object
- #overlap?(other) ⇒ Boolean
Methods inherited from RGame::Engine::Component
#context, #control, #draw, #sweep_freed, #update
Methods included from Signal::DSL
Constructor Details
#initialize(radius:, layer: :default) ⇒ CircleCollider
Returns a new instance of CircleCollider.
22 23 24 25 26 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 22 def initialize(radius:, layer: :default) super() @radius = radius @layer = layer end |
Instance Attribute Details
#layer ⇒ Object (readonly)
Returns the value of attribute layer.
20 21 22 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 20 def layer @layer end |
#radius ⇒ Object
radius is writable so a pooled entity (e.g. a multi-tier rock) can retune its shape on reset; CollisionWorld reads it fresh each frame, so no re-registration.
19 20 21 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 19 def radius @radius end |
Instance Method Details
#cx ⇒ Object
World-space centre — the node's resolved absolute origin.
32 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 32 def cx = node.abs_x |
#cy ⇒ Object
33 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 33 def cy = node.abs_y |
#emit_hit(other) ⇒ Object
Called by CollisionWorld on contact (the signal's emit is otherwise private).
40 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 40 def emit_hit(other) = on_hit_signal.emit(other) |
#on_attach ⇒ Object
28 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 28 def on_attach = node.system(CollisionWorld).register(self) |
#on_detach ⇒ Object
29 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 29 def on_detach = node.system(CollisionWorld)&.unregister(self) |
#overlap?(other) ⇒ Boolean
35 36 37 |
# File 'lib/rgame/engine/components/circle_collider.rb', line 35 def overlap?(other) Engine::CircleCollider.overlap?(cx, cy, @radius, other.cx, other.cy, other.radius) end |