Asteroids

You can access the list of moving asteroids through the array game.asteroids

You can also find an asteroid with a specific id using game.findAsteroid(id), which returns an object represents the matched asteroid or null (if no asteroids are matching the provided id)

Creation

To create an asteroid, use game.addAsteroid({ options }).

Here is the list of accepted options:

(Note: Server will respond with Incorrect data when at least one input property value is improper)

OptionDescriptionDefault value (if omitted)
xX coordinate0
yY coordinate0
vxVelocity vector X component0
vyVelocity vector Y component0
sizeSize of the asteroid in the range [1-100]30

A new Asteroid object is immediately added to game.asteroids ; however, it cannot be used before it has been assigned an id (natural number, a.k.a non-negative integer) by the server.

Limits

You can only have 300 alive asteroids (including moving asteroids generated by the game mode) at any time in your game

The server will respond with Too many asteroids for each asteroid passing the limit

Accessible fields

For each asteroid object in game.asteroids, You have access to the same properties as the available ones when you add asteroids, plus some additional properties:

OptionDescription
gamePoints to the global game object
ida unique identifier for the asteroid

Configuration

Once an asteroid is live and has an assigned id, you can set options to it. For example:

> game.asteroids[0].set({x:0,y:0});
>

Will move the first asteroid in the list to the center of the map

List of accepted options when using asteroid.set:

OptionDescriptionServer response error message (if improper)
xX coordinateWrong coordinate
yY coordinateWrong coordinate
vxVelocity vector X componentWrong coordinate
vyVelocity vector Y componentWrong coordinate
sizeAsteroid size in the range [1-100] (note that changing asteroid size resets its life points)Incorrect size
killSet kill: (any "truthy" value, e.g: true) to destroy the asteroidNo violation