zyps 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,18 +28,18 @@ class TestConditions < Test::Unit::TestCase
28
28
 
29
29
 
30
30
  def setup
31
- @actor = Creature.new('name', Location.new(1, 1))
32
- @target = GameObject.new('name', Location.new(2, 2))
31
+ @actor = Creature.new(:name => 'name', :location => Location.new(1, 1))
32
+ @target = GameObject.new(:name => 'name', :location => Location.new(2, 2))
33
33
  end
34
34
 
35
35
 
36
36
  def test_tag_condition
37
37
  condition = TagCondition.new("tag")
38
38
  #Test for falsehood.
39
- assert(! condition.met?(@actor, @target))
39
+ assert(! condition.select(@actor, [@target]).include?(@target))
40
40
  #Test for truth.
41
41
  @target.tags << "tag"
42
- assert(condition.met?(@actor, @target))
42
+ assert(condition.select(@actor, [@target]).include?(@target))
43
43
  end
44
44
 
45
45
 
@@ -47,22 +47,22 @@ class TestConditions < Test::Unit::TestCase
47
47
  condition = AgeCondition.new(0.2)
48
48
  #Test for falsehood.
49
49
  @target.age = 0.1
50
- assert(! condition.met?(@actor, @target))
50
+ assert(! condition.select(@actor, [@target]).include?(@target))
51
51
  #Test for truth.
52
52
  @target.age = 0.2
53
- assert(condition.met?(@actor, @target))
53
+ assert(condition.select(@actor, [@target]).include?(@target))
54
54
  @target.age = 0.3
55
- assert(condition.met?(@actor, @target))
55
+ assert(condition.select(@actor, [@target]).include?(@target))
56
56
  end
57
57
 
58
58
 
59
59
  def test_proximity_condition
60
60
  condition = ProximityCondition.new(1)
61
61
  #Test for falsehood.
62
- assert(! condition.met?(@actor, @target))
62
+ assert(! condition.select(@actor, [@target]).include?(@target))
63
63
  #Test for truth.
64
64
  @target.location = Location.new(0.5, 0.5)
65
- assert(condition.met?(@actor, @target))
65
+ assert(condition.select(@actor, [@target]).include?(@target))
66
66
  end
67
67
 
68
68
 
@@ -70,10 +70,29 @@ class TestConditions < Test::Unit::TestCase
70
70
  condition = CollisionCondition.new
71
71
  #Test for falsehood.
72
72
  @actor.size, @target.size = 0.196, 0.196 #Radius = 0.25
73
- assert(! condition.met?(@actor, @target))
73
+ assert(! condition.select(@actor, [@target]).include?(@target))
74
74
  #Test for truth.
75
75
  @actor.size, @target.size = 1.766, 1.766 #Radius = 0.75
76
- assert(condition.met?(@actor, @target))
76
+ assert(condition.select(@actor, [@target]).include?(@target))
77
+ end
78
+
79
+
80
+ def test_strength_condition
81
+ condition = StrengthCondition.new
82
+ #For now, "strength" is based merely on size.
83
+ #Test for falsehood.
84
+ @actor.size = 1
85
+ @target.size = 2
86
+ assert(! condition.select(@actor, [@target]).include?(@target))
87
+ #Test for truth.
88
+ #Equally strong objects cause the condition to return true.
89
+ @actor.size = 2
90
+ @target.size = 2
91
+ assert(condition.select(@actor, [@target]).include?(@target))
92
+ #As will cases where the actor is stronger, of course.
93
+ @actor.size = 3
94
+ @target.size = 2
95
+ assert(condition.select(@actor, [@target]).include?(@target))
77
96
  end
78
97
 
79
98
 
@@ -35,40 +35,42 @@ class TestEnclosure < Test::Unit::TestCase
35
35
  def test_enclosure
36
36
 
37
37
  creature = Creature.new
38
+ environment = Environment.new(:objects => [creature])
38
39
 
39
40
  #Create an enclosure.
40
- enclosure = Enclosure.new
41
- enclosure.left = 1
42
- enclosure.top = 3
43
- enclosure.right = 3
44
- enclosure.bottom = 1
41
+ enclosure = Enclosure.new(
42
+ :left => 1,
43
+ :top => 3,
44
+ :right => 3,
45
+ :bottom => 1
46
+ )
45
47
 
46
48
  #Place creature outside the walls, and act on it.
47
49
  #Ensure it's moved inside and its heading reflects off the walls.
48
50
  creature.location = Location.new(0, 2) #Too far left.
49
51
  creature.vector.pitch = 170
50
- enclosure.act(creature)
52
+ enclosure.act(environment)
51
53
  assert_equal(1, creature.location.x)
52
54
  assert_equal(2, creature.location.y)
53
55
  assert_equal(10, creature.vector.pitch)
54
56
 
55
57
  creature.location = Location.new(4, 2) #Too far right.
56
58
  creature.vector.pitch = 10
57
- enclosure.act(creature)
59
+ enclosure.act(environment)
58
60
  assert_equal(3, creature.location.x)
59
61
  assert_equal(2, creature.location.y)
60
62
  assert_equal(170, creature.vector.pitch)
61
63
 
62
64
  creature.location = Location.new(2, 0) #Too far down.
63
65
  creature.vector.pitch = 280
64
- enclosure.act(creature)
66
+ enclosure.act(environment)
65
67
  assert_equal(2, creature.location.x)
66
68
  assert_equal(1, creature.location.y)
67
69
  assert_equal(80, creature.vector.pitch)
68
70
 
69
71
  creature.location = Location.new(2, 4) #Too far up.
70
72
  creature.vector.pitch = 80
71
- enclosure.act(creature)
73
+ enclosure.act(environment)
72
74
  assert_equal(2, creature.location.x)
73
75
  assert_equal(3, creature.location.y)
74
76
  assert_equal(280, creature.vector.pitch)
@@ -76,7 +78,7 @@ class TestEnclosure < Test::Unit::TestCase
76
78
  #Place creature inside the walls, and ensure it's unaffected.
77
79
  creature.location = Location.new(2, 2) #Inside.
78
80
  creature.vector.pitch = 45
79
- enclosure.act(creature)
81
+ enclosure.act(environment)
80
82
  assert_equal(2, creature.location.x)
81
83
  assert_equal(2, creature.location.y)
82
84
  assert_equal(45, creature.vector.pitch)
@@ -92,23 +94,24 @@ class TestSpeedLimit < Test::Unit::TestCase
92
94
  def test_speed_limit
93
95
 
94
96
  creature = Creature.new
97
+ environment = Environment.new(:objects => [creature])
95
98
 
96
99
  #Create a speed limit.
97
100
  limit = SpeedLimit.new(10)
98
101
 
99
102
  #Act on a creature going under the limit, and ensure it's unaffected.
100
103
  creature.vector.speed = 1
101
- limit.act(creature)
104
+ limit.act(environment)
102
105
  assert_equal(1, creature.vector.speed)
103
106
 
104
107
  #Act on a creature going over the limit, and ensure its speed is reduced.
105
108
  creature.vector.speed = 11
106
- limit.act(creature)
109
+ limit.act(environment)
107
110
  assert_equal(10, creature.vector.speed)
108
111
 
109
112
  #Act on a creature going in reverse, and ensure its speed is reduced.
110
113
  creature.vector.speed = -11
111
- limit.act(creature)
114
+ limit.act(environment)
112
115
  assert_equal(-10, creature.vector.speed)
113
116
 
114
117
  end
@@ -121,11 +124,12 @@ class TestAccelerator < Test::Unit::TestCase
121
124
 
122
125
  def test_standing_start
123
126
  creature = Creature.new
127
+ environment = Environment.new(:objects => [creature])
124
128
  creature.vector = Vector.new(0, 0)
125
129
  #Create an accelerator that pushes downwards by 1 unit/sec.
126
130
  accelerator = Accelerator.new(Vector.new(1, 270))
127
131
  #Act on a creature, and ensure its vector is modified appropriately.
128
- accelerator.act(creature)
132
+ accelerator.act(environment)
129
133
  assert_equal(ELAPSED_TIME, creature.vector.speed)
130
134
  assert_equal(270, creature.vector.pitch)
131
135
  end
@@ -133,11 +137,12 @@ class TestAccelerator < Test::Unit::TestCase
133
137
 
134
138
  def test_cancellation
135
139
  creature = Creature.new
140
+ environment = Environment.new(:objects => [creature])
136
141
  creature.vector = Vector.new(1, 45)
137
142
  #Create an accelerator pushing opposite to the creature's direction of travel.
138
143
  accelerator = Accelerator.new(Vector.new(0.5, 225))
139
144
  #Act on a creature, and ensure its vector is modified appropriately.
140
- accelerator.act(creature)
145
+ accelerator.act(environment)
141
146
  assert_equal(0.95, creature.vector.speed)
142
147
  assert_equal(45, creature.vector.pitch)
143
148
  end
@@ -151,14 +156,15 @@ class TestFriction < Test::Unit::TestCase
151
156
 
152
157
  def test_slowing
153
158
  creature = Creature.new
159
+ environment = Environment.new(:objects => [creature])
154
160
  creature.vector = Vector.new(STARTING_SPEED, 0)
155
161
  #Create friction that slows objects by 1 unit/sec.
156
162
  friction = Friction.new(1)
157
163
  #Act on a creature, and ensure its vector is modified appropriately.
158
- friction.act(creature)
164
+ friction.act(environment)
159
165
  assert_equal(STARTING_SPEED - ELAPSED_TIME, creature.vector.speed)
160
166
  #Test cumulative effect.
161
- friction.act(creature)
167
+ friction.act(environment)
162
168
  assert_equal(STARTING_SPEED - ELAPSED_TIME * 2, creature.vector.speed)
163
169
  end
164
170
 
@@ -172,26 +178,26 @@ class TestPopulationLimit < Test::Unit::TestCase
172
178
  #Create an environment.
173
179
  environment = Environment.new
174
180
  #Create a population limit for the environment.
175
- limit = PopulationLimit.new(environment, 2)
181
+ limit = PopulationLimit.new(2)
176
182
 
177
183
  #Ensure population is not affected when under/at the limit.
178
184
  creature_1 = Creature.new
179
185
  environment.objects << creature_1
180
- limit.act(creature_1)
186
+ limit.act(environment)
181
187
  assert(environment.objects.include?(creature_1))
182
188
  creature_2 = Creature.new
183
189
  environment.objects << creature_2
184
- limit.act(creature_1)
190
+ limit.act(environment)
185
191
  assert(environment.objects.include?(creature_1))
186
192
  assert(environment.objects.include?(creature_2))
187
- limit.act(creature_2)
193
+ limit.act(environment)
188
194
  assert(environment.objects.include?(creature_1))
189
195
  assert(environment.objects.include?(creature_2))
190
196
 
191
197
  #Ensure first creature is removed when limit is exceeded.
192
198
  creature_3 = Creature.new
193
199
  environment.objects << creature_3
194
- limit.act(creature_1)
200
+ limit.act(environment)
195
201
  assert(! environment.objects.include?(creature_1))
196
202
 
197
203
  #Ensure other creatures aren't touched.
@@ -79,12 +79,12 @@ class TestRemote < Test::Unit::TestCase
79
79
  creature = Creature.new
80
80
  creature.vector = Vector.new(SPEED, PITCH)
81
81
  behavior = Behavior.new
82
- behavior.actions << TurnAction.new(RATE)
82
+ behavior.actions << TurnAction.new(RATE, 90)
83
83
  creature.behaviors << behavior
84
84
  @client.objects << creature
85
85
  @client.objects << Creature.new #Second creature to interact with.
86
86
  @environment.interact
87
- assert_in_delta(PITCH + 0.1 * RATE, @client.objects[0].vector.pitch, 0.001)
87
+ assert(@client.objects[0].vector.pitch > PITCH)
88
88
  end
89
89
 
90
90
  #Place Creature with Condition and ensure it's followed.
@@ -92,7 +92,7 @@ class TestRemote < Test::Unit::TestCase
92
92
  creature = Creature.new
93
93
  creature.vector = Vector.new(SPEED, PITCH)
94
94
  behavior = Behavior.new
95
- behavior.actions << TurnAction.new(RATE)
95
+ behavior.actions << TurnAction.new(RATE, 90)
96
96
  behavior.conditions << TagCondition.new('foobar') #Will return false.
97
97
  creature.behaviors << behavior
98
98
  @client.objects << creature
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: zyps
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.6.3
7
- date: 2007-11-08 00:00:00 -07:00
6
+ version: 0.7.0
7
+ date: 2008-01-23 00:00:00 -07:00
8
8
  summary: A game library for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -34,13 +34,15 @@ files:
34
34
  - README.txt
35
35
  - bin/zyps
36
36
  - bin/zyps_demo
37
- - bin/zyps_server
38
37
  - lib/zyps
39
38
  - lib/zyps/actions.rb
40
39
  - lib/zyps/conditions.rb
41
40
  - lib/zyps/environmental_factors.rb
42
41
  - lib/zyps/remote.rb
43
42
  - lib/zyps/views
43
+ - lib/zyps/views/canvas
44
+ - lib/zyps/views/canvas/gtk2.rb
45
+ - lib/zyps/views/canvas/wx.rb
44
46
  - lib/zyps/views/trails.rb
45
47
  - lib/zyps.rb
46
48
  - test/test_zyps.rb
@@ -63,11 +65,17 @@ extra_rdoc_files:
63
65
  - COPYING.txt
64
66
  executables:
65
67
  - zyps
66
- - zyps_demo
67
- - zyps_server
68
68
  extensions: []
69
69
 
70
- requirements:
71
- - - Ruby-GNOME2
72
- dependencies: []
70
+ requirements: []
73
71
 
72
+ dependencies:
73
+ - !ruby/object:Gem::Dependency
74
+ name: wxruby
75
+ version_requirement:
76
+ version_requirements: !ruby/object:Gem::Version::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.9.2
81
+ version:
data/bin/zyps_server DELETED
@@ -1,235 +0,0 @@
1
- #!/usr/local/bin/ruby
2
-
3
- # Copyright 2007 Jay McGavren, jay@mcgavren.com.
4
- #
5
- # This file is part of Zyps.
6
- #
7
- # Zyps is free software; you can redistribute it and/or modify
8
- # it under the terms of the GNU Lesser General Public License as published by
9
- # the Free Software Foundation; either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU Lesser General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
-
20
-
21
- gems_loaded = false
22
- begin
23
- require 'optparse'
24
- require 'zyps'
25
- require 'zyps/actions'
26
- require 'zyps/conditions'
27
- require 'zyps/environmental_factors'
28
- require 'zyps/remote'
29
- require 'zyps/views/trails'
30
- require 'drb'
31
- rescue LoadError
32
- if gems_loaded == false
33
- require 'rubygems'
34
- gems_loaded = true
35
- retry
36
- else
37
- raise
38
- end
39
- end
40
-
41
-
42
- include Zyps
43
-
44
-
45
- DEFAULT_VIEW_WIDTH = 800
46
- DEFAULT_VIEW_HEIGHT = 600
47
- DEFAULT_MAX_SPEED = 500
48
- DEFAULT_MAX_POPULATION = 100
49
- DEFAULT_FPS = 60
50
-
51
-
52
- #A server for a Zyps Environment.
53
- class ZypsServer
54
-
55
- #Port to open service on.
56
- attr_accessor :uri
57
- #Maximum allowed number of objects.
58
- attr_accessor :max_population
59
- #View dimensions.
60
- attr_accessor :view_width, :view_height
61
-
62
- #Set up default values.
63
- def initialize(
64
- uri = nil,
65
- view_width = DEFAULT_VIEW_WIDTH,
66
- view_height = DEFAULT_VIEW_HEIGHT,
67
- fps = DEFAULT_FPS,
68
- max_population = DEFAULT_MAX_POPULATION,
69
- max_speed = DEFAULT_MAX_SPEED,
70
- enclosure = true
71
- )
72
- @uri, @view_width, @view_height, @fps, @max_population, @max_speed, @enclosure =
73
- uri, view_width, view_height, fps, max_population, max_speed, enclosure
74
- end
75
-
76
- #Create app window, game environment, view, and network service.
77
- def main
78
-
79
- #A clock to track frames to draw this second.
80
- clock = Clock.new
81
- time_per_frame = 1.0 / @fps
82
-
83
- #Create a window, and set GTK up to quit when it is closed.
84
- window = Gtk::Window.new
85
- window.signal_connect("delete_event") {false}
86
- window.signal_connect("destroy") {Gtk.main_quit}
87
-
88
- #Add view to window.
89
- view = TrailsView.new(@view_width, @view_height)
90
- window.add(view.canvas)
91
- window.show_all
92
-
93
- #Create environment.
94
- environment = Environment.new
95
-
96
- #Point view at environment.
97
- environment.add_observer(view)
98
-
99
- #Limit population.
100
- environment.environmental_factors << PopulationLimit.new(environment, @max_population) if @max_population
101
-
102
- #Limit speed of objects.
103
- environment.environmental_factors << SpeedLimit.new(@max_speed) if @max_speed
104
-
105
- #Keep objects on screen.
106
- if @enclosure
107
- enclosure = Enclosure.new()
108
- enclosure.left = 0
109
- enclosure.bottom = 0
110
- enclosure.top = @view_height
111
- enclosure.right = @view_width
112
- environment.environmental_factors << enclosure
113
- end
114
-
115
- #Create thread to update environment.
116
- update_thread = Thread.new do
117
-
118
- begin
119
-
120
- loop do
121
-
122
- begin
123
- environment.interact
124
- rescue Exception => exception
125
- puts exception, exception.backtrace
126
- puts environment.inspect
127
- end
128
-
129
- #Control population.
130
- environment.objects.shift while environment.objects.length > @max_population
131
-
132
- #Determine how much time is left in this frame.
133
- time_left_in_frame = time_per_frame - clock.elapsed_time
134
- #Sleep for the remaining time.
135
- if time_left_in_frame > 0
136
- sleep time_left_in_frame
137
- #Skip a frame if things are going too slow.
138
- else
139
- sleep time_per_frame
140
- end
141
-
142
- end
143
-
144
- rescue Exception => exception
145
- puts exception, exception.backtrace
146
- end
147
-
148
- end
149
-
150
- #Start a network service.
151
- server = EnvironmentServer.new(environment, @uri)
152
- server.start
153
- #Display our URI.
154
- puts "Zyps server active at #{server.uri}"
155
-
156
- #Disable file system access.
157
- $SAFE = 2
158
-
159
- #Activate the GUI.
160
- Gtk.main
161
-
162
- end
163
-
164
-
165
- #Set attributes according to command-line arguments.
166
- def process_options(arguments)
167
-
168
- #Set up option parser.
169
- options = OptionParser.new
170
-
171
- #Define valid options.
172
- options.on("-h", "--help", TrueClass, "Display program help.") {
173
- puts options.help
174
- exit
175
- }
176
- options.on(
177
- "-m",
178
- "--max-population [number]",
179
- Integer,
180
- "The maximum number of allowed game objects. #{DEFAULT_MAX_POPULATION} by default."
181
- ) {|value| @max_population = value}
182
- options.on(
183
- "-s",
184
- "--max-speed [number]",
185
- Integer,
186
- "The fastest an object can go. #{DEFAULT_MAX_SPEED ? DEFAULT_MAX_SPEED : 'No limit'} by default."
187
- ) {|value| @max_speed = value}
188
- options.on(
189
- "-n",
190
- "--no-enclosure",
191
- "Disables the barrier that normally keeps objects on the screen."
192
- ) {|value| @enclosure = false}
193
- options.on(
194
- "-u",
195
- "--uri [uri]",
196
- String,
197
- "dRuby URI to run the server on. If not defined, one will be selected and printed to STDOUT."
198
- ) {|value| @uri = value}
199
- options.on(
200
- "-f",
201
- "--fps [frames]",
202
- Integer,
203
- "Number of frames to draw per second. #{DEFAULT_FPS} by default."
204
- ) {|value| @fps = value}
205
- options.on(
206
- "--view-width [pixels]",
207
- Integer,
208
- "Window width. #{DEFAULT_VIEW_WIDTH} by default."
209
- ) {|value| @view_width = value}
210
- options.on(
211
- "--view-height [pixels]",
212
- Integer,
213
- "Window height. #{DEFAULT_VIEW_HEIGHT} by default."
214
- ) {|value| @view_height = value}
215
-
216
- #Parse the options, printing usage if parsing fails.
217
- options.parse(arguments) rescue puts "#{$!}\nType '#{$0} --help' for valid options."
218
-
219
- end
220
-
221
-
222
- end
223
-
224
-
225
- begin
226
- #Create a server.
227
- server = ZypsServer.new
228
- #Parse the command line.
229
- server.process_options(ARGV)
230
- #Start the server.
231
- server.main
232
- rescue => exception
233
- #Print error to STDERR and exit with an abnormal status.
234
- abort "Error: " + exception.message + exception.backtrace.join("\n")
235
- end