zyps 0.2.1 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +0 -14
- data/bin/zyps +240 -28
- data/bin/zyps_demo +18 -2
- data/doc/classes/Behavior.html +205 -0
- data/doc/classes/Behavior.src/M000003.html +18 -0
- data/doc/classes/Behavior.src/M000004.html +19 -0
- data/doc/classes/Clock.html +165 -0
- data/doc/classes/Clock.src/M000026.html +18 -0
- data/doc/classes/Clock.src/M000027.html +21 -0
- data/doc/classes/Color.html +299 -0
- data/doc/classes/Color.src/M000015.html +18 -0
- data/doc/classes/Color.src/M000016.html +16 -0
- data/doc/classes/Color.src/M000017.html +16 -0
- data/doc/classes/Color.src/M000018.html +16 -0
- data/doc/classes/Color.src/M000019.html +18 -0
- data/doc/classes/Color.src/M000020.html +22 -0
- data/doc/classes/Creature.html +176 -0
- data/doc/classes/Creature.src/M000005.html +19 -0
- data/doc/classes/Environment.html +203 -0
- data/doc/classes/Environment.src/M000028.html +19 -0
- data/doc/classes/Environment.src/M000029.html +45 -0
- data/doc/classes/EnvironmentalFactor.html +167 -0
- data/doc/classes/EnvironmentalFactor.src/M000021.html +18 -0
- data/doc/classes/GameObject.html +256 -0
- data/doc/classes/GameObject.src/M000022.html +20 -0
- data/doc/classes/GameObject.src/M000023.html +19 -0
- data/doc/classes/GameObject.src/M000024.html +16 -0
- data/doc/classes/GameObject.src/M000025.html +16 -0
- data/doc/classes/Location.html +167 -0
- data/doc/classes/Location.src/M000014.html +18 -0
- data/doc/classes/Responsive.html +143 -0
- data/doc/classes/Responsive.src/M000030.html +18 -0
- data/doc/classes/TrailsView.html +217 -0
- data/doc/classes/TrailsView.src/M000001.html +40 -0
- data/doc/classes/TrailsView.src/M000002.html +76 -0
- data/doc/classes/Utility.html +264 -0
- data/doc/classes/Utility.src/M000031.html +26 -0
- data/doc/classes/Utility.src/M000032.html +22 -0
- data/doc/classes/Utility.src/M000033.html +18 -0
- data/doc/classes/Utility.src/M000034.html +21 -0
- data/doc/classes/Utility.src/M000035.html +25 -0
- data/doc/classes/Utility.src/M000036.html +21 -0
- data/doc/classes/Utility.src/M000037.html +22 -0
- data/doc/classes/Vector.html +281 -0
- data/doc/classes/Vector.src/M000006.html +19 -0
- data/doc/classes/Vector.src/M000007.html +16 -0
- data/doc/classes/Vector.src/M000008.html +21 -0
- data/doc/classes/Vector.src/M000009.html +16 -0
- data/doc/classes/Vector.src/M000010.html +18 -0
- data/doc/classes/Vector.src/M000011.html +16 -0
- data/doc/classes/Vector.src/M000012.html +18 -0
- data/doc/classes/Vector.src/M000013.html +25 -0
- data/doc/created.rid +1 -0
- data/doc/files/COPYING_LESSER_txt.html +311 -0
- data/doc/files/COPYING_txt.html +1003 -0
- data/doc/files/README_txt.html +214 -0
- data/doc/files/lib/zyps/views/trails_rb.html +134 -0
- data/doc/files/lib/zyps_rb.html +134 -0
- data/doc/fr_class_index.html +38 -0
- data/doc/fr_file_index.html +31 -0
- data/doc/fr_method_index.html +63 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/zyps/views/trails.rb +3 -3
- metadata +81 -6
- data/bin/zyps_server +0 -178
data/README.txt
CHANGED
@@ -34,20 +34,6 @@ To see a tutorial on the library, at a command line, type:
|
|
34
34
|
|
35
35
|
zyps_demo
|
36
36
|
|
37
|
-
To run a DRb server others can connect to and add creatures (NOTE: not thoroughly tested and probably insecure!):
|
38
|
-
|
39
|
-
zyps_server [options]
|
40
|
-
-h, --help Display program help.
|
41
|
-
-m, --max-population [number] The maximum number of allowed game
|
42
|
-
objects. 25 by default.
|
43
|
-
-p, --port [number] Port number to run the server on.
|
44
|
-
If not defined, next available one
|
45
|
-
will be selected and the URI printed
|
46
|
-
to STDOUT.
|
47
|
-
-f, --fps [frames] Number of frames to draw per second.
|
48
|
-
--view-width [pixels] Window width. 800 by default.
|
49
|
-
--view-height [pixels] Window height. 600 by default.
|
50
|
-
|
51
37
|
|
52
38
|
== Development
|
53
39
|
|
data/bin/zyps
CHANGED
@@ -261,11 +261,16 @@ class Generator
|
|
261
261
|
end
|
262
262
|
|
263
263
|
|
264
|
+
|
264
265
|
#Keeps all objects within a set of walls.
|
265
|
-
class
|
266
|
+
class EncloseBehavior < Behavior
|
267
|
+
|
268
|
+
#Positions of walls.
|
266
269
|
attr_accessor :left, :top, :right, :bottom
|
270
|
+
|
267
271
|
def initialize
|
268
272
|
super
|
273
|
+
@left, @top, @right, @bottom = 0, 0, 0, 0
|
269
274
|
@actions << lambda do |boundary, object|
|
270
275
|
#If object is beyond a boundary, set its position equal to the boundary and reflect it.
|
271
276
|
if (object.location.x < @left) then
|
@@ -284,9 +289,11 @@ class Enclose < Behavior
|
|
284
289
|
end
|
285
290
|
end
|
286
291
|
end
|
292
|
+
|
287
293
|
end
|
288
294
|
|
289
295
|
|
296
|
+
|
290
297
|
class Application
|
291
298
|
|
292
299
|
#Tags to randomly choose from.
|
@@ -300,17 +307,18 @@ class Application
|
|
300
307
|
def initialize(width, height)
|
301
308
|
|
302
309
|
@width, @height = width, height
|
303
|
-
@tag_pool, @color_pool = [], []
|
304
310
|
@birth_rate = 1
|
305
|
-
|
311
|
+
@fps = 30.0
|
312
|
+
|
306
313
|
#Create a window, and set GTK up to quit when it is closed.
|
307
314
|
window = Gtk::Window.new
|
308
315
|
window.signal_connect("delete_event") {false}
|
309
316
|
window.signal_connect("destroy") {Gtk.main_quit}
|
310
317
|
|
311
|
-
#
|
312
|
-
|
313
|
-
|
318
|
+
#Set up controls.
|
319
|
+
window.add(create_controls)
|
320
|
+
|
321
|
+
#Show all widgets.
|
314
322
|
window.show_all
|
315
323
|
|
316
324
|
#Create environment.
|
@@ -324,8 +332,9 @@ class Application
|
|
324
332
|
|
325
333
|
def main
|
326
334
|
|
335
|
+
|
327
336
|
#Keep all objects within a boundary.
|
328
|
-
enclose =
|
337
|
+
enclose = EncloseBehavior.new()
|
329
338
|
enclose.left = 0
|
330
339
|
enclose.right = @width
|
331
340
|
enclose.top = 0
|
@@ -333,30 +342,41 @@ class Application
|
|
333
342
|
@environment.environmental_factors << EnvironmentalFactor.new([enclose])
|
334
343
|
|
335
344
|
#Create a creature generator.
|
336
|
-
generator = Generator.new(@environment, 0, 0, @width, @height)
|
337
|
-
generator.tag_pool = @tag_pool
|
338
|
-
generator.color_pool = @color_pool
|
345
|
+
@generator = Generator.new(@environment, 0, 0, @width, @height)
|
339
346
|
|
340
347
|
#Create thread to update environment.
|
341
348
|
thread = Thread.new do
|
349
|
+
|
342
350
|
begin
|
351
|
+
|
352
|
+
drawing_clock = Clock.new
|
343
353
|
birth_clock = Clock.new
|
354
|
+
time_per_frame = 1.0 / @fps
|
344
355
|
time_since_birth = 0
|
356
|
+
|
345
357
|
loop do
|
358
|
+
|
346
359
|
@environment.interact
|
360
|
+
|
347
361
|
#Control population.
|
348
362
|
@environment.objects.shift while @environment.objects.length > 25
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
363
|
+
|
364
|
+
#Determine how much time is left in this frame.
|
365
|
+
time_left_in_frame = (time_per_frame) - drawing_clock.elapsed_time
|
366
|
+
#Sleep for the remaining time.
|
367
|
+
if time_left_in_frame > 0
|
368
|
+
sleep time_left_in_frame
|
369
|
+
#Skip a frame if things are going too slow.
|
370
|
+
else
|
371
|
+
sleep time_per_frame
|
353
372
|
end
|
354
|
-
|
355
|
-
sleep 1.0 / 60.0
|
373
|
+
|
356
374
|
end
|
375
|
+
|
357
376
|
rescue Exception => exception
|
358
377
|
puts exception, exception.backtrace
|
359
378
|
end
|
379
|
+
|
360
380
|
end
|
361
381
|
|
362
382
|
#Activate the GUI.
|
@@ -364,28 +384,220 @@ class Application
|
|
364
384
|
|
365
385
|
end
|
366
386
|
|
387
|
+
|
388
|
+
#Create a view and controls.
|
389
|
+
def create_controls(width = @width, height = @height, homogeneous = false, spacing = 0, expand = false, fill = false, padding = 0)
|
390
|
+
|
391
|
+
#Create a container for the view and controls.
|
392
|
+
interface = Gtk::HBox.new(homogeneous, spacing)
|
393
|
+
|
394
|
+
#Add view to interface.
|
395
|
+
@view = TrailsView.new(width, height)
|
396
|
+
interface.pack_start(@view.canvas, expand, fill, padding)
|
397
|
+
#Get mouse events on view.
|
398
|
+
@view.canvas.add_events(Gdk::Event::BUTTON_PRESS_MASK)
|
399
|
+
@view.canvas.signal_connect("button-press-event") do |canvas, event|
|
400
|
+
@press_location = Location.new(event.x, event.y)
|
401
|
+
end
|
402
|
+
@view.canvas.add_events(Gdk::Event::BUTTON_RELEASE_MASK)
|
403
|
+
@view.canvas.signal_connect("button-release-event") do |canvas, event|
|
404
|
+
@release_location = Location.new(event.x, event.y)
|
405
|
+
creature = Creature.new(
|
406
|
+
'',
|
407
|
+
@release_location,
|
408
|
+
Color.new(@red_slider.value, @green_slider.value, @blue_slider.value),
|
409
|
+
Vector.new(
|
410
|
+
Utility.find_distance(@press_location, @release_location) * 2, #Use distance dragged as speed.
|
411
|
+
Utility.find_angle(@press_location, @release_location) #Move in direction of drag.
|
412
|
+
),
|
413
|
+
0,
|
414
|
+
@tags_box.text.split(/,\s*/)
|
415
|
+
)
|
416
|
+
behavior = Behavior.new
|
417
|
+
condition_tags = @tag_condition_box.text
|
418
|
+
condition_tags.split(/,\s*/).each do |tag|
|
419
|
+
behavior.conditions << lambda do |creature, target|
|
420
|
+
target.tags.include?(tag)
|
421
|
+
end
|
422
|
+
end
|
423
|
+
proximity = @proximity_condition_slider.value
|
424
|
+
if proximity > 0
|
425
|
+
behavior.conditions << lambda do |creature, target|
|
426
|
+
Utility.find_distance(creature.location, target.location) < proximity
|
427
|
+
end
|
428
|
+
end
|
429
|
+
age = @age_condition_slider.value
|
430
|
+
if age > 0
|
431
|
+
behavior.conditions << lambda do |creature, target|
|
432
|
+
target.age > age
|
433
|
+
end
|
434
|
+
end
|
435
|
+
acceleration = @acceleration_slider.value
|
436
|
+
if acceleration != 0
|
437
|
+
behavior.actions << lambda do |creature, target|
|
438
|
+
creature.vector.speed += acceleration
|
439
|
+
creature.vector.speed = 0 if creature.vector.speed < 0
|
440
|
+
end
|
441
|
+
end
|
442
|
+
turn = @turn_slider.value
|
443
|
+
if turn != 0
|
444
|
+
behavior.actions << lambda do |creature, target|
|
445
|
+
creature.vector.pitch += turn
|
446
|
+
end
|
447
|
+
end
|
448
|
+
approach_angle = @approach_slider.value
|
449
|
+
if approach_angle > 0
|
450
|
+
heading = creature.vector.clone
|
451
|
+
behavior.actions << lambda do |creature, target|
|
452
|
+
#Find the difference between the current heading and the angle to the target.
|
453
|
+
turn_angle = Utility.find_angle(creature.location, target.location) - heading.pitch
|
454
|
+
#If the angle is the long way around from the current heading, change it to the smaller angle.
|
455
|
+
if turn_angle > 180 then
|
456
|
+
turn_angle -= 360.0
|
457
|
+
elsif turn_angle < -180 then
|
458
|
+
turn_angle += 360.0
|
459
|
+
end
|
460
|
+
#If turn angle is greater than allowed turn speed, reduce it.
|
461
|
+
turn_angle = Utility.constrain_value(turn_angle, approach_angle)
|
462
|
+
#Turn the appropriate amount.
|
463
|
+
heading.pitch += turn_angle
|
464
|
+
#Apply the heading to the creature's movement vector.
|
465
|
+
creature.vector += heading
|
466
|
+
end
|
467
|
+
end
|
468
|
+
flee_angle = @flee_slider.value
|
469
|
+
if flee_angle > 0
|
470
|
+
heading = creature.vector.clone
|
471
|
+
behavior.actions << lambda do |creature, target|
|
472
|
+
#Find the difference between the current heading and the angle to the target.
|
473
|
+
turn_angle = Utility.find_angle(creature.location, target.location) - heading.pitch + 180
|
474
|
+
#If the angle is the long way around from the current heading, change it to the smaller angle.
|
475
|
+
if turn_angle > 180 then
|
476
|
+
turn_angle -= 360.0
|
477
|
+
elsif turn_angle < -180 then
|
478
|
+
turn_angle += 360.0
|
479
|
+
end
|
480
|
+
#If turn angle is greater than allowed turn speed, reduce it.
|
481
|
+
turn_angle = Utility.constrain_value(turn_angle, flee_angle)
|
482
|
+
#Turn the appropriate amount.
|
483
|
+
heading.pitch += turn_angle
|
484
|
+
#Apply the heading to the creature's movement vector.
|
485
|
+
creature.vector += heading
|
486
|
+
end
|
487
|
+
end
|
488
|
+
if @eat_flag.active?
|
489
|
+
behavior.actions << lambda do |creature, target|
|
490
|
+
@environment.objects.delete(target)
|
491
|
+
end
|
492
|
+
end
|
493
|
+
apply_tags = @tag_action_box.text
|
494
|
+
apply_tags.split(/,\s*/).each do |tag|
|
495
|
+
behavior.conditions << lambda do |creature, target|
|
496
|
+
target.tags << tag unless target.tags.include?(tag)
|
497
|
+
end
|
498
|
+
end
|
499
|
+
creature.behaviors << behavior
|
500
|
+
@environment.objects << creature
|
501
|
+
end
|
502
|
+
|
503
|
+
#Create a VBox for all controls.
|
504
|
+
control_panel = Gtk::VBox.new(homogeneous, spacing)
|
505
|
+
|
506
|
+
#Create a group for the new object's attributes.
|
507
|
+
attribute_controls = Gtk::VBox.new(homogeneous, spacing)
|
508
|
+
|
509
|
+
#Add sliders for the color components.
|
510
|
+
attribute_controls.pack_start(Gtk::Label.new("Color"), expand, fill, padding)
|
511
|
+
attribute_controls.pack_start(Gtk::Label.new("R"), expand, fill, padding)
|
512
|
+
@red_slider = Gtk::HScale.new(0, 1, 0.1)
|
513
|
+
attribute_controls.pack_start(@red_slider, expand, fill, padding)
|
514
|
+
attribute_controls.pack_start(Gtk::Label.new("G"), expand, fill, padding)
|
515
|
+
@green_slider = Gtk::HScale.new(0, 1, 0.1)
|
516
|
+
attribute_controls.pack_start(@green_slider, expand, fill, padding)
|
517
|
+
attribute_controls.pack_start(Gtk::Label.new("B"), expand, fill, padding)
|
518
|
+
@blue_slider = Gtk::HScale.new(0, 1, 0.1)
|
519
|
+
attribute_controls.pack_start(@blue_slider, expand, fill, padding)
|
520
|
+
@red_slider.value, @green_slider.value, @blue_slider.value = 1, 1, 1
|
521
|
+
|
522
|
+
#Add a text box for the tags.
|
523
|
+
attribute_controls.pack_start(Gtk::Label.new("Tags"), expand, fill, padding)
|
524
|
+
@tags_box = Gtk::Entry.new
|
525
|
+
attribute_controls.pack_start(@tags_box, expand, fill, padding)
|
526
|
+
|
527
|
+
#Add the attribute controls to the panel.
|
528
|
+
control_panel.pack_start(attribute_controls, expand, fill, padding)
|
529
|
+
|
530
|
+
#Create a group for the conditions.
|
531
|
+
condition_controls = Gtk::VBox.new(homogeneous, spacing)
|
532
|
+
condition_controls.pack_start(Gtk::Label.new("Target"), expand, fill, padding)
|
533
|
+
#Add a text box for the tag condition.
|
534
|
+
condition_controls.pack_start(Gtk::Label.new("Tags"), expand, fill, padding)
|
535
|
+
@tag_condition_box = Gtk::Entry.new
|
536
|
+
condition_controls.pack_start(@tag_condition_box, expand, fill, padding)
|
537
|
+
#Add a slider for the age condition.
|
538
|
+
@age_condition_slider = Gtk::HScale.new(0, 300, 30)
|
539
|
+
condition_controls.pack_start(Gtk::Label.new("Age"), expand, fill, padding)
|
540
|
+
condition_controls.pack_start(@age_condition_slider, expand, fill, padding)
|
541
|
+
#Add a slider for the proximity condition.
|
542
|
+
@proximity_condition_slider = Gtk::HScale.new(1, 100, 10)
|
543
|
+
condition_controls.pack_start(Gtk::Label.new("Proximity"), expand, fill, padding)
|
544
|
+
condition_controls.pack_start(@proximity_condition_slider, expand, fill, padding)
|
545
|
+
#Add the condition controls to the panel.
|
546
|
+
control_panel.pack_start(condition_controls, expand, fill, padding)
|
547
|
+
|
548
|
+
#Create a group for the actions.
|
549
|
+
action_controls = Gtk::VBox.new(homogeneous, spacing)
|
550
|
+
action_controls.pack_start(Gtk::Label.new("Actions"), expand, fill, padding)
|
551
|
+
#Add a slider for the accelerate action.
|
552
|
+
@acceleration_slider = Gtk::HScale.new(-10, 10, 2)
|
553
|
+
action_controls.pack_start(Gtk::Label.new("Accelerate"), expand, fill, padding)
|
554
|
+
action_controls.pack_start(@acceleration_slider, expand, fill, padding)
|
555
|
+
@acceleration_slider.value = 0
|
556
|
+
#Add a slider for the turn action.
|
557
|
+
@turn_slider = Gtk::HScale.new(-180, 180, 20)
|
558
|
+
action_controls.pack_start(Gtk::Label.new("Turn"), expand, fill, padding)
|
559
|
+
action_controls.pack_start(@turn_slider, expand, fill, padding)
|
560
|
+
@turn_slider.value = 0
|
561
|
+
#Add a slider for the approach angle.
|
562
|
+
@approach_slider = Gtk::HScale.new(-180, 180, 20)
|
563
|
+
action_controls.pack_start(Gtk::Label.new("Approach"), expand, fill, padding)
|
564
|
+
action_controls.pack_start(@approach_slider, expand, fill, padding)
|
565
|
+
@approach_slider.value = 0
|
566
|
+
#Add a slider for the flee action.
|
567
|
+
@flee_slider = Gtk::HScale.new(-180, 180, 20)
|
568
|
+
action_controls.pack_start(Gtk::Label.new("Flee"), expand, fill, padding)
|
569
|
+
action_controls.pack_start(@flee_slider, expand, fill, padding)
|
570
|
+
@flee_slider.value = 0
|
571
|
+
#Add a checkbox for the eat action.
|
572
|
+
@eat_flag = Gtk::CheckButton.new("Eat")
|
573
|
+
action_controls.pack_start(@eat_flag, expand, fill, padding)
|
574
|
+
#Add a checkbox for the spawn action.
|
575
|
+
#TODO
|
576
|
+
#Add a text box for the tag action.
|
577
|
+
action_controls.pack_start(Gtk::Label.new("Apply Tag"), expand, fill, padding)
|
578
|
+
@tag_action_box = Gtk::Entry.new
|
579
|
+
action_controls.pack_start(@tag_action_box, expand, fill, padding)
|
580
|
+
#Add the action controls to the panel.
|
581
|
+
control_panel.pack_start(action_controls, expand, fill, padding)
|
582
|
+
|
583
|
+
#Add the control panel to the interface.
|
584
|
+
interface.pack_start(control_panel, expand, fill, padding)
|
585
|
+
|
586
|
+
interface
|
587
|
+
|
588
|
+
end
|
589
|
+
|
367
590
|
|
368
591
|
end
|
369
592
|
|
370
593
|
|
371
594
|
begin
|
372
|
-
TAG_POOL = %w{x y z}
|
373
|
-
COLOR_POOL = [
|
374
|
-
Color.new(1, 0, 0),
|
375
|
-
Color.new(1, 0.75, 0),
|
376
|
-
Color.new(1, 1, 0),
|
377
|
-
Color.new(0, 1, 0),
|
378
|
-
Color.new(0, 0, 1),
|
379
|
-
Color.new(1, 0, 1)
|
380
|
-
]
|
381
595
|
#The view width.
|
382
596
|
WIDTH = 500
|
383
597
|
#The view height.
|
384
|
-
HEIGHT =
|
598
|
+
HEIGHT = 600
|
385
599
|
#Run the application.
|
386
600
|
application = Application.new(WIDTH, HEIGHT)
|
387
|
-
application.color_pool = COLOR_POOL
|
388
|
-
application.tag_pool = TAG_POOL
|
389
601
|
application.main
|
390
602
|
rescue => exception
|
391
603
|
#Print error to STDERR and exit with an abnormal status.
|
data/bin/zyps_demo
CHANGED
@@ -36,6 +36,8 @@ class Demo
|
|
36
36
|
HEIGHT = 300
|
37
37
|
#Number of frames to draw per demo.
|
38
38
|
FRAME_COUNT = 80
|
39
|
+
#Number of frames per second.
|
40
|
+
FRAMES_PER_SECOND = 30
|
39
41
|
|
40
42
|
#Set up a window, a canvas, and an object environment, then run the given block.
|
41
43
|
def demo
|
@@ -70,15 +72,28 @@ class Demo
|
|
70
72
|
|
71
73
|
#Animate an environment for a given number of frames.
|
72
74
|
def animate(frame_count)
|
75
|
+
|
76
|
+
#A clock to track frames to draw this second.
|
77
|
+
clock = Clock.new
|
78
|
+
time_per_frame = 1.0 / FRAMES_PER_SECOND
|
79
|
+
|
73
80
|
begin
|
74
81
|
(1..frame_count).each do |i|
|
75
82
|
@environment.interact
|
76
|
-
#
|
77
|
-
|
83
|
+
#Determine how much time is left in this frame.
|
84
|
+
time_left_in_frame = (time_per_frame) - clock.elapsed_time
|
85
|
+
#Sleep for the remaining time.
|
86
|
+
if time_left_in_frame > 0
|
87
|
+
sleep time_left_in_frame
|
88
|
+
#Skip a frame if things are going too slow.
|
89
|
+
else
|
90
|
+
sleep time_per_frame
|
91
|
+
end
|
78
92
|
end
|
79
93
|
rescue Exception => exception
|
80
94
|
puts exception, exception.backtrace
|
81
95
|
end
|
96
|
+
|
82
97
|
end
|
83
98
|
|
84
99
|
|
@@ -176,6 +191,7 @@ class Demo
|
|
176
191
|
end
|
177
192
|
|
178
193
|
|
194
|
+
|
179
195
|
#Demonstrates creature behaviors.
|
180
196
|
def test_behaviors
|
181
197
|
|
@@ -0,0 +1,205 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Behavior</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Behavior</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/zyps_rb.html">
|
59
|
+
lib/zyps.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
<div id="description">
|
82
|
+
<p>
|
83
|
+
A behavior that a <a href="Creature.html">Creature</a> or <a
|
84
|
+
href="EnvironmentalFactor.html">EnvironmentalFactor</a> object (or other
|
85
|
+
classes that include <a href="Responsive.html">Responsive</a>) engage in.
|
86
|
+
The target can have its tags or colors changed, it can be
|
87
|
+
"herded", it can be destroyed, or any other action the library
|
88
|
+
user can dream up. Likewise, the subject can change its own attributes, it
|
89
|
+
can approach or flee from the target, it can spawn <a
|
90
|
+
href="Behavior.html#M000003">new</a> Creatures or GameObjects (like
|
91
|
+
bullets), or anything else.
|
92
|
+
</p>
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<div id="method-list">
|
100
|
+
<h3 class="section-bar">Methods</h3>
|
101
|
+
|
102
|
+
<div class="name-list">
|
103
|
+
<a href="#M000003">new</a>
|
104
|
+
<a href="#M000004">perform</a>
|
105
|
+
</div>
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
|
110
|
+
|
111
|
+
<!-- if includes -->
|
112
|
+
|
113
|
+
<div id="section">
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<div id="attribute-list">
|
120
|
+
<h3 class="section-bar">Attributes</h3>
|
121
|
+
|
122
|
+
<div class="name-list">
|
123
|
+
<table>
|
124
|
+
<tr class="top-aligned-row context-row">
|
125
|
+
<td class="context-item-name">actions</td>
|
126
|
+
<td class="context-item-value"> [RW] </td>
|
127
|
+
<td class="context-item-desc">
|
128
|
+
A list of actions, which are Proc objects called with the object and its
|
129
|
+
target when all conditions are met. An action can act on the subject or its
|
130
|
+
target.
|
131
|
+
|
132
|
+
</td>
|
133
|
+
</tr>
|
134
|
+
<tr class="top-aligned-row context-row">
|
135
|
+
<td class="context-item-name">conditions</td>
|
136
|
+
<td class="context-item-value"> [RW] </td>
|
137
|
+
<td class="context-item-desc">
|
138
|
+
A list of conditions, which are Proc objects called with the object itself
|
139
|
+
and its target. A condition can consider the tags on the target, the
|
140
|
+
distance from the subject, or any other criteria. If any condition returns
|
141
|
+
false, the behavior will not be carried out.
|
142
|
+
|
143
|
+
</td>
|
144
|
+
</tr>
|
145
|
+
</table>
|
146
|
+
</div>
|
147
|
+
</div>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<!-- if method_list -->
|
152
|
+
<div id="methods">
|
153
|
+
<h3 class="section-bar">Public Class methods</h3>
|
154
|
+
|
155
|
+
<div id="method-M000003" class="method-detail">
|
156
|
+
<a name="M000003"></a>
|
157
|
+
|
158
|
+
<div class="method-heading">
|
159
|
+
<a href="Behavior.src/M000003.html" target="Code" class="method-signature"
|
160
|
+
onclick="popupCode('Behavior.src/M000003.html');return false;">
|
161
|
+
<span class="method-name">new</span><span class="method-args">(actions = [], conditions = [])</span>
|
162
|
+
</a>
|
163
|
+
</div>
|
164
|
+
|
165
|
+
<div class="method-description">
|
166
|
+
<p>
|
167
|
+
Optionally takes an array of actions and one of conditions.
|
168
|
+
</p>
|
169
|
+
</div>
|
170
|
+
</div>
|
171
|
+
|
172
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
173
|
+
|
174
|
+
<div id="method-M000004" class="method-detail">
|
175
|
+
<a name="M000004"></a>
|
176
|
+
|
177
|
+
<div class="method-heading">
|
178
|
+
<a href="Behavior.src/M000004.html" target="Code" class="method-signature"
|
179
|
+
onclick="popupCode('Behavior.src/M000004.html');return false;">
|
180
|
+
<span class="method-name">perform</span><span class="method-args">(subject, target)</span>
|
181
|
+
</a>
|
182
|
+
</div>
|
183
|
+
|
184
|
+
<div class="method-description">
|
185
|
+
<p>
|
186
|
+
Calls each Proc object in the list of conditions with the subject and its
|
187
|
+
target. Returns nil if any condition returns false. Then calls each Proc
|
188
|
+
object in the list of actions, also with the subject and its target.
|
189
|
+
</p>
|
190
|
+
</div>
|
191
|
+
</div>
|
192
|
+
|
193
|
+
|
194
|
+
</div>
|
195
|
+
|
196
|
+
|
197
|
+
</div>
|
198
|
+
|
199
|
+
|
200
|
+
<div id="validator-badges">
|
201
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
202
|
+
</div>
|
203
|
+
|
204
|
+
</body>
|
205
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>new (Behavior)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/zyps.rb, line 170</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span> (<span class="ruby-identifier">actions</span> = [], <span class="ruby-identifier">conditions</span> = [])
|
15
|
+
<span class="ruby-ivar">@actions</span>, <span class="ruby-ivar">@conditions</span> = <span class="ruby-identifier">actions</span>, <span class="ruby-identifier">conditions</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>perform (Behavior)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/zyps.rb, line 176</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">perform</span>(<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">target</span>)
|
15
|
+
<span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">condition</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">condition</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">target</span>)}
|
16
|
+
<span class="ruby-identifier">actions</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">action</span><span class="ruby-operator">|</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">target</span>)}
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|