Class: Zyps::SpawnAction
- Inherits:
-
Action
- Object
- Action
- Zyps::SpawnAction
- Defined in:
- lib/zyps/actions.rb
Overview
Copies the given GameObject prototypes into the environment.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#environment ⇒ Object
Environment to place children into.
-
#prototypes ⇒ Object
Array of GameObjects to copy into environment.
Instance Method Summary collapse
-
#do(actor, targets) ⇒ Object
Add children to environment.
-
#generate_child(actor, prototype) ⇒ Object
Copy prototype to actor’s location.
-
#initialize(environment, prototypes = []) ⇒ SpawnAction
constructor
A new instance of SpawnAction.
Constructor Details
#initialize(environment, prototypes = []) ⇒ SpawnAction
Returns a new instance of SpawnAction.
279 280 281 282 |
# File 'lib/zyps/actions.rb', line 279 def initialize(environment, prototypes = []) self.environment = environment self.prototypes = prototypes end |
Instance Attribute Details
#environment ⇒ Object
Environment to place children into.
276 277 278 |
# File 'lib/zyps/actions.rb', line 276 def environment @environment end |
#prototypes ⇒ Object
Array of GameObjects to copy into environment.
278 279 280 |
# File 'lib/zyps/actions.rb', line 278 def prototypes @prototypes end |
Instance Method Details
#do(actor, targets) ⇒ Object
Add children to environment.
284 285 286 287 288 |
# File 'lib/zyps/actions.rb', line 284 def do(actor, targets) prototypes.each do |prototype| environment.objects << generate_child(actor, prototype) end end |
#generate_child(actor, prototype) ⇒ Object
Copy prototype to actor’s location.
290 291 292 293 294 295 |
# File 'lib/zyps/actions.rb', line 290 def generate_child(actor, prototype) #Copy prototype so it can be spawned repeatedly if need be. child = prototype.copy child.location = actor.location.copy child end |