Class: Zyps::Creature
- Inherits:
-
GameObject
- Object
- GameObject
- Zyps::Creature
- Defined in:
- lib/zyps.rb
Overview
A Creature is a GameObject that can sense and respond to other GameObjects (including other Creature objects).
Instance Attribute Summary collapse
-
#behaviors ⇒ Object
A list of Behavior objects that determine the creature’s response to its environment.
Attributes inherited from GameObject
#color, #identifier, #location, #name, #size, #tags, #vector
Instance Method Summary collapse
-
#act(targets) ⇒ Object
Performs all assigned behaviors on the targets.
-
#copy ⇒ Object
Make a deep copy.
-
#initialize(options = {}) ⇒ Creature
constructor
Identical to the GameObject constructor, except that it also takes a list of Behavior objects.
Methods inherited from GameObject
Constructor Details
#initialize(options = {}) ⇒ Creature
Identical to the GameObject constructor, except that it also takes a list of Behavior objects. Takes a hash with these keys and defaults: :name => nil :location => Location.new :color => Color.new :vector => Vector.new :age => 0 :size => 1 :tags => [] :behaviors => []
217 218 219 220 221 222 223 |
# File 'lib/zyps.rb', line 217 def initialize ( = {}) = { :behaviors => [] }.merge() super self.behaviors = [:behaviors] end |
Instance Attribute Details
#behaviors ⇒ Object
A list of Behavior objects that determine the creature’s response to its environment.
205 206 207 |
# File 'lib/zyps.rb', line 205 def behaviors @behaviors end |
Instance Method Details
#act(targets) ⇒ Object
Performs all assigned behaviors on the targets.
235 236 237 |
# File 'lib/zyps.rb', line 235 def act(targets) behaviors.each {|behavior| behavior.perform(self, targets)} end |
#copy ⇒ Object
Make a deep copy.
226 227 228 229 230 231 232 |
# File 'lib/zyps.rb', line 226 def copy copy = super #Make deep copy of each behavior. copy.behaviors = [] @behaviors.each {|behavior| copy.behaviors << behavior.copy} copy end |