Number thrust( [ power ] )
Optionally updates the power setting of the player ship's main engines to a value between 0 and 1, then returns the power setting. A thrust value of 0 corresponds to 0 acceleration, and a thrust value of 1 corresponds to 0.5 units/frame^2 of acceleration in the direction the player's ship is pointing.
power <Number>
Optional, clipped to the range [0, 1].
The current power setting of the player ship's main engines.
Number turn( [ power ] )
Optionally updates the power setting of the player ship's turning engines to a value between 1 (counterclockwise) and -1 (clockwise), then returns the power setting. A turn value of 1 corresponds to 0.005 radians/frame^2 of angular acceleration and a turn value of -1 corresponds to -0.005 radians/frame^2 of angular acceleration.
power <Number>
Clipped to the range [-1, 1].
The power setting of the player ship's turning engines.
Vector accel()
Gets the x, y, and angular acceleration of the player ship. The x and y acceleration are computed from the angular position of the ship and the power setting of its main engines, and are given in pixels/frame^2. The angular acceleration is computed from the power setting of the ship's turning engines, and is given in radians/frame^2.
An object with numeric 'x', 'y', and 'angular' properties.
Rectangle bounds()
Gets the player ship's current bounding box.
An object with numeric 'x', 'y', 'width', and 'height' properties.
Number health()
Gets the player's current health.
Vector pos()
Gets the x, y, and angular position of the player ship. The x and y position are given in pixels. The angular position, or rotation, is given in radians.
An object with numeric 'x', 'y', and 'angular' properties.
Vector vel()
Gets the x, y, and angular velocity of the player ship. The x and y velocity are given in pixels/frame. The angular velocity is given in radians/frame.
Extra info on the return value.
Array radar( [ filter ] )
Gets an array of game objects that the player ship can pick up on its sensors, optionally filtered by the given filter.
filter <String|Object|Function>
Optional, if set this will filter the output. If the filter is of type String, the output will be filtered by the 'type' property. If the filter is of type Object, the output will be filtered by all of its properties; for example, if the filter is { type: 'target', objective: 'reach' }, the output will only contain game objects that have a type of 'target' and an objective of 'reach'. If the filter is of type Function, it will pass each game object to the filter as an argument and will include it in the output only if the filter returns true. For example, radar('asteroid'), radar({ type: 'asteroid' }), and radar(function(obj) { return 'asteroid' === obj.type; }) all have the same return value.
The array of GameObjects.
See the radar usage example for more.
void fire( x, y )
Fires the currently equipped weapon in the direction (x, y). If called more than once, the latest direction will be used. If x and y are both zero, the weapon will not be fired.
x <Number>
The x-coordinate to aim at.
y <Number>
The y-coordinate to aim at.
See the weapons usage example for more.
void equip( [ weapon ] )
If weapon
is of type String, the weapon with that name is equipped. If weapon
is of type Weapon, the weapon with a name of weapon.name
is equipped. If no matching weapon is found or weapon
is not set, the current weapon is unequipped.
weapon <String|Weapon>
The weapon or name of the weapon to be equipped.
See the weapons usage example for more.
Weapon equipped()
Returns the currently equipped weapon object, or null if no weapon is currently equipped.
The currently equipped weapon.
See the weapons usage example for more.
Array weapons()
Gets an array of weapons available to the player ship.
The array of available Weapon objects.
See the weapons usage example for more.
Object load( key, [ defaultValue ] )
Loads a value with the given key from persistent storage.
key <String>
The key from which to load the value.
defaultValue <Object>
The default value to return if no value stored at key.
The value stored at the given key, or the defaultValue.
See the persistent variables example for more.
void store( key, value )
Stores a value at the given key in persistent storage.
key <String>
The key at which to store the given value.
value <Object>
The value to store at the given key.
See the persistent variables example for more.
void console.error( message )
Prints the given message to the console as an error. Pops out the console window if it is currently hidden.
message <String|Object>
If the message is of type Object, its JSON representation is printed instead.
void console.log( message )
Prints the given message to the console.
message <String|Object>
If the message is of type Object, its JSON representation is printed instead.
void console.warn( message )
Prints the given message to the console as a warning.
message <String|Object>
If the message is of type Object, its JSON representation is printed instead.