zyps 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/zyps CHANGED
@@ -164,6 +164,14 @@ class Application < Wx::App
164
164
  evt_timer(timer_id) {on_timer}
165
165
  timer.start(milliseconds_per_frame)
166
166
 
167
+
168
+ if @options[:uri]
169
+ @log.debug "Start a network service at #{@options[:uri]}."
170
+ server = EnvironmentServer.new(@environment, @options[:uri])
171
+ server.start
172
+ $SAFE = 1
173
+ end
174
+
167
175
  @log.debug "Display GUI."
168
176
  frame.send_size_event
169
177
  frame.show
@@ -181,7 +189,12 @@ class Application < Wx::App
181
189
  @enclosure.right = @drawing_area.size.width
182
190
  end
183
191
  #Update environment.
184
- @environment.interact
192
+ begin
193
+ @environment.interact
194
+ rescue Exception => exception
195
+ puts exception, exception.backtrace
196
+ raise
197
+ end
185
198
  #If there are no Creatures, show instructions on creating them.
186
199
  if @environment.objects.empty?
187
200
  @view.canvas.buffer.draw do |dc|
@@ -711,9 +724,7 @@ class CreatureGenerator
711
724
  if options[:turn]
712
725
  color.blue += 1
713
726
  creature.behaviors << Behavior.new(
714
- :actions => [TurnAction.new(@turn_rate, @turn_angle)],
715
- :conditions => [ProximityCondition.new(options[:action_proximity] * 2)],
716
- :condition_frequency => 20
727
+ :actions => [TurnAction.new(@turn_rate, @turn_angle)]
717
728
  )
718
729
  end
719
730
  if options[:approach]
data/lib/zyps/actions.rb CHANGED
@@ -66,6 +66,7 @@ end
66
66
  class FaceAction < Action
67
67
  #Set the actor's heading to point directly at first target.
68
68
  def do(actor, targets)
69
+ return if targets.empty?
69
70
  actor.vector.pitch = Utility.find_angle(actor.location, targets[0].location)
70
71
  end
71
72
  end
@@ -104,6 +105,7 @@ end
104
105
  class ApproachAction < TimedAction
105
106
  #Accelerate toward the first target, but limited by rate.
106
107
  def do(actor, targets)
108
+ return if targets.empty?
107
109
  #Apply thrust to the creature's movement vector, adjusted by elapsed time.
108
110
  actor.vector += Vector.new(
109
111
  delta,
@@ -117,6 +119,7 @@ end
117
119
  class FleeAction < TimedAction
118
120
  #Accelerate away from the first target, but limited by turn rate.
119
121
  def do(actor, targets)
122
+ return if targets.empty?
120
123
  #Apply thrust to the creature's movement vector, adjusted by elapsed time.
121
124
  actor.vector += Vector.new(
122
125
  delta,
@@ -71,6 +71,52 @@ class Enclosure < EnvironmentalFactor
71
71
  end
72
72
 
73
73
 
74
+ #When an object crosses its boundary, warps object to opposite boundary.
75
+ class WrapAround < EnvironmentalFactor
76
+
77
+ #X coordinate of left boundary.
78
+ attr_accessor :left
79
+ #Y coordinate of top boundary.
80
+ attr_accessor :top
81
+ #X coordinate of right boundary.
82
+ attr_accessor :right
83
+ #Y coordinate of bottom boundary.
84
+ attr_accessor :bottom
85
+
86
+ #Takes a hash with these keys and defaults:
87
+ # :left => 0
88
+ # :top => 0
89
+ # :right => 0
90
+ # :bottom => 0
91
+ def initialize(options = {})
92
+ options = {
93
+ :left => 0,
94
+ :top => 0,
95
+ :right => 0,
96
+ :bottom => 0
97
+ }.merge(options)
98
+ self.left, self.top, self.right, self.bottom = options[:left], options[:top], options[:right], options[:bottom]
99
+ end
100
+
101
+ #If object is beyond a boundary, set its position to that of opposite boundary.
102
+ def act(environment)
103
+ environment.objects.each do |object|
104
+ if (object.location.x < @left) then
105
+ object.location.x = @right
106
+ elsif (object.location.x > @right) then
107
+ object.location.x = @left
108
+ end
109
+ if (object.location.y > @top) then
110
+ object.location.y = @bottom
111
+ elsif (object.location.y < @bottom) then
112
+ object.location.y = @top
113
+ end
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+
74
120
  #Keeps all objects at/under the assigned speed.
75
121
  class SpeedLimit < EnvironmentalFactor
76
122
 
data/lib/zyps.rb CHANGED
@@ -358,6 +358,7 @@ class Behavior
358
358
  #Calls select(actor, targets) on each Condition, each time discarding targets that fail.
359
359
  #Then on each Action, calls Action#start(actor, targets) (if not already started) followed by Action#do(actor, targets).
360
360
  #If no matching targets are found, calls Action#stop(actor, targets) on each Action.
361
+ #If there are no conditions, actions will occur regardless of targets.
361
362
  def perform(actor, targets)
362
363
 
363
364
  if condition_evaluation_turn?
@@ -365,11 +366,11 @@ class Behavior
365
366
  conditions.each {|condition| @current_targets = condition.select(actor, @current_targets)}
366
367
  end
367
368
  actions.each do |action|
368
- if ! @current_targets.empty?
369
+ if @current_targets.empty? and ! @conditions.empty?
370
+ action.stop(actor, targets) #Not @current_targets; that array is empty.
371
+ else
369
372
  action.start(actor, @current_targets) unless action.started?
370
373
  action.do(actor, @current_targets)
371
- else
372
- action.stop(actor, targets) #Not @current_targets; that array is empty.
373
374
  end
374
375
  end
375
376
 
data/test/test_zyps.rb CHANGED
@@ -574,5 +574,26 @@ class TestBehavior < Test::Unit::TestCase
574
574
  assert_not_same(original.conditions[0], copy.conditions[0], "Conditions in list should not be same objects.")
575
575
  end
576
576
 
577
+ def test_no_conditions
578
+ #Set up a behavior with no conditions.
579
+ action = MockAction.new
580
+ behavior = Behavior.new(:conditions => [], :actions => [action])
581
+ #Perform the behavior with no targets.
582
+ behavior.perform(@actor, [])
583
+ assert_equal(1, action.start_count, "start() should have been called on the mock action.")
584
+ assert_equal(1, action.do_count, "do() should have been called.")
585
+ assert_equal(0, action.stop_count, "stop() should NOT have been called.")
586
+ #Add a true condition.
587
+ behavior.conditions << TrueCondition.new
588
+ #Perform the behavior with no targets.
589
+ behavior.perform(@actor, [])
590
+ assert_equal(1, action.stop_count, "stop() should have been called.")
591
+ #Perform the behavior WITH targets.
592
+ behavior.perform(@actor, @targets)
593
+ assert_equal(2, action.start_count, "start() should have been called.")
594
+ assert_equal(2, action.do_count, "do() should have been called.")
595
+ assert_equal(1, action.stop_count, "stop() should NOT have been called.")
596
+ end
597
+
577
598
 
578
599
  end
@@ -89,6 +89,55 @@ end
89
89
 
90
90
 
91
91
 
92
+ class TestWrapAround < Test::Unit::TestCase
93
+
94
+ def test_wrap_around
95
+
96
+ creature = Creature.new
97
+ environment = Environment.new(:objects => [creature])
98
+
99
+ #Create a WrapAround.
100
+ wrapper = WrapAround.new(
101
+ :left => 1,
102
+ :top => 3,
103
+ :right => 3,
104
+ :bottom => 1
105
+ )
106
+
107
+ #Place creature outside the walls, and act on it.
108
+ #Ensure it's moved inside on opposite side.
109
+ creature.location = Location.new(0, 2) #Too far left.
110
+ wrapper.act(environment)
111
+ assert_equal(3, creature.location.x)
112
+ assert_equal(2, creature.location.y)
113
+
114
+ creature.location = Location.new(4, 2) #Too far right.
115
+ wrapper.act(environment)
116
+ assert_equal(1, creature.location.x)
117
+ assert_equal(2, creature.location.y)
118
+
119
+ creature.location = Location.new(2, 0) #Too far down.
120
+ wrapper.act(environment)
121
+ assert_equal(2, creature.location.x)
122
+ assert_equal(3, creature.location.y)
123
+
124
+ creature.location = Location.new(2, 4) #Too far up.
125
+ wrapper.act(environment)
126
+ assert_equal(2, creature.location.x)
127
+ assert_equal(1, creature.location.y)
128
+
129
+ #Place creature inside the walls, and ensure it's unaffected.
130
+ creature.location = Location.new(2, 2) #Inside.
131
+ wrapper.act(environment)
132
+ assert_equal(2, creature.location.x)
133
+ assert_equal(2, creature.location.y)
134
+
135
+ end
136
+
137
+ end
138
+
139
+
140
+
92
141
  class TestSpeedLimit < Test::Unit::TestCase
93
142
 
94
143
  def test_speed_limit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zyps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay McGavren
@@ -9,7 +9,7 @@ autorequire: zyps
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-05 00:00:00 -07:00
12
+ date: 2008-02-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,24 +36,24 @@ files:
36
36
  - COPYING.txt
37
37
  - README_windows.txt
38
38
  - README.txt
39
- - bin/zyps
40
39
  - bin/zyps_demo
40
+ - bin/zyps
41
41
  - lib/zyps
42
42
  - lib/zyps/views
43
43
  - lib/zyps/views/canvas
44
44
  - lib/zyps/views/canvas/wx.rb
45
45
  - lib/zyps/views/trails.rb
46
- - lib/zyps/actions.rb
47
- - lib/zyps/environmental_factors.rb
48
46
  - lib/zyps/conditions.rb
49
47
  - lib/zyps/remote.rb
48
+ - lib/zyps/actions.rb
49
+ - lib/zyps/environmental_factors.rb
50
50
  - lib/zyps.rb
51
51
  - test/zyps
52
52
  - test/zyps/test_behaviors.rb
53
53
  - test/zyps/test_actions.rb
54
- - test/zyps/test_environmental_factors.rb
55
54
  - test/zyps/test_conditions.rb
56
55
  - test/zyps/test_remote.rb
56
+ - test/zyps/test_environmental_factors.rb
57
57
  - test/test_zyps.rb
58
58
  has_rdoc: true
59
59
  homepage: http://jay.mcgavren.com/zyps/
@@ -85,4 +85,9 @@ signing_key:
85
85
  specification_version: 2
86
86
  summary: A game library for Ruby
87
87
  test_files:
88
+ - test/zyps/test_behaviors.rb
89
+ - test/zyps/test_actions.rb
90
+ - test/zyps/test_conditions.rb
91
+ - test/zyps/test_remote.rb
92
+ - test/zyps/test_environmental_factors.rb
88
93
  - test/test_zyps.rb