Generate

From Scalable Game Design wiki
Jump to navigation Jump to search

GeneratePatternAnimation.gif

Description:In many gamelet situations one agent needs to generate a stream of other agents that move away, for example vehicles coming out of a tunnel, or electrons coming from an electron gun. The generator agent should create a generated agent next to itself (say to the right), with some probability. The generated agents, once created, move away to the right. The following code is for a tunnel creating a truck.

Real World Examples "I want a stream of bullets to come out of a gun when the user hits the spacebar" "I want a stream of cars to come out of tunnels based on some probability (some chance)"

PseudoCode: IF once every some seconds, THEN create an new agent to the right

AgentSheets Code:

GenerationPatternCode.png

You can also add probability to make the stream less predictable (this is good for cars coming out of a tunnel, for example) and you could make sure no agent is in front of your generating agent before you create another agent. Again, the following code is for a tunnel creating a truck.

PseudoCode: IF there's no agent already created, once every some seconds, some percent of the time THEN create an new agent to the right,

AgentSheets Code:

GenerationPatternCodeAdded.png


Games/Simulations that use this pattern