From: James Britt Date: Nov 6, 6:23 pm Subject: November Phoenix Ruby User Group Meeting (PLEASE NOTE NEW LOCATION!) To: Phoenix Ruby Users Group November Phoenix Ruby User Group Meeting Date: Monday, November 12, 2007 Time: 7:00pm Place: Rising Tide Software ... Topics: * A recap of the recent RubyConf 2007 by people who were *Actually There!* * A demo of the Zyps game library by Jay McGavren! * Maybe some other stuff!
I prepped a tutorial on the dRuby server, which I’ve copied here…
First, install Zyps:
sudo gem install zyps
Run Ruby in interactive mode:
irb
Load the libraries for remote communication:
require 'rubygems' require 'zyps/remote' include Zyps
Set up a proxy to the remote environment:
uri = 'druby://lappy486:8989' environment = EnvironmentClient.get_environment(uri)
Create a creature:
creature = Creature.new creature.location = Location.new(200, 100) #x, y creature.vector = Vector.new(45, 50) #angle, speed creature.size = 50
Add it to the environment:
environment.objects << creature
Let’s make one that actually does something.
A Behavior has one or more Actions.
chase = Behavior.new chase.actions << ApproachAction.new(360, Vector.new(50, 0))
Copy our first Creature…
cat = creature.copy
This cat will be orange…
cat.color = Color.new(1, 0.75, 0)
Add the Behavior…
cat.behaviors << chase
And add it to the environment.
environment.objects << cat
Add a few more…
5.times {|i| environment.objects << cat.copy}
Behaviors also have Conditions.
These limit the circumstances under which Actions occur.
Let’s make a timid Creature that flees when others get too close.
run = Behavior.new run.actions << FleeAction.new(360, Vector.new(60, 0)) run.conditions << ProximityCondition.new(200)
Copy a creature…
mouse = creature.copy mouse.size = 10
Add the Behavior…
mouse.behaviors << run
And add several to the Environment.
5.times {|i| environment.objects << mouse.copy}
EnvironmentalFactors affect all the objects at once.
Let’s mix it up and add some wind.
environment.environmental_factors << Accelerator.new(Vector.new(200, 0))
There are many other Actions, Conditions, and EnvironmentalFactors to play with. Read about them in the API docs: