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.
- data/bin/zyps +22 -346
- data/bin/zyps_demo +116 -188
- data/doc/classes/AccelerateAction.html +182 -0
- data/doc/classes/{Vector.src/M000006.html → AccelerateAction.src/M000009.html} +5 -5
- data/doc/classes/AccelerateAction.src/M000010.html +18 -0
- data/doc/classes/Action.html +118 -0
- data/doc/classes/AgeCondition.html +181 -0
- data/doc/classes/AgeCondition.src/M000039.html +18 -0
- data/doc/classes/AgeCondition.src/M000040.html +18 -0
- data/doc/classes/ApproachAction.html +189 -0
- data/doc/classes/ApproachAction.src/M000048.html +19 -0
- data/doc/classes/ApproachAction.src/M000049.html +38 -0
- data/doc/classes/Behavior.html +23 -26
- data/doc/classes/Behavior.src/{M000003.html → M000001.html} +1 -1
- data/doc/classes/Behavior.src/{M000004.html → M000002.html} +2 -2
- data/doc/classes/BlendAction.html +181 -0
- data/doc/classes/BlendAction.src/M000043.html +18 -0
- data/doc/classes/BlendAction.src/M000044.html +18 -0
- data/doc/classes/Clock.html +10 -10
- data/doc/classes/Clock.src/{M000026.html → M000041.html} +0 -0
- data/doc/classes/Clock.src/{M000027.html → M000042.html} +0 -0
- data/doc/classes/CollisionCondition.html +148 -0
- data/doc/classes/CollisionCondition.src/M000053.html +18 -0
- data/doc/classes/Color.html +36 -36
- data/doc/classes/Color.src/{M000015.html → M000022.html} +0 -0
- data/doc/classes/Color.src/{M000016.html → M000023.html} +0 -0
- data/doc/classes/Color.src/{M000017.html → M000024.html} +0 -0
- data/doc/classes/Color.src/{M000018.html → M000025.html} +0 -0
- data/doc/classes/Color.src/{M000019.html → M000026.html} +0 -0
- data/doc/classes/Color.src/{M000020.html → M000027.html} +3 -3
- data/doc/classes/Condition.html +118 -0
- data/doc/classes/Creature.html +28 -13
- data/doc/classes/Creature.src/{M000005.html → M000011.html} +4 -4
- data/doc/classes/{Responsive.src/M000030.html → Creature.src/M000012.html} +2 -2
- data/doc/classes/DestroyAction.html +181 -0
- data/doc/classes/DestroyAction.src/M000030.html +18 -0
- data/doc/classes/DestroyAction.src/M000031.html +18 -0
- data/doc/classes/EatAction.html +149 -0
- data/doc/classes/EatAction.src/M000045.html +21 -0
- data/doc/classes/Enclosure.html +206 -0
- data/doc/classes/Enclosure.src/M000005.html +18 -0
- data/doc/classes/Enclosure.src/M000006.html +31 -0
- data/doc/classes/Environment.html +11 -11
- data/doc/classes/Environment.src/{M000028.html → M000046.html} +1 -1
- data/doc/classes/Environment.src/{M000029.html → M000047.html} +0 -0
- data/doc/classes/EnvironmentalFactor.html +2 -51
- data/doc/classes/{Responsive.html → FaceAction.html} +21 -16
- data/doc/classes/FaceAction.src/M000052.html +18 -0
- data/doc/classes/FleeAction.html +189 -0
- data/doc/classes/FleeAction.src/M000054.html +19 -0
- data/doc/classes/FleeAction.src/M000055.html +38 -0
- data/doc/classes/GameObject.html +47 -21
- data/doc/classes/GameObject.src/{M000022.html → M000032.html} +3 -4
- data/doc/classes/GameObject.src/M000033.html +16 -0
- data/doc/classes/GameObject.src/{M000023.html → M000034.html} +1 -1
- data/doc/classes/GameObject.src/{M000024.html → M000035.html} +1 -1
- data/doc/classes/GameObject.src/{M000025.html → M000036.html} +1 -1
- data/doc/classes/Location.html +5 -5
- data/doc/classes/Location.src/{M000014.html → M000021.html} +1 -1
- data/doc/classes/ProximityCondition.html +182 -0
- data/doc/classes/ProximityCondition.src/M000037.html +18 -0
- data/doc/classes/ProximityCondition.src/M000038.html +18 -0
- data/doc/classes/TagAction.html +181 -0
- data/doc/classes/{EnvironmentalFactor.src/M000021.html → TagAction.src/M000028.html} +4 -4
- data/doc/classes/TagAction.src/M000029.html +18 -0
- data/doc/classes/TagCondition.html +181 -0
- data/doc/classes/TagCondition.src/M000007.html +18 -0
- data/doc/classes/TagCondition.src/M000008.html +18 -0
- data/doc/classes/TrailsView.html +13 -21
- data/doc/classes/TrailsView.src/{M000001.html → M000003.html} +3 -3
- data/doc/classes/TrailsView.src/{M000002.html → M000004.html} +4 -2
- data/doc/classes/TurnAction.html +182 -0
- data/doc/classes/TurnAction.src/M000050.html +19 -0
- data/doc/classes/TurnAction.src/M000051.html +18 -0
- data/doc/classes/Utility.html +48 -48
- data/doc/classes/Utility.src/{M000031.html → M000056.html} +0 -0
- data/doc/classes/Utility.src/{M000032.html → M000057.html} +0 -0
- data/doc/classes/Utility.src/{M000033.html → M000058.html} +0 -0
- data/doc/classes/Utility.src/{M000034.html → M000059.html} +0 -0
- data/doc/classes/Utility.src/{M000035.html → M000060.html} +0 -0
- data/doc/classes/Utility.src/{M000036.html → M000061.html} +0 -0
- data/doc/classes/Utility.src/M000062.html +21 -0
- data/doc/classes/Vector.html +41 -41
- data/doc/classes/Vector.src/M000013.html +5 -11
- data/doc/classes/Vector.src/{M000007.html → M000014.html} +0 -0
- data/doc/classes/Vector.src/{M000008.html → M000015.html} +0 -0
- data/doc/classes/Vector.src/{M000009.html → M000016.html} +0 -0
- data/doc/classes/Vector.src/{M000010.html → M000017.html} +0 -0
- data/doc/classes/Vector.src/{M000011.html → M000018.html} +0 -0
- data/doc/classes/Vector.src/{M000012.html → M000019.html} +0 -0
- data/doc/classes/Vector.src/M000020.html +25 -0
- data/doc/created.rid +1 -1
- data/doc/files/COPYING_LESSER_txt.html +1 -1
- data/doc/files/COPYING_txt.html +1 -1
- data/doc/files/README_txt.html +1 -1
- data/doc/files/lib/zyps/actions_rb.html +134 -0
- data/doc/files/lib/zyps/conditions_rb.html +134 -0
- data/doc/files/lib/zyps/environmental_factors_rb.html +134 -0
- data/doc/files/lib/zyps/views/trails_rb.html +1 -1
- data/doc/files/lib/zyps_rb.html +1 -1
- data/doc/fr_class_index.html +16 -1
- data/doc/fr_file_index.html +3 -0
- data/doc/fr_method_index.html +62 -37
- data/doc/index.html +2 -2
- data/lib/zyps.rb +46 -47
- data/lib/zyps/actions.rb +186 -0
- data/lib/zyps/conditions.rb +69 -0
- data/lib/zyps/environmental_factors.rb +55 -0
- data/lib/zyps/views/trails.rb +6 -6
- data/test/test_zyps.rb +159 -69
- data/test/zyps/test_actions.rb +183 -0
- data/test/zyps/test_conditions.rb +83 -0
- data/test/zyps/test_environmental_factors.rb +88 -0
- metadata +137 -75
- data/doc/classes/Utility.src/M000037.html +0 -22
data/doc/files/lib/zyps_rb.html
CHANGED
data/doc/fr_class_index.html
CHANGED
|
@@ -20,16 +20,31 @@
|
|
|
20
20
|
<div id="index">
|
|
21
21
|
<h1 class="section-bar">Classes</h1>
|
|
22
22
|
<div id="index-entries">
|
|
23
|
+
<a href="classes/AccelerateAction.html">AccelerateAction</a><br />
|
|
24
|
+
<a href="classes/Action.html">Action</a><br />
|
|
25
|
+
<a href="classes/AgeCondition.html">AgeCondition</a><br />
|
|
26
|
+
<a href="classes/ApproachAction.html">ApproachAction</a><br />
|
|
23
27
|
<a href="classes/Behavior.html">Behavior</a><br />
|
|
28
|
+
<a href="classes/BlendAction.html">BlendAction</a><br />
|
|
24
29
|
<a href="classes/Clock.html">Clock</a><br />
|
|
30
|
+
<a href="classes/CollisionCondition.html">CollisionCondition</a><br />
|
|
25
31
|
<a href="classes/Color.html">Color</a><br />
|
|
32
|
+
<a href="classes/Condition.html">Condition</a><br />
|
|
26
33
|
<a href="classes/Creature.html">Creature</a><br />
|
|
34
|
+
<a href="classes/DestroyAction.html">DestroyAction</a><br />
|
|
35
|
+
<a href="classes/EatAction.html">EatAction</a><br />
|
|
36
|
+
<a href="classes/Enclosure.html">Enclosure</a><br />
|
|
27
37
|
<a href="classes/Environment.html">Environment</a><br />
|
|
28
38
|
<a href="classes/EnvironmentalFactor.html">EnvironmentalFactor</a><br />
|
|
39
|
+
<a href="classes/FaceAction.html">FaceAction</a><br />
|
|
40
|
+
<a href="classes/FleeAction.html">FleeAction</a><br />
|
|
29
41
|
<a href="classes/GameObject.html">GameObject</a><br />
|
|
30
42
|
<a href="classes/Location.html">Location</a><br />
|
|
31
|
-
<a href="classes/
|
|
43
|
+
<a href="classes/ProximityCondition.html">ProximityCondition</a><br />
|
|
44
|
+
<a href="classes/TagAction.html">TagAction</a><br />
|
|
45
|
+
<a href="classes/TagCondition.html">TagCondition</a><br />
|
|
32
46
|
<a href="classes/TrailsView.html">TrailsView</a><br />
|
|
47
|
+
<a href="classes/TurnAction.html">TurnAction</a><br />
|
|
33
48
|
<a href="classes/Utility.html">Utility</a><br />
|
|
34
49
|
<a href="classes/Vector.html">Vector</a><br />
|
|
35
50
|
</div>
|
data/doc/fr_file_index.html
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
<a href="files/COPYING_txt.html">COPYING.txt</a><br />
|
|
25
25
|
<a href="files/README_txt.html">README.txt</a><br />
|
|
26
26
|
<a href="files/lib/zyps_rb.html">lib/zyps.rb</a><br />
|
|
27
|
+
<a href="files/lib/zyps/actions_rb.html">lib/zyps/actions.rb</a><br />
|
|
28
|
+
<a href="files/lib/zyps/conditions_rb.html">lib/zyps/conditions.rb</a><br />
|
|
29
|
+
<a href="files/lib/zyps/environmental_factors_rb.html">lib/zyps/environmental_factors.rb</a><br />
|
|
27
30
|
<a href="files/lib/zyps/views/trails_rb.html">lib/zyps/views/trails.rb</a><br />
|
|
28
31
|
</div>
|
|
29
32
|
</div>
|
data/doc/fr_method_index.html
CHANGED
|
@@ -20,43 +20,68 @@
|
|
|
20
20
|
<div id="index">
|
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
|
22
22
|
<div id="index-entries">
|
|
23
|
-
<a href="classes/Vector.html#
|
|
24
|
-
<a href="classes/Color.html#
|
|
25
|
-
<a href="classes/Color.html#
|
|
26
|
-
<a href="classes/
|
|
27
|
-
<a href="classes/
|
|
28
|
-
<a href="classes/GameObject.html#
|
|
29
|
-
<a href="classes/
|
|
30
|
-
<a href="classes/
|
|
31
|
-
<a href="classes/
|
|
32
|
-
<a href="classes/Utility.html#
|
|
33
|
-
<a href="classes/
|
|
34
|
-
<a href="classes/
|
|
35
|
-
<a href="classes/
|
|
36
|
-
<a href="classes/
|
|
37
|
-
<a href="classes/
|
|
38
|
-
<a href="classes/
|
|
39
|
-
<a href="classes/
|
|
40
|
-
<a href="classes/
|
|
41
|
-
<a href="classes/
|
|
42
|
-
<a href="classes/
|
|
43
|
-
<a href="classes/
|
|
44
|
-
<a href="classes/
|
|
45
|
-
<a href="classes/
|
|
46
|
-
<a href="classes/
|
|
47
|
-
<a href="classes/Environment.html#
|
|
48
|
-
<a href="classes/
|
|
49
|
-
<a href="classes/
|
|
50
|
-
<a href="classes/
|
|
51
|
-
<a href="classes/
|
|
52
|
-
<a href="classes/
|
|
53
|
-
<a href="classes/
|
|
54
|
-
<a href="classes/
|
|
55
|
-
<a href="classes/
|
|
56
|
-
<a href="classes/
|
|
57
|
-
<a href="classes/
|
|
58
|
-
<a href="classes/
|
|
59
|
-
<a href="classes/
|
|
23
|
+
<a href="classes/Vector.html#M000020">+ (Vector)</a><br />
|
|
24
|
+
<a href="classes/Color.html#M000027">+ (Color)</a><br />
|
|
25
|
+
<a href="classes/Color.html#M000026"><=> (Color)</a><br />
|
|
26
|
+
<a href="classes/Enclosure.html#M000006">act (Enclosure)</a><br />
|
|
27
|
+
<a href="classes/Creature.html#M000012">act (Creature)</a><br />
|
|
28
|
+
<a href="classes/GameObject.html#M000035">age (GameObject)</a><br />
|
|
29
|
+
<a href="classes/GameObject.html#M000036">age= (GameObject)</a><br />
|
|
30
|
+
<a href="classes/Color.html#M000025">blue= (Color)</a><br />
|
|
31
|
+
<a href="classes/Utility.html#M000062">collided? (Utility)</a><br />
|
|
32
|
+
<a href="classes/Utility.html#M000060">constrain_value (Utility)</a><br />
|
|
33
|
+
<a href="classes/FaceAction.html#M000052">do (FaceAction)</a><br />
|
|
34
|
+
<a href="classes/TurnAction.html#M000051">do (TurnAction)</a><br />
|
|
35
|
+
<a href="classes/AccelerateAction.html#M000010">do (AccelerateAction)</a><br />
|
|
36
|
+
<a href="classes/ApproachAction.html#M000049">do (ApproachAction)</a><br />
|
|
37
|
+
<a href="classes/BlendAction.html#M000044">do (BlendAction)</a><br />
|
|
38
|
+
<a href="classes/TagAction.html#M000029">do (TagAction)</a><br />
|
|
39
|
+
<a href="classes/FleeAction.html#M000055">do (FleeAction)</a><br />
|
|
40
|
+
<a href="classes/DestroyAction.html#M000031">do (DestroyAction)</a><br />
|
|
41
|
+
<a href="classes/EatAction.html#M000045">do (EatAction)</a><br />
|
|
42
|
+
<a href="classes/Clock.html#M000042">elapsed_time (Clock)</a><br />
|
|
43
|
+
<a href="classes/Utility.html#M000056">find_angle (Utility)</a><br />
|
|
44
|
+
<a href="classes/Utility.html#M000057">find_distance (Utility)</a><br />
|
|
45
|
+
<a href="classes/Utility.html#M000061">find_reflection_angle (Utility)</a><br />
|
|
46
|
+
<a href="classes/Color.html#M000024">green= (Color)</a><br />
|
|
47
|
+
<a href="classes/Environment.html#M000047">interact (Environment)</a><br />
|
|
48
|
+
<a href="classes/GameObject.html#M000034">move (GameObject)</a><br />
|
|
49
|
+
<a href="classes/GameObject.html#M000032">new (GameObject)</a><br />
|
|
50
|
+
<a href="classes/TagAction.html#M000028">new (TagAction)</a><br />
|
|
51
|
+
<a href="classes/Color.html#M000022">new (Color)</a><br />
|
|
52
|
+
<a href="classes/DestroyAction.html#M000030">new (DestroyAction)</a><br />
|
|
53
|
+
<a href="classes/Location.html#M000021">new (Location)</a><br />
|
|
54
|
+
<a href="classes/TrailsView.html#M000003">new (TrailsView)</a><br />
|
|
55
|
+
<a href="classes/Enclosure.html#M000005">new (Enclosure)</a><br />
|
|
56
|
+
<a href="classes/TagCondition.html#M000007">new (TagCondition)</a><br />
|
|
57
|
+
<a href="classes/FleeAction.html#M000054">new (FleeAction)</a><br />
|
|
58
|
+
<a href="classes/AccelerateAction.html#M000009">new (AccelerateAction)</a><br />
|
|
59
|
+
<a href="classes/ProximityCondition.html#M000037">new (ProximityCondition)</a><br />
|
|
60
|
+
<a href="classes/TurnAction.html#M000050">new (TurnAction)</a><br />
|
|
61
|
+
<a href="classes/AgeCondition.html#M000039">new (AgeCondition)</a><br />
|
|
62
|
+
<a href="classes/Creature.html#M000011">new (Creature)</a><br />
|
|
63
|
+
<a href="classes/Clock.html#M000041">new (Clock)</a><br />
|
|
64
|
+
<a href="classes/ApproachAction.html#M000048">new (ApproachAction)</a><br />
|
|
65
|
+
<a href="classes/BlendAction.html#M000043">new (BlendAction)</a><br />
|
|
66
|
+
<a href="classes/Vector.html#M000013">new (Vector)</a><br />
|
|
67
|
+
<a href="classes/Environment.html#M000046">new (Environment)</a><br />
|
|
68
|
+
<a href="classes/Behavior.html#M000001">new (Behavior)</a><br />
|
|
69
|
+
<a href="classes/Behavior.html#M000002">perform (Behavior)</a><br />
|
|
70
|
+
<a href="classes/Vector.html#M000014">pitch (Vector)</a><br />
|
|
71
|
+
<a href="classes/Vector.html#M000015">pitch= (Vector)</a><br />
|
|
72
|
+
<a href="classes/Color.html#M000023">red= (Color)</a><br />
|
|
73
|
+
<a href="classes/GameObject.html#M000033">size= (GameObject)</a><br />
|
|
74
|
+
<a href="classes/ProximityCondition.html#M000038">test (ProximityCondition)</a><br />
|
|
75
|
+
<a href="classes/CollisionCondition.html#M000053">test (CollisionCondition)</a><br />
|
|
76
|
+
<a href="classes/TagCondition.html#M000008">test (TagCondition)</a><br />
|
|
77
|
+
<a href="classes/AgeCondition.html#M000040">test (AgeCondition)</a><br />
|
|
78
|
+
<a href="classes/Utility.html#M000058">to_degrees (Utility)</a><br />
|
|
79
|
+
<a href="classes/Utility.html#M000059">to_radians (Utility)</a><br />
|
|
80
|
+
<a href="classes/TrailsView.html#M000004">update (TrailsView)</a><br />
|
|
81
|
+
<a href="classes/Vector.html#M000016">x (Vector)</a><br />
|
|
82
|
+
<a href="classes/Vector.html#M000017">x= (Vector)</a><br />
|
|
83
|
+
<a href="classes/Vector.html#M000018">y (Vector)</a><br />
|
|
84
|
+
<a href="classes/Vector.html#M000019">y= (Vector)</a><br />
|
|
60
85
|
</div>
|
|
61
86
|
</div>
|
|
62
87
|
</body>
|
data/doc/index.html
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
<!--
|
|
7
7
|
|
|
8
|
-
Zyps - A
|
|
8
|
+
Zyps - A game library for Ruby
|
|
9
9
|
|
|
10
10
|
-->
|
|
11
11
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
12
12
|
<head>
|
|
13
|
-
<title>Zyps - A
|
|
13
|
+
<title>Zyps - A game library for Ruby</title>
|
|
14
14
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
15
15
|
</head>
|
|
16
16
|
<frameset rows="20%, 80%">
|
data/lib/zyps.rb
CHANGED
|
@@ -30,7 +30,7 @@ class Environment
|
|
|
30
30
|
attr_accessor :environmental_factors
|
|
31
31
|
|
|
32
32
|
def initialize (objects = [], environmental_factors = [])
|
|
33
|
-
|
|
33
|
+
self.objects, self.environmental_factors = objects, environmental_factors
|
|
34
34
|
@clock = Clock.new
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -83,6 +83,8 @@ class GameObject
|
|
|
83
83
|
attr_accessor :location
|
|
84
84
|
#A Color that will be used to draw the object.
|
|
85
85
|
attr_accessor :color
|
|
86
|
+
#Radius of the object.
|
|
87
|
+
attr_accessor :size
|
|
86
88
|
#A Vector with the object's current speed and direction of travel.
|
|
87
89
|
attr_accessor :vector
|
|
88
90
|
#A String with the object's name.
|
|
@@ -90,12 +92,14 @@ class GameObject
|
|
|
90
92
|
#An array of Strings with tags that determine how the object will be treated by Creature and EnvironmentalFactor objects in its environment.
|
|
91
93
|
attr_accessor :tags
|
|
92
94
|
|
|
93
|
-
def initialize (name = nil, location = Location.new, color = Color.new, vector = Vector.new, age = 0, tags = [])
|
|
94
|
-
|
|
95
|
+
def initialize (name = nil, location = Location.new, color = Color.new, vector = Vector.new, age = 0, size = 1, tags = [])
|
|
96
|
+
self.name, self.location, self.color, self.vector, self.age, self.size, self.tags = name, location, color, vector, age, size, tags
|
|
95
97
|
@identifier = rand(99999999) #TODO: Current setup won't necessarily be unique.
|
|
96
|
-
self.age = age
|
|
97
98
|
end
|
|
98
99
|
|
|
100
|
+
#Size must be positive.
|
|
101
|
+
def size=(v); v = 0 if v < 0; @size = v; end
|
|
102
|
+
|
|
99
103
|
#Move according to vector over the given number of seconds.
|
|
100
104
|
def move (elapsed_time)
|
|
101
105
|
@location.x += @vector.x * elapsed_time
|
|
@@ -110,30 +114,21 @@ end
|
|
|
110
114
|
|
|
111
115
|
|
|
112
116
|
|
|
113
|
-
#Mixin to have an object (usually a Creature) act on other objects.
|
|
114
|
-
module Responsive
|
|
115
|
-
|
|
116
|
-
#Call Behavior.perform on each of the object's assigned Behaviors, with the object and a target as arguments.
|
|
117
|
-
def act(target)
|
|
118
|
-
behaviors.each {|behavior| behavior.perform(self, target)}
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
117
|
#A Creature is a GameObject that can sense and respond to other GameObjects (including other Creature objects).
|
|
126
118
|
class Creature < GameObject
|
|
127
119
|
|
|
128
|
-
include Responsive
|
|
129
|
-
|
|
130
120
|
#A list of Behavior objects that determine the creature's response to its environment.
|
|
131
121
|
attr_accessor :behaviors
|
|
132
122
|
|
|
133
123
|
#Identical to the GameObject constructor, except that it also takes a list of Behavior objects.
|
|
134
|
-
def initialize (name = nil, location = Location.new, color = Color.new, vector = Vector.new, age = 0, tags = [], behaviors = [])
|
|
135
|
-
super(name, location, color, vector, age, tags)
|
|
136
|
-
|
|
124
|
+
def initialize (name = nil, location = Location.new, color = Color.new, vector = Vector.new, age = 0, size = 1, tags = [], behaviors = [])
|
|
125
|
+
super(name, location, color, vector, age, size, tags)
|
|
126
|
+
self.behaviors = behaviors
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
#Call Behavior.perform on each of the object's assigned Behaviors, with the object and a target as arguments.
|
|
130
|
+
def act(target)
|
|
131
|
+
behaviors.each {|behavior| behavior.perform(self, target)}
|
|
137
132
|
end
|
|
138
133
|
|
|
139
134
|
end
|
|
@@ -141,41 +136,46 @@ end
|
|
|
141
136
|
|
|
142
137
|
|
|
143
138
|
#Something in the environment that acts on creatures.
|
|
139
|
+
#EnvironmentalFactors must implement an act(target) instance method.
|
|
144
140
|
class EnvironmentalFactor
|
|
141
|
+
end
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
#An action that one Creature takes on another.
|
|
146
|
+
#Actions must implement a do(actor, target) instance method.
|
|
147
|
+
class Action
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
#A condition for one Creature to act on another.
|
|
153
|
+
#Conditions must implement a test(actor, target) instance method.
|
|
154
|
+
class Condition
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
|
|
159
|
-
#A behavior that a Creature
|
|
159
|
+
#A behavior that a Creature engages in.
|
|
160
160
|
#The target can have its tags or colors changed, it can be "herded", it can be destroyed, or any other action the library user can dream up.
|
|
161
161
|
#Likewise, the subject can change its own attributes, it can approach or flee from the target, it can spawn new Creatures or GameObjects (like bullets), or anything else.
|
|
162
162
|
class Behavior
|
|
163
163
|
|
|
164
|
-
#A list of
|
|
164
|
+
#A list of Condition objects, which are called with the object itself and its target. A condition can consider the tags on the target, the distance from the subject, or any other criteria. If any condition returns false, the behavior will not be carried out.
|
|
165
165
|
attr_accessor :conditions
|
|
166
|
-
#A list of
|
|
166
|
+
#A list of Action objects, which are called with the object and its target when all conditions are met. An action can act on the subject or its target.
|
|
167
167
|
attr_accessor :actions
|
|
168
168
|
|
|
169
169
|
#Optionally takes an array of actions and one of conditions.
|
|
170
170
|
def initialize (actions = [], conditions = [])
|
|
171
|
-
|
|
171
|
+
self.actions, self.conditions = actions, conditions
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
#Calls each Proc object in the list of conditions with the subject and its target. Returns nil if any condition returns false.
|
|
175
175
|
#Then calls each Proc object in the list of actions, also with the subject and its target.
|
|
176
176
|
def perform(subject, target)
|
|
177
|
-
conditions.each {|condition| return
|
|
178
|
-
actions.each {|action| action.
|
|
177
|
+
conditions.each {|condition| return unless condition.test(subject, target)}
|
|
178
|
+
actions.each {|action| action.do(subject, target)}
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
end
|
|
@@ -215,9 +215,9 @@ class Color
|
|
|
215
215
|
#Averages each component of this Color with the corresponding component of color2, returning a new Color.
|
|
216
216
|
def +(color2)
|
|
217
217
|
Color.new(
|
|
218
|
-
self.red + color2.red / 2.0,
|
|
219
|
-
self.green + color2.green / 2.0,
|
|
220
|
-
self.blue + color2.blue / 2.0
|
|
218
|
+
(self.red + color2.red) / 2.0,
|
|
219
|
+
(self.green + color2.green) / 2.0,
|
|
220
|
+
(self.blue + color2.blue) / 2.0
|
|
221
221
|
)
|
|
222
222
|
end
|
|
223
223
|
|
|
@@ -232,7 +232,7 @@ class Location
|
|
|
232
232
|
attr_accessor :x, :y
|
|
233
233
|
|
|
234
234
|
def initialize (x = 0, y = 0)
|
|
235
|
-
|
|
235
|
+
self.x, self.y = x, y
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
end
|
|
@@ -367,13 +367,12 @@ module Utility
|
|
|
367
367
|
reflection_angle
|
|
368
368
|
end
|
|
369
369
|
|
|
370
|
-
#Given
|
|
371
|
-
def Utility.
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return
|
|
375
|
-
|
|
376
|
-
true
|
|
370
|
+
#Given two GameObjects, determine if the boundary of one crosses the boundary of the other.
|
|
371
|
+
def Utility.collided?(object1, object2)
|
|
372
|
+
object1_radius = Math.sqrt(object1.size / Math::PI)
|
|
373
|
+
object2_radius = Math.sqrt(object2.size / Math::PI)
|
|
374
|
+
return true if find_distance(object1.location, object2.location) < object1_radius + object2_radius
|
|
375
|
+
false
|
|
377
376
|
end
|
|
378
377
|
|
|
379
378
|
end
|
data/lib/zyps/actions.rb
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
#Head toward a target.
|
|
22
|
+
class FaceAction < Action
|
|
23
|
+
#Set the actor's heading to point directly at target.
|
|
24
|
+
def do(actor, target)
|
|
25
|
+
actor.vector.pitch = Utility.find_angle(actor.location, target.location)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
#Increase/decrease speed over time.
|
|
30
|
+
class AccelerateAction < Action
|
|
31
|
+
#Units per second to accelerate.
|
|
32
|
+
#Can be negative to slow down or go in reverse.
|
|
33
|
+
attr_accessor :rate
|
|
34
|
+
def initialize(rate = 0)
|
|
35
|
+
self.rate = rate
|
|
36
|
+
@clock = Clock.new
|
|
37
|
+
end
|
|
38
|
+
#Increase or decrease speed according to elapsed time.
|
|
39
|
+
def do(actor, target)
|
|
40
|
+
actor.vector.speed += @clock.elapsed_time * rate
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#Turn over time.
|
|
46
|
+
class TurnAction < Action
|
|
47
|
+
#Degrees per second to turn.
|
|
48
|
+
#Positive turns clockwise, negative turns counter-clockwise.
|
|
49
|
+
attr_accessor :rate
|
|
50
|
+
def initialize(rate = 0)
|
|
51
|
+
self.rate = rate
|
|
52
|
+
@clock = Clock.new
|
|
53
|
+
end
|
|
54
|
+
#Turn according to elapsed time.
|
|
55
|
+
def do(actor, target)
|
|
56
|
+
actor.vector.pitch += @clock.elapsed_time * rate
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
#Approaches the target, but obeys law of inertia.
|
|
62
|
+
class ApproachAction < Action
|
|
63
|
+
#Direction/speed actor is accelerating in.
|
|
64
|
+
attr_accessor :heading
|
|
65
|
+
#Degrees per second the direction of acceleration can change.
|
|
66
|
+
attr_accessor :turn_rate
|
|
67
|
+
def initialize(heading = Vector.new, turn_rate = 360)
|
|
68
|
+
self.heading, self.turn_rate = heading, turn_rate
|
|
69
|
+
@clock = Clock.new
|
|
70
|
+
end
|
|
71
|
+
#Accelerate toward the target, but limited by turn rate.
|
|
72
|
+
def do(actor, target)
|
|
73
|
+
#Find the difference between the current heading and the angle to the target.
|
|
74
|
+
turn_angle = Utility.find_angle(actor.location, target.location) - @heading.pitch
|
|
75
|
+
#If the angle is the long way around from the current heading, change it to the smaller angle.
|
|
76
|
+
if turn_angle > 180 then
|
|
77
|
+
turn_angle -= 360.0
|
|
78
|
+
elsif turn_angle < -180 then
|
|
79
|
+
turn_angle += 360.0
|
|
80
|
+
end
|
|
81
|
+
#The creature can only turn as fast as the elapsed time, of course.
|
|
82
|
+
maximum_turn = turn_rate * @clock.elapsed_time
|
|
83
|
+
if turn_angle.abs > maximum_turn
|
|
84
|
+
if turn_angle > 0
|
|
85
|
+
turn_angle = maximum_turn
|
|
86
|
+
else
|
|
87
|
+
turn_angle = maximum_turn * -1
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
#Turn the appropriate amount.
|
|
91
|
+
@heading.pitch += turn_angle
|
|
92
|
+
#Apply the heading to the creature's movement vector.
|
|
93
|
+
actor.vector += @heading
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
#Flees from the target, but obeys law of inertia.
|
|
99
|
+
class FleeAction < Action
|
|
100
|
+
#Direction/speed actor is accelerating in.
|
|
101
|
+
attr_accessor :heading
|
|
102
|
+
#Degrees per second the direction of acceleration can change.
|
|
103
|
+
attr_accessor :turn_rate
|
|
104
|
+
def initialize(heading = Vector.new, turn_rate = 360)
|
|
105
|
+
self.heading, self.turn_rate = heading, turn_rate
|
|
106
|
+
@clock = Clock.new
|
|
107
|
+
end
|
|
108
|
+
#Accelerate away from the target, but limited by turn rate.
|
|
109
|
+
def do(actor, target)
|
|
110
|
+
#Find the difference between the current heading and the angle to the target.
|
|
111
|
+
turn_angle = Utility.find_angle(actor.location, target.location) - @heading.pitch + 180
|
|
112
|
+
#If the angle is the long way around from the current heading, change it to the smaller angle.
|
|
113
|
+
if turn_angle > 180 then
|
|
114
|
+
turn_angle -= 360.0
|
|
115
|
+
elsif turn_angle < -180 then
|
|
116
|
+
turn_angle += 360.0
|
|
117
|
+
end
|
|
118
|
+
#The creature can only turn as fast as the elapsed time, of course.
|
|
119
|
+
maximum_turn = turn_rate * @clock.elapsed_time
|
|
120
|
+
if turn_angle.abs > maximum_turn
|
|
121
|
+
if turn_angle > 0
|
|
122
|
+
turn_angle = maximum_turn
|
|
123
|
+
else
|
|
124
|
+
turn_angle = maximum_turn * -1
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
#Turn the appropriate amount.
|
|
128
|
+
@heading.pitch += turn_angle
|
|
129
|
+
#Apply the heading to the creature's movement vector.
|
|
130
|
+
actor.vector += @heading
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
#Destroy the target.
|
|
136
|
+
class DestroyAction < Action
|
|
137
|
+
#The environment to remove objects from.
|
|
138
|
+
attr_accessor :environment
|
|
139
|
+
def initialize(environment)
|
|
140
|
+
self.environment = environment
|
|
141
|
+
end
|
|
142
|
+
#Remove the target from the environment.
|
|
143
|
+
def do(actor, target)
|
|
144
|
+
@environment.objects.delete(target)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
#Destroy the target and grow in size.
|
|
150
|
+
class EatAction < DestroyAction
|
|
151
|
+
#Remove the target from the environment, and increase actor's size by size of target.
|
|
152
|
+
def do(actor, target)
|
|
153
|
+
#Remove the target from the environment.
|
|
154
|
+
super
|
|
155
|
+
#Grow in size.
|
|
156
|
+
actor.size += target.size
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
#Add a tag to the target.
|
|
162
|
+
class TagAction < Action
|
|
163
|
+
#Tag to apply to target.
|
|
164
|
+
attr_accessor :tag
|
|
165
|
+
def initialize(tag)
|
|
166
|
+
self.tag = tag
|
|
167
|
+
end
|
|
168
|
+
#Apply the given tag to the target.
|
|
169
|
+
def do(actor, target)
|
|
170
|
+
target.tags << tag unless target.tags.include?(tag)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
#Blend the target's color with another color.
|
|
176
|
+
class BlendAction < Action
|
|
177
|
+
#Color to apply to target.
|
|
178
|
+
attr_accessor :color
|
|
179
|
+
def initialize(color)
|
|
180
|
+
self.color = color
|
|
181
|
+
end
|
|
182
|
+
#Blend the target's color with the assigned color.
|
|
183
|
+
def do(actor, target)
|
|
184
|
+
target.color += @color
|
|
185
|
+
end
|
|
186
|
+
end
|