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)
Option | Description | Default value (if omitted) |
---|---|---|
x | X coordinate | 0 |
y | Y coordinate | 0 |
vx | Velocity vector X component | 0 |
vy | Velocity vector Y component | 0 |
size | Size 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:
Option | Description |
---|---|
game | Points to the global game object |
id | a 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
:
Option | Description | Server response error message (if improper) |
---|---|---|
x | X coordinate | Wrong coordinate |
y | Y coordinate | Wrong coordinate |
vx | Velocity vector X component | Wrong coordinate |
vy | Velocity vector Y component | Wrong coordinate |
size | Asteroid size in the range [1-100] (note that changing asteroid size resets its life points) | Incorrect size |
kill | Set kill: (any "truthy" value, e.g: true) to destroy the asteroid | No violation |