If you want to dive right in, check out the BerryBots API docs.
Ships start the game and each round with 100 energy (health).
Each turn, a ship receives data about enemy ships and gameplay events based on what it can see via line of sight. Then it can choose to fire a thruster, laser, and/or torpedo.
Firing a thruster alters the ship's trajectory. From a stand-still, the thruster force becomes the ship's speed and heading. If the ship is already moving, its speed and heading will be slightly modified. To stop, you would use this until speed is 0:
ship:fireThruster(ship:heading() + math.pi, ship:speed()).
A laser can be fired in any direction. A laser moves at a speed of 25 per tick and advances an extra 25 on the first tick after being fired. It dissipates when it hits a wall or inflicts 4 damage when it hits an enemy ship. A ship can fire another laser after 5 ticks.
A torpedo can be fired in any direction and with a specified distance. It moves at a speed of 12 and moves an extra 12 on the first tick after being fired. It moves through walls and ships until it reaches the specified distance, then explodes with a blast radius of 100. It does a maximum of 30 damage and 30 knockback at the center of the blast, scaling to 0 at the edge of the blast radius. A ship can fire another torpedo after 100 ticks.
Be careful: a ship can be hit by its own lasers and torpedos!
When a ship hits a wall, it bounces off. The wall absorbs half the force the ship exerts against the wall. If it just grazes the wall, this is only a small percentage of its speed; if it slams directly into a wall, it will lose half of its speed. It doesn't take any damage.
When two ships collide, they each transfer momentum to the other ship. No momentum is lost and neither ships take damage.
- The stage program's
configurefunction is called. It can use the passed StageBuilder object to configure the stage parameters - size, walls, starting points, and so on.
- Each ship's
initfunction is called with a reference to its Ship(s) and a World object it can query for information about the stage and state of the game.
- The stage's
initfunction is called with references to all initialized Ships, the World object, and an Admin object it can use to monitor the match, modify ships, and decide when the rounds and match end and who wins.
- Each ship program's
runfunction is called. It takes two parameters: a table of data about all enemy ships that are visible to one of the program's ships and a collection of visible gameplay events that occurred during physics processing the previous tick. It doesn't matter which ship runs first - it's as if they're all run simultaneously.
- Game physics are processed. All ships, lasers, and torpedos move, check for collisions, do damage, ships bounce off walls and each other, ships are destroyed, and gameplay events are generated.
- The stage program's
runfunction is called. It takes one parameter: a collection of all gameplay events that occurred in the previous step. With the Ship and World objects it already has, it's aware of everything going on in the game.
- If the stage calls
Admin:gameOver, the corresponding function is called in each of the Ship programs before returning control to the Stage's
- If graphics are enabled, the stage and ships are drawn to the screen.