Module Ship

A ship controlled by a user written program.

Functions

alive () Whether the ship is currently alive.
energy () The ship's energy.
fireLaser (heading) Fires a laser at the given angle.
fireThruster (angle, force) Fires the ship's thruster, pushing it in the given direction and altering its speed and/or heading.
fireTorpedo (heading, distance) Fires a torpedo the given distance at the given angle.
heading () The ship's heading, in radians (0 is east, pi / 2 is north).
hitShip () Whether the ship hit another ship on the previous tick.
hitWall () Whether the ship hit a wall on the previous tick.
isStageShip () Whether the ship was loaded by the stage.
laserGunHeat () The heat of the ship's laser gun.
name () The name of the ship.
setLaserColor (r, g, b) Sets the color of the ship's lasers, in RGB (0-255).
setName (name) Sets the name of the ship.
setShipColor (r, g, b) Sets the color of the ship's hull, in RGB (0-255).
setTeamName (teamName) Sets the name of the ship's team.
setThrusterColor (r, g, b) Sets the color of the ship's thruster, in RGB (0-255).
speed () The ship's speed.
teamName () The name of the team this ship is part of.
torpedoGunHeat () The heat of the ship's torpedo gun.
x () The x coordinate of the ship (higher is to the right).
y () The y coordinate of the ship (higher is to the top).


Functions

alive ()

Whether the ship is currently alive.

Return value:

true if the ship is alive, false otherwise.
energy ()

The ship's energy. A ship with energy <= 0 is destroyed.

Return value:

The ship's energy
fireLaser (heading)

Fires a laser at the given angle. All lasers move at the same speed (25), do the same amount of damage (4), and cool at the same rate (5 ticks).

Parameters

  • heading: The angle at which to fire the laser, in radians (0 is east, pi / 2 is north).

Return value:

true if the laser was fired, false otherwise (if battle mode is disabled, if the laser gun was not cool, or if it was disabled by the stage).
fireThruster (angle, force)

Fires the ship's thruster, pushing it in the given direction and altering its speed and/or heading. This command only affects one tick - if you don't call it again the next tick, your ship will keep moving with the same speed and heading.

Note that momentum is cumulative. From a dead stop, your ship will move in the given direction, but if your ship is already moving, the thruster force is added to your current movement vector. If you want to keep things simple and always move in straight lines, you can stop moving in one direction before starting to move in another: ship:fireThruster(ship:heading() + math.pi, ship:speed())

Parameters

  • angle: The angle the thruster will push the ship in, in radians (0 is east, pi / 2 is north).
  • force: The force of the thruster push, 0 <= force <= 1. A force of 1 alters the ship's speed by 1 along the axis of the thruster angle.

Return value:

true if the thruster was fired, false otherwise (if the thruster has been disabled by the stage).
fireTorpedo (heading, distance)

Fires a torpedo the given distance at the given angle. All torpedos move at the same speed (12), do the same amount of damage, and cool at the same rate (100 ticks). Torpedos move through walls and ships until they reach the specified distance. They inflict damage and knockback on all ships within the blast radius (100), doing the most damage and knockback to ships near the center of the blast.

The damage and knockback formulas are both:
30 / (1 - square(distance to blast center / blast radius))

Ships near the center of the blast radius take nearly full damage, while ships at a distance of 50 take 25% damage and knockback.

Parameters

  • heading: The angle at which to fire the torpedo, in radians (0 is east, pi / 2 is north).
  • distance: The distance to fire the torpedo.

Return value:

true if the torpedo was fired, false otherwise (if battle mode is disabled, if the torpedo gun was not cool, or if it was disabled by the stage).
heading ()

The ship's heading, in radians (0 is east, pi / 2 is north).

Return value:

The ship's heading.
hitShip ()

Whether the ship hit another ship on the previous tick.

Return value:

true if the ship hit another ship on the previous tick, false otherwise.
hitWall ()

Whether the ship hit a wall on the previous tick.

Return value:

true if the ship hit a wall on the previous tick, false otherwise.
isStageShip ()

Whether the ship was loaded by the stage.

Return value:

true if the ship is part of the stage, false otherwise.
laserGunHeat ()

The heat of the ship's laser gun. A heat of 0 means the gun can be fired, a heat of 3 means the gun can be fired 3 ticks from now.

Return value:

The heat of the ship's laser gun.
name ()

The name of the ship.

Return value:

The name of the ship.
setLaserColor (r, g, b)

Sets the color of the ship's lasers, in RGB (0-255).

Parameters

  • r: The amount of red, from 0 to 255.
  • g: The amount of green, from 0 to 255.
  • b: The amount of blue, from 0 to 255.
setName (name)

Sets the name of the ship. This function can only be called during init.

Parameters

  • name: The name of the ship.
setShipColor (r, g, b)

Sets the color of the ship's hull, in RGB (0-255).

Parameters

  • r: The amount of red, from 0 to 255.
  • g: The amount of green, from 0 to 255.
  • b: The amount of blue, from 0 to 255.
setTeamName (teamName)

Sets the name of the ship's team. This function can only be called during init.

Parameters

  • teamName: The name of the team this ship is part of.
setThrusterColor (r, g, b)

Sets the color of the ship's thruster, in RGB (0-255).

Parameters

  • r: The amount of red, from 0 to 255.
  • g: The amount of green, from 0 to 255.
  • b: The amount of blue, from 0 to 255.
speed ()

The ship's speed.

Return value:

The ship's speed.
teamName ()

The name of the team this ship is part of.

Return value:

The name of the team this ship is part of.
torpedoGunHeat ()

The heat of the ship's torpedo gun. A heat of 0 means the gun can be fired, a heat of 50 means the gun can be fired 50 ticks from now.

Return value:

The heat of the ship's torpedo gun.
x ()

The x coordinate of the ship (higher is to the right).

Return value:

The x coordinate of the ship.
y ()

The y coordinate of the ship (higher is to the top).

Return value:

The y coordinate of the ship.