Class: Zyps::GameObject
- Inherits:
-
Object
- Object
- Zyps::GameObject
- Defined in:
- lib/zyps.rb
Overview
An object in the virtual environment.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#color ⇒ Object
A Color that will be used to draw the object.
-
#identifier ⇒ Object
A universal identifier for the object.
-
#location ⇒ Object
The object’s Location in space.
-
#name ⇒ Object
A String with the object’s name.
-
#size ⇒ Object
Radius of the object.
-
#tags ⇒ Object
An array of Strings with tags that determine how the object will be treated by Creature and EnvironmentalFactor objects in its environment.
-
#vector ⇒ Object
A Vector with the object’s current speed and direction of travel.
Instance Method Summary collapse
-
#age ⇒ Object
Time since the object was created, in seconds.
- #age=(age) ⇒ Object
-
#copy ⇒ Object
Make a deep copy.
-
#initialize(options = {}) ⇒ GameObject
constructor
Takes a hash with these keys and defaults: :name => nil, :location => Location.new, :color => Color.new, :vector => Vector.new, :age => 0, :size => 1, :tags => [].
-
#move(elapsed_time) ⇒ Object
Move according to vector over the given number of seconds.
Constructor Details
#initialize(options = {}) ⇒ GameObject
Takes a hash with these keys and defaults: :name => nil, :location => Location.new, :color => Color.new, :vector => Vector.new, :age => 0, :size => 1, :tags => []
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/zyps.rb', line 145 def initialize ( = {}) = { :name => nil, :location => Location.new, :color => Color.new, :vector => Vector.new, :age => 0, :size => 1, :tags => [] }.merge() self.name, self.location, self.color, self.vector, self.age, self.size, self. = [:name], [:location], [:color], [:vector], [:age], [:size], [:tags] @identifier = generate_identifier end |
Instance Attribute Details
#color ⇒ Object
A Color that will be used to draw the object.
127 128 129 |
# File 'lib/zyps.rb', line 127 def color @color end |
#identifier ⇒ Object
A universal identifier for the object. Needed for DRb transmission, etc.
123 124 125 |
# File 'lib/zyps.rb', line 123 def identifier @identifier end |
#location ⇒ Object
The object’s Location in space.
125 126 127 |
# File 'lib/zyps.rb', line 125 def location @location end |
#name ⇒ Object
A String with the object’s name.
133 134 135 |
# File 'lib/zyps.rb', line 133 def name @name end |
#size ⇒ Object
Radius of the object.
129 130 131 |
# File 'lib/zyps.rb', line 129 def size @size end |
#tags ⇒ Object
An array of Strings with tags that determine how the object will be treated by Creature and EnvironmentalFactor objects in its environment.
135 136 137 |
# File 'lib/zyps.rb', line 135 def @tags end |
#vector ⇒ Object
A Vector with the object’s current speed and direction of travel.
131 132 133 |
# File 'lib/zyps.rb', line 131 def vector @vector end |
Instance Method Details
#age ⇒ Object
Time since the object was created, in seconds.
181 |
# File 'lib/zyps.rb', line 181 def age; Time.new.to_f - @birth_time; end |
#age=(age) ⇒ Object
182 |
# File 'lib/zyps.rb', line 182 def age=(age); @birth_time = Time.new.to_f - age; end |
#copy ⇒ Object
Make a deep copy.
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/zyps.rb', line 160 def copy copy = self.clone copy.vector = @vector.copy copy.color = @color.copy copy.location = @location.copy copy. = @tags.clone copy.identifier = generate_identifier copy.name = @name ? "Copy of " + @name : nil copy end |
#move(elapsed_time) ⇒ Object
Move according to vector over the given number of seconds.
175 176 177 178 |
# File 'lib/zyps.rb', line 175 def move (elapsed_time) @location.x += @vector.x * elapsed_time @location.y += @vector.y * elapsed_time end |