Game manual

The aim of this game is to programmatically control a cannon to shoot and destroy hordes of enemies. The cannon exposes a JavaScript API for you to use to control it. You will find some examples and a complete API reference below.

Every time an enemy reaches the cannon, the cannon loses 1 health point (out of 10). Once health goes down to 0, you lose.

The cannon can basically perform two actions: it can shoot or self-repair from damage taken. Both actions will require some time for the cannon to be ready again.

Aiming

You can aim the cannon using the function this.setCannonAngle (A), which takes as a parameter the angle you want to point the cannon at, measured in radians, counter-clockwise, starting from the horizontal (which means, 0 is horizontal, Math.PI / is vertical). The cannon has a minimum and maximum angle, which you can respectively read in the variables cannonMinAngle and cannonMaxAngle. When the function is called, the cannon starts moving towards the wanted angle. You can check what angle it currently is at using the function this.getCannonAngle().

Shooting

Using the function this.shoot(), the cannon will shoot if ready. After shooting, it will have to reload and won't be able to shoot for a while.

Repairing

You can recover your cannon's health with the function this.repair(). As for shooting, this will take some time for the cannon to be ready again to shoot or repair. Repair reload time is twice as long as shoot reload time.

Enemies

You can access information about the enemies via the this.getEnemies() function. Enemies can come both on the ground or in the air. The pattern they will follow depends on the test you choose.

Scoring

The score will be calculated as follows:
[survived time] + 5*[kills] + 20*[accuracy] - [repairs]

Examples

Basic shooting:

setup: function () { /* Miscellaneous setup things here */ }, update: function () { this.shoot(); // Shoots the cannon }

"Up'n'down":

setup: function() { this.setCannonAngle ( cannonMaxAngle ); }, update: function () { // Moves the cannon from up to down continuously if ( this.getCannonAngle() == cannonMaxAngle ) this.setCannonAngle ( cannonMinAngle ); if ( this.getCannonAngle() == cannonMinAngle ) this.setCannonAngle ( cannonMaxAngle ); this.shoot(); }

Repairing:

setup: function () { /* Miscellaneous setup things here */ }, update: function () { if ( this.hp() < 5 ) // EMERGENCY! Low health => repair this.repair(); this.shoot(); }

Cannon API reference

Methods:

this.shoot(): shoots the cannon; it works only if the cannon is ready; you can check that programmatically via the this.ready() function. The function returns 1 if the cannon could shoot, 0 otherwise.

this.repair(): repairs your cannon, restoring 1 hit point; it works only if the cannon is ready; you can check that programmatically via the this.ready() function. The function returns 1 if the cannon could repair, 0 otherwise.

this.setCannonAngle(A): tells the cannon to move to angle A, given in radians (0 means horizontal, Math.PI/2 means vertical - note that cannon angle has a maximum and a minimum, see more here).

this.getCannonAngle(): returns current cannon angle, in radians; 0 means horizontal and Math.PI/2 means vertical (note that cannon angle has a maximum and a minimum, see more here).

this.getEnemies(): returns the current alive enemies as an array; each element of the array is a two-element array [x,y], where x is the x coordinate of the enemy (0 is the cannon's base center position) and y is the vertical coordinate (0 is the ground). Enemies are sorted in ascending x order, so that the first element of the array is always the closest to the cannon.

this.ready(): returns 1 if the cannon is ready to shoot, or repair 0 otherwise.

this.hp(): returns the amount of hit points left the cannon has.

this.mark(i): you can use this function to mark the enemy of index i. The marked enemy is graphically highlighted. You can use this function for debugging purposes; you can mark only one enemy at a time, so the only actually marked enemy will be the last one on which this function was called.

this.unmark(): removes the mark from the currently marked enemy.

Constants:

cannonShootSpeed: the speed of the cannon projectile when shot.

g: gravity force.

controllerT: game time in seconds between two subsequent calls of the update() function (game time is measured with respect to the timer in the top left corner of game screen).

cannonMinAngle: minimum cannon angle.

cannonMaxAngle: maximum cannon angle.