Rock Patrol

A ship in a field of rocks, and a queen with drones that hunt it and shoot at it. Each thing is one Erlang process that senses, decides and acts.

Connecting
Or use the arrow keys and the space bar. With no key for 5 seconds, the autopilot flies the ship.

The ship is a boid that you control

Its module has the behavior gen_boid. Its force is a rule of its own: a function that reads your keys. The autopilot is a list of rules of the library.

A shot sends a message

A shot senses the rock that it touches, and sends hit to that process. The rock starts two smaller rocks, and stops. The world removes a boid that stops.

The drones have a relation

Each drone has the relation guards to its queen, and follows it. A drone that sees the ship changes its rules: it hunts the ship, and shoots bolts at it. The lines show the relations.

The world is a graph

The number of swarms comes from boids:graph/2 and graph:components/1, one time each second.

Read the code of the game.