Skip to content
Joshua Murphy edited this page Jul 17, 2016 · 40 revisions

Scripts

Each team has a script. A different instance of that script is run on each of the team's fighters. Click here for some example scripts. Any code outside of the update function is run at game start.

Arena

Each game is played in a flat, 2D plane. Each point in the plane has an x and a y coordinate. The x-axis is horizontal, and grows to the right. The y-axis is vertical, and grows downward. The origin, point (0, 0), is in the center of the plane. Each object has a position coordinate, which represents the center on that object within the arena.

The arena has boundaries, the dimensions of which are given by game.width by game.height. A fighter cannot leave this boundary.

Game Start

At the beginning of the game, each team is given four fighters. Each of those fighters is given an ID ranging from 0 to 3. The fighters are placed in their starting positions, and a new instance of each team's script is created for each fighter.

Events

Events are optional functions that can be included in any fighter script. Each event function is called when something happens, such as an enemy shooting, or an ally being destroyed. Each event (with the exception of update) is called in the cycle after the event takes place. The update event is called every cycle during the script step.

Physics

Movement

First, at the beginning of each cycle, acceleration is set to 0. Then, each movement function adds to the fighter's acceleration. Lastly, the magnitude of acceleration is clamped to be between 0 and 1, and acceleration is multiplied by thrust.

Turning

First, at the beginning of each cycle, turning is set to 0. Then, each turning function adds to the fighter's turning. Lastly, turning is clamped between -1 and 1, and multiplied by turnSpeed.

Velocity

Each cycle, during the physics step, each fighter's velocity is set based on the following:

velocity = (velocity + acceleration) * maxSpeed / (maxSpeed + thrust)

Where thrust is the maximum thrust of the fighter, not the current thrust in that cycle.

Combat

Each fighter starts with an amount of health equal to its maxHealth. Whenever a fighter is hit by a bullet, that fighter's health is decreased by the bullet's damage. When a fighter reaches 0 health, the fighter is destroyed.

Fighters can shoot bullets once every few frames. When a fighter shoots, a bullet is created traveling in the direction the fighter is facing, with a speed equal to the fighter's shootSpeed. Its cooldown is set to equal its shootCooldown. Cooldown will decrease by 1 every frame, until it reaches zero. A fighter cannot shoot while its cooldown is greater than zero.

Cycles

The game is played in cycles. By default, there are 50 cycles per second, but this may vary. Because of this, you should base any timing elements in your script on cycles, rather than real time. Here's a breakdown of what happens each cycle:

  1. Script Step
  • For each fighter:
  • Acceleration and turning are each set to 0.
  • Cooldown is decreased by 1.
  • Events from the previous cycle are called in the order that they occurred.
  • The update() event is called.
  • The magnitude of acceleration and turning are each capped at 1, then multiplied by thrust and turnSpeed respectively.
  1. Physics Step
  • Velocities are calculated.
  1. Collision Calculation
  • The collision point for each object is calculated.
  1. Collision Move
  • Objects move to their collision points.
  1. Move Step
  • Each object moves by its velocity, and rotates by its turning.

Clone this wiki locally