Class: Zyps::SpawnAction

Inherits:
Action
  • Object
show all
Defined in:
lib/zyps/actions.rb

Overview

Copies the given GameObject prototypes into the environment.

Direct Known Subclasses

ExplodeAction, ShootAction

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#environmentObject

Environment to place children into.



276
277
278
# File 'lib/zyps/actions.rb', line 276

def environment
  @environment
end

#prototypesObject

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