zyps 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/bin/zyps +22 -346
  2. data/bin/zyps_demo +116 -188
  3. data/doc/classes/AccelerateAction.html +182 -0
  4. data/doc/classes/{Vector.src/M000006.html → AccelerateAction.src/M000009.html} +5 -5
  5. data/doc/classes/AccelerateAction.src/M000010.html +18 -0
  6. data/doc/classes/Action.html +118 -0
  7. data/doc/classes/AgeCondition.html +181 -0
  8. data/doc/classes/AgeCondition.src/M000039.html +18 -0
  9. data/doc/classes/AgeCondition.src/M000040.html +18 -0
  10. data/doc/classes/ApproachAction.html +189 -0
  11. data/doc/classes/ApproachAction.src/M000048.html +19 -0
  12. data/doc/classes/ApproachAction.src/M000049.html +38 -0
  13. data/doc/classes/Behavior.html +23 -26
  14. data/doc/classes/Behavior.src/{M000003.html → M000001.html} +1 -1
  15. data/doc/classes/Behavior.src/{M000004.html → M000002.html} +2 -2
  16. data/doc/classes/BlendAction.html +181 -0
  17. data/doc/classes/BlendAction.src/M000043.html +18 -0
  18. data/doc/classes/BlendAction.src/M000044.html +18 -0
  19. data/doc/classes/Clock.html +10 -10
  20. data/doc/classes/Clock.src/{M000026.html → M000041.html} +0 -0
  21. data/doc/classes/Clock.src/{M000027.html → M000042.html} +0 -0
  22. data/doc/classes/CollisionCondition.html +148 -0
  23. data/doc/classes/CollisionCondition.src/M000053.html +18 -0
  24. data/doc/classes/Color.html +36 -36
  25. data/doc/classes/Color.src/{M000015.html → M000022.html} +0 -0
  26. data/doc/classes/Color.src/{M000016.html → M000023.html} +0 -0
  27. data/doc/classes/Color.src/{M000017.html → M000024.html} +0 -0
  28. data/doc/classes/Color.src/{M000018.html → M000025.html} +0 -0
  29. data/doc/classes/Color.src/{M000019.html → M000026.html} +0 -0
  30. data/doc/classes/Color.src/{M000020.html → M000027.html} +3 -3
  31. data/doc/classes/Condition.html +118 -0
  32. data/doc/classes/Creature.html +28 -13
  33. data/doc/classes/Creature.src/{M000005.html → M000011.html} +4 -4
  34. data/doc/classes/{Responsive.src/M000030.html → Creature.src/M000012.html} +2 -2
  35. data/doc/classes/DestroyAction.html +181 -0
  36. data/doc/classes/DestroyAction.src/M000030.html +18 -0
  37. data/doc/classes/DestroyAction.src/M000031.html +18 -0
  38. data/doc/classes/EatAction.html +149 -0
  39. data/doc/classes/EatAction.src/M000045.html +21 -0
  40. data/doc/classes/Enclosure.html +206 -0
  41. data/doc/classes/Enclosure.src/M000005.html +18 -0
  42. data/doc/classes/Enclosure.src/M000006.html +31 -0
  43. data/doc/classes/Environment.html +11 -11
  44. data/doc/classes/Environment.src/{M000028.html → M000046.html} +1 -1
  45. data/doc/classes/Environment.src/{M000029.html → M000047.html} +0 -0
  46. data/doc/classes/EnvironmentalFactor.html +2 -51
  47. data/doc/classes/{Responsive.html → FaceAction.html} +21 -16
  48. data/doc/classes/FaceAction.src/M000052.html +18 -0
  49. data/doc/classes/FleeAction.html +189 -0
  50. data/doc/classes/FleeAction.src/M000054.html +19 -0
  51. data/doc/classes/FleeAction.src/M000055.html +38 -0
  52. data/doc/classes/GameObject.html +47 -21
  53. data/doc/classes/GameObject.src/{M000022.html → M000032.html} +3 -4
  54. data/doc/classes/GameObject.src/M000033.html +16 -0
  55. data/doc/classes/GameObject.src/{M000023.html → M000034.html} +1 -1
  56. data/doc/classes/GameObject.src/{M000024.html → M000035.html} +1 -1
  57. data/doc/classes/GameObject.src/{M000025.html → M000036.html} +1 -1
  58. data/doc/classes/Location.html +5 -5
  59. data/doc/classes/Location.src/{M000014.html → M000021.html} +1 -1
  60. data/doc/classes/ProximityCondition.html +182 -0
  61. data/doc/classes/ProximityCondition.src/M000037.html +18 -0
  62. data/doc/classes/ProximityCondition.src/M000038.html +18 -0
  63. data/doc/classes/TagAction.html +181 -0
  64. data/doc/classes/{EnvironmentalFactor.src/M000021.html → TagAction.src/M000028.html} +4 -4
  65. data/doc/classes/TagAction.src/M000029.html +18 -0
  66. data/doc/classes/TagCondition.html +181 -0
  67. data/doc/classes/TagCondition.src/M000007.html +18 -0
  68. data/doc/classes/TagCondition.src/M000008.html +18 -0
  69. data/doc/classes/TrailsView.html +13 -21
  70. data/doc/classes/TrailsView.src/{M000001.html → M000003.html} +3 -3
  71. data/doc/classes/TrailsView.src/{M000002.html → M000004.html} +4 -2
  72. data/doc/classes/TurnAction.html +182 -0
  73. data/doc/classes/TurnAction.src/M000050.html +19 -0
  74. data/doc/classes/TurnAction.src/M000051.html +18 -0
  75. data/doc/classes/Utility.html +48 -48
  76. data/doc/classes/Utility.src/{M000031.html → M000056.html} +0 -0
  77. data/doc/classes/Utility.src/{M000032.html → M000057.html} +0 -0
  78. data/doc/classes/Utility.src/{M000033.html → M000058.html} +0 -0
  79. data/doc/classes/Utility.src/{M000034.html → M000059.html} +0 -0
  80. data/doc/classes/Utility.src/{M000035.html → M000060.html} +0 -0
  81. data/doc/classes/Utility.src/{M000036.html → M000061.html} +0 -0
  82. data/doc/classes/Utility.src/M000062.html +21 -0
  83. data/doc/classes/Vector.html +41 -41
  84. data/doc/classes/Vector.src/M000013.html +5 -11
  85. data/doc/classes/Vector.src/{M000007.html → M000014.html} +0 -0
  86. data/doc/classes/Vector.src/{M000008.html → M000015.html} +0 -0
  87. data/doc/classes/Vector.src/{M000009.html → M000016.html} +0 -0
  88. data/doc/classes/Vector.src/{M000010.html → M000017.html} +0 -0
  89. data/doc/classes/Vector.src/{M000011.html → M000018.html} +0 -0
  90. data/doc/classes/Vector.src/{M000012.html → M000019.html} +0 -0
  91. data/doc/classes/Vector.src/M000020.html +25 -0
  92. data/doc/created.rid +1 -1
  93. data/doc/files/COPYING_LESSER_txt.html +1 -1
  94. data/doc/files/COPYING_txt.html +1 -1
  95. data/doc/files/README_txt.html +1 -1
  96. data/doc/files/lib/zyps/actions_rb.html +134 -0
  97. data/doc/files/lib/zyps/conditions_rb.html +134 -0
  98. data/doc/files/lib/zyps/environmental_factors_rb.html +134 -0
  99. data/doc/files/lib/zyps/views/trails_rb.html +1 -1
  100. data/doc/files/lib/zyps_rb.html +1 -1
  101. data/doc/fr_class_index.html +16 -1
  102. data/doc/fr_file_index.html +3 -0
  103. data/doc/fr_method_index.html +62 -37
  104. data/doc/index.html +2 -2
  105. data/lib/zyps.rb +46 -47
  106. data/lib/zyps/actions.rb +186 -0
  107. data/lib/zyps/conditions.rb +69 -0
  108. data/lib/zyps/environmental_factors.rb +55 -0
  109. data/lib/zyps/views/trails.rb +6 -6
  110. data/test/test_zyps.rb +159 -69
  111. data/test/zyps/test_actions.rb +183 -0
  112. data/test/zyps/test_conditions.rb +83 -0
  113. data/test/zyps/test_environmental_factors.rb +88 -0
  114. metadata +137 -75
  115. data/doc/classes/Utility.src/M000037.html +0 -22
@@ -0,0 +1,69 @@
1
+ # Copyright 2007 Jay McGavren, jay@mcgavren.com.
2
+ #
3
+ # This file is part of Zyps.
4
+ #
5
+ # Zyps is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation; either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'zyps'
19
+
20
+
21
+ #Act only on objects with the correct tag.
22
+ class TagCondition < Condition
23
+ #The tag to look for on the target.
24
+ attr_accessor :tag
25
+ def initialize(tag)
26
+ self.tag = tag
27
+ end
28
+ #True if the target has the assigned tag.
29
+ def test(actor, target)
30
+ target.tags.include?(@tag)
31
+ end
32
+ end
33
+
34
+
35
+ #Act only on objects older than the given age.
36
+ class AgeCondition < Condition
37
+ #The minimum age in seconds.
38
+ attr_accessor :age
39
+ def initialize(age)
40
+ self.age = age
41
+ end
42
+ #True if the target is older than the assigned age.
43
+ def test(actor, target)
44
+ target.age > @age
45
+ end
46
+ end
47
+
48
+
49
+ #Act only on objects closer than the given distance.
50
+ class ProximityCondition < Condition
51
+ #The maximum number of units away the target can be.
52
+ attr_accessor :distance
53
+ def initialize(distance)
54
+ self.distance = distance
55
+ end
56
+ #True if the actor and target are equal to or closer than the given distance.
57
+ def test(actor, target)
58
+ Utility.find_distance(actor.location, target.location) <= @distance
59
+ end
60
+ end
61
+
62
+
63
+ #True only if collided with target.
64
+ class CollisionCondition < Condition
65
+ #True if the objects have collided.
66
+ def test(actor, target)
67
+ Utility.collided?(actor, target)
68
+ end
69
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright 2007 Jay McGavren, jay@mcgavren.com.
2
+ #
3
+ # This file is part of Zyps.
4
+ #
5
+ # Zyps is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation; either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require 'zyps'
19
+
20
+
21
+ #Keeps all objects within a set of walls.
22
+ class Enclosure < EnvironmentalFactor
23
+
24
+ #X coordinate of left boundary.
25
+ attr_accessor :left
26
+ #Y coordinate of top boundary.
27
+ attr_accessor :top
28
+ #X coordinate of right boundary.
29
+ attr_accessor :right
30
+ #Y coordinate of bottom boundary.
31
+ attr_accessor :bottom
32
+ def initialize(left = 0, top = 0, right = 0, bottom = 0)
33
+ self.left, self.top, self.right, self.bottom = left, top, right, bottom
34
+ end
35
+ #If object is beyond a boundary, set its position equal to the boundary and reflect it.
36
+ def act(object)
37
+ if (object.location.x < @left) then
38
+ object.location.x = @left
39
+ object.vector.pitch = Utility.find_reflection_angle(90, object.vector.pitch)
40
+ elsif (object.location.x > @right) then
41
+ object.location.x = @right
42
+ object.vector.pitch = Utility.find_reflection_angle(270, object.vector.pitch)
43
+ end
44
+ if (object.location.y > @top) then
45
+ object.location.y = @top
46
+ object.vector.pitch = Utility.find_reflection_angle(0, object.vector.pitch)
47
+ elsif (object.location.y < @bottom) then
48
+ object.location.y = @bottom
49
+ object.vector.pitch = Utility.find_reflection_angle(180, object.vector.pitch)
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+
@@ -28,12 +28,10 @@ class TrailsView
28
28
  attr_reader :width, :height
29
29
  #Number of line segments to draw for each object.
30
30
  attr_accessor :trail_length
31
- #Width of the trail behind each object.
32
- attr_accessor :trail_width
33
31
 
34
- def initialize (width = 600, height = 400, trail_length = 5, trail_width = trail_length)
32
+ def initialize (width = 600, height = 400, trail_length = 5)
35
33
 
36
- @width, @height, @trail_length, @trail_width = width, height, trail_length, trail_width
34
+ @width, @height, @trail_length, = width, height, trail_length
37
35
 
38
36
  #Create a drawing area.
39
37
  @canvas = Gtk::DrawingArea.new
@@ -69,7 +67,7 @@ class TrailsView
69
67
  #Takes an Environment, and draws it to the canvas.
70
68
  #Tracks the position of each GameObject over time so it can draw a trail behind it.
71
69
  #The head will match the object's Color exactly, fading to black at the tail.
72
- #trail_width will be used as the line thickness at the object's head, diminishing to 1 at the tail.
70
+ #GameObject.size will be used as the line thickness at the object's head, diminishing to 1 at the tail.
73
71
  def update(environment)
74
72
 
75
73
  #Clear the background on the buffer.
@@ -85,6 +83,8 @@ class TrailsView
85
83
  #For each GameObject in the environment:
86
84
  environment.objects.each do |object|
87
85
 
86
+ object_radius = Math.sqrt(object.size / Math::PI)
87
+
88
88
  #Add the object's current location to the list.
89
89
  @locations[object.identifier] << [object.location.x, object.location.y]
90
90
  #If the list is larger than the number of tail segments, delete the first position.
@@ -108,7 +108,7 @@ class TrailsView
108
108
 
109
109
  #Multiply the actual drawing width by the current multiplier to get the current drawing width.
110
110
  graphics_context.set_line_attributes(
111
- (@trail_width * multiplier).ceil,
111
+ (object_radius * 2 * multiplier).ceil,
112
112
  Gdk::GC::LINE_SOLID,
113
113
  Gdk::GC::CAP_ROUND, #Line ends drawn as semicircles.
114
114
  Gdk::GC::JOIN_MITER #Only used for polygons.
data/test/test_zyps.rb CHANGED
@@ -20,9 +20,33 @@ require 'zyps'
20
20
  require 'test/unit'
21
21
 
22
22
 
23
+ #Redefine Clock to return a predictable time.
24
+ class Clock
25
+ def elapsed_time; 0.1; end
26
+ end
27
+
28
+
23
29
  class TestGameObject < Test::Unit::TestCase
24
30
 
25
31
 
32
+ def test_constraints
33
+ #Test at initialization.
34
+ object = GameObject.new(
35
+ "", #Name.
36
+ Location.new,
37
+ Color.new,
38
+ Vector.new,
39
+ 0,
40
+ -1 #Size.
41
+ )
42
+ assert_equal(0, object.size)
43
+ #Test accessors.
44
+ object = GameObject.new
45
+ object.size = -1
46
+ assert_equal(0, object.size)
47
+ end
48
+
49
+
26
50
  def test_move
27
51
  #Set up moving object.
28
52
  object = GameObject.new
@@ -53,7 +77,7 @@ class TestCreature < Test::Unit::TestCase
53
77
  assert_equal(0, creature.vector.speed)
54
78
  assert_equal(0, creature.vector.pitch)
55
79
  assert_equal(nil, creature.name)
56
- assert_in_delta(0, creature.age, 0.1)
80
+ assert_equal(1, creature.size)
57
81
  assert_equal([], creature.tags)
58
82
  assert_equal([], creature.behaviors)
59
83
  #Identifiers should be unique.
@@ -69,6 +93,7 @@ class TestCreature < Test::Unit::TestCase
69
93
  Color.new(0.5, 0.6, 0.7),
70
94
  Vector.new(1.5, 225),
71
95
  2.001, #Age.
96
+ 5.0, #Size.
72
97
  ["predator", "blue team"],
73
98
  [behavior]
74
99
  )
@@ -80,7 +105,7 @@ class TestCreature < Test::Unit::TestCase
80
105
  assert_equal(0.7, creature.color.blue)
81
106
  assert_equal(1.5, creature.vector.speed)
82
107
  assert_equal(225, creature.vector.pitch)
83
- assert_in_delta(2.001, creature.age, 0.01)
108
+ assert_equal(5.0, creature.size)
84
109
  assert(creature.tags.include?("predator"))
85
110
  assert(creature.tags.include?("blue team"))
86
111
  assert(creature.behaviors.include?(behavior))
@@ -93,77 +118,103 @@ end
93
118
 
94
119
  class TestEnvironment < Test::Unit::TestCase
95
120
 
121
+
96
122
  def setup
97
123
 
98
- #Interactions will be logged here.
99
- @interactions = []
100
-
101
- #Create creatures.
102
- creature1 = Creature.new('1')
103
- creature2 = Creature.new('2')
104
- creature_behavior = Behavior.new
105
- creature_behavior.actions << lambda {|creature, target| @interactions << "#{creature.name} targeting #{target.name}"}
106
- creature1.behaviors << creature_behavior
107
- creature2.behaviors << creature_behavior
108
-
109
- #Create an environment and add the creatures.
110
- @environment = Environment.new([creature1, creature2])
124
+ #Create an environment and add creatures.
125
+ @environment = Environment.new
126
+ @environment.objects << Creature.new('1')
127
+ @environment.objects << Creature.new('2')
111
128
 
112
129
  end
113
130
 
114
131
 
132
+ #An action that keeps a log of the actor and target.
133
+ class LogAction < Action
134
+ attr_reader :interactions
135
+ def initialize
136
+ #Interactions will be logged here.
137
+ @interactions = []
138
+ end
139
+ def do(actor, target)
140
+ #Log the interaction.
141
+ @interactions << "#{actor.name} targeting #{target.name}"
142
+ end
143
+ end
144
+
115
145
  def test_interactions
116
146
 
147
+ #Set up behavior that will log interactions.
148
+ behavior = Behavior.new
149
+ log = LogAction.new
150
+ behavior.actions << log
151
+ @environment.objects.each {|creature| creature.behaviors << behavior}
152
+
117
153
  #Have environment elements interact.
118
154
  @environment.interact
119
155
 
120
156
  #Look for expected interactions (each should only occur once).
121
- assert(@interactions.find_all{|i| i == "2 targeting 1"}.length == 1)
122
- assert(@interactions.find_all{|i| i == "1 targeting 2"}.length == 1)
123
- assert(@interactions.find_all{|i| i == "1 targeting 1"}.length == 0)
124
- assert(@interactions.find_all{|i| i == "2 targeting 2"}.length == 0)
157
+ assert(log.interactions.find_all{|i| i == "2 targeting 1"}.length == 1)
158
+ assert(log.interactions.find_all{|i| i == "1 targeting 2"}.length == 1)
159
+ assert(log.interactions.find_all{|i| i == "1 targeting 1"}.length == 0)
160
+ assert(log.interactions.find_all{|i| i == "2 targeting 2"}.length == 0)
125
161
 
126
162
  end
127
163
 
128
164
 
165
+ #An environmental factor that logs its target.
166
+ class LogFactor < EnvironmentalFactor
167
+ attr_reader :interactions
168
+ def initialize
169
+ #Interactions will be logged here.
170
+ @interactions = []
171
+ end
172
+ def act(target)
173
+ #Log the interaction.
174
+ @interactions << "Environment targeting #{target.name}"
175
+ end
176
+ end
177
+
129
178
  def test_environmental_factors
130
179
 
131
180
  #Create an environmental factor.
132
- behavior = Behavior.new
133
- behavior.actions << lambda {|factor, target| @interactions << "Environment targeting #{target.name}"}
134
- @environment.environmental_factors << EnvironmentalFactor.new([behavior])
181
+ logger = LogFactor.new
182
+ @environment.environmental_factors << logger
135
183
 
136
184
  #Have environment elements interact.
137
185
  @environment.interact
138
186
 
139
187
  #Look for expected interactions (each should only occur once).
140
- assert(@interactions.find_all{|i| i == "Environment targeting 1"}.length == 1)
141
- assert(@interactions.find_all{|i| i == "Environment targeting 2"}.length == 1)
188
+ assert(logger.interactions.find_all{|i| i == "Environment targeting 1"}.length == 1)
189
+ assert(logger.interactions.find_all{|i| i == "Environment targeting 2"}.length == 1)
142
190
 
143
191
  end
144
192
 
145
193
 
194
+ #A condition that is false unless actor and target have specific names.
195
+ class NameCondition < Condition
196
+ def test(actor, target)
197
+ return true if actor.name == '1' and target.name == '2'
198
+ end
199
+ end
200
+
146
201
  def test_conditions
147
202
 
148
- #Change behaviors to only occur if the target's name is '2'.
149
- @environment.objects.each do |creature|
150
- behavior = Behavior.new
151
- behavior.conditions << lambda do |creature, target|
152
- return true if creature.name == '1' and target.name == '2'
153
- end
154
- behavior.actions << lambda do |creature, target|
155
- @interactions << "#{creature.name} is targeting #{target.name}"
156
- end
157
- creature.behaviors << behavior
158
- end
159
-
203
+ #Set up behavior that will log interactions.
204
+ behavior = Behavior.new
205
+ log = LogAction.new
206
+ behavior.actions << log
207
+ name_checker = NameCondition.new
208
+ behavior.conditions << name_checker
209
+ @environment.objects.each {|creature| creature.behaviors << behavior}
210
+
160
211
  #Have environment elements interact.
161
212
  @environment.interact
162
213
 
163
- #Creature '1' should not have been acted on.
164
- assert(@interactions.find_all{|i| i == "2 is targeting 1"}.length == 0)
165
- #Creature '2' *should* have been acted on.
166
- assert(@interactions.find_all{|i| i == "1 is targeting 2"}.length == 1)
214
+ #Creature '1' should NOT have been acted on.
215
+ assert(log.interactions.find_all{|i| i == "2 targeting 1"}.length == 0)
216
+ #Creature '2' SHOULD have been acted on.
217
+ assert(log.interactions.find_all{|i| i == "1 targeting 2"}.length == 1)
167
218
 
168
219
  end
169
220
 
@@ -172,6 +223,53 @@ end
172
223
 
173
224
 
174
225
 
226
+ class TestColor < Test::Unit::TestCase
227
+
228
+ def test_default_initialization
229
+ color = Color.new
230
+ assert_equal(1, color.red)
231
+ assert_equal(1, color.green)
232
+ assert_equal(1, color.blue)
233
+ end
234
+
235
+ def test_explicit_initialization
236
+ color = Color.new(0.25, 0.5, 0.75)
237
+ assert_equal(0.25, color.red)
238
+ assert_equal(0.5, color.green)
239
+ assert_equal(0.75, color.blue)
240
+ end
241
+
242
+ def test_constraints
243
+ #Test at initialization.
244
+ color = Color.new(-1, -1, -1)
245
+ assert_equal(0, color.red)
246
+ assert_equal(0, color.green)
247
+ assert_equal(0, color.blue)
248
+ color = Color.new(2, 2, 2)
249
+ assert_equal(1, color.red)
250
+ assert_equal(1, color.green)
251
+ assert_equal(1, color.blue)
252
+ #Test accessors.
253
+ color = Color.new
254
+ color.red = -1
255
+ assert_equal(0, color.red)
256
+ color.red = 2
257
+ assert_equal(1, color.red)
258
+ color.green = -1
259
+ assert_equal(0, color.green)
260
+ color.green = 2
261
+ assert_equal(1, color.green)
262
+ color.blue = -1
263
+ assert_equal(0, color.blue)
264
+ color.blue = 2
265
+ assert_equal(1, color.blue)
266
+ end
267
+
268
+
269
+ end
270
+
271
+
272
+
175
273
  class TestVector < Test::Unit::TestCase
176
274
 
177
275
 
@@ -270,23 +368,6 @@ end
270
368
 
271
369
 
272
370
 
273
- class TestClock < Test::Unit::TestCase
274
-
275
-
276
- def test_elapsed_time
277
-
278
- #Create a clock, wait a moment, then see how much time has elapsed since its creation.
279
- clock = Clock.new
280
- sleep 0.1
281
- assert_in_delta(0.1, clock.elapsed_time, 0.02)
282
-
283
- end
284
-
285
-
286
- end
287
-
288
-
289
-
290
371
  class TestUtility < Test::Unit::TestCase
291
372
 
292
373
 
@@ -342,18 +423,27 @@ class TestUtility < Test::Unit::TestCase
342
423
  end
343
424
 
344
425
 
345
- def test_inside_box?
346
- #Too far left.
347
- assert(! Utility.inside_box?(Location.new(1, 3), Location.new(2, 2), Location.new(4, 4)))
348
- #Too far right.
349
- assert(! Utility.inside_box?(Location.new(5, 3), Location.new(2, 2), Location.new(4, 4)))
350
- #Too far up.
351
- assert(! Utility.inside_box?(Location.new(3, 1), Location.new(2, 2), Location.new(4, 4)))
352
- #Too far down.
353
- assert(! Utility.inside_box?(Location.new(3, 5), Location.new(2, 2), Location.new(4, 4)))
354
- #Inside.
355
- assert(Utility.inside_box?(Location.new(3, 3), Location.new(2, 2), Location.new(4, 4)))
426
+ def test_collided?
427
+ #Objects apart.
428
+ assert(! Utility.collided?(
429
+ GameObject.new("", Location.new(0, 0), Color.new, Vector.new, 0, 0.196), #Radius = 0.25
430
+ GameObject.new("", Location.new(1, 0), Color.new, Vector.new, 0, 0.196)
431
+ ))
432
+ #Objects touching (not a collision).
433
+ assert(! Utility.collided?(
434
+ GameObject.new("", Location.new(0, 0), Color.new, Vector.new, 0, 0.785), #Radius = 0.5
435
+ GameObject.new("", Location.new(1, 0), Color.new, Vector.new, 0, 0.785)
436
+ ))
437
+ #Objects collided.
438
+ assert(Utility.collided?(
439
+ GameObject.new("", Location.new(0, 0), Color.new, Vector.new, 0, 1.766), #Radius = 0.75
440
+ GameObject.new("", Location.new(1, 0), Color.new, Vector.new, 0, 1.766)
441
+ ))
442
+ #Objects in same place.
443
+ assert(Utility.collided?(
444
+ GameObject.new("", Location.new(0, 0)),
445
+ GameObject.new("", Location.new(0, 0))
446
+ ))
356
447
  end
357
-
358
448
 
359
449
  end