Sourcer

Sourcer A game that fights using JavaScript programs.

Let's write code and fight against others'.

Overview

This is a game playing a match using an aircraft operating with a JavaScript program called sourcer.

Rule

The goal of a game is for attack the opponent's shield to 0, winning the game.

Attack

Laser
The laser flies straight. The laser ammo is unlimited.
Missile
The missile can be operating with a JavaScript program like sourcer. The missile ammo is 20. Missiles can be shot down with a laser.

Status

Shield
Initial value 100. The shield will decrease when attacked. When the shield of your sourcer runs out, you lose.
Temperature
Initial value 0. It will rise when you attack or get damaged. When the temperature exceeds 100, the shield gradually decreases. The temperature gradually decreases.
Fuel
Initial value 100. Fuel is reduced as you move. When the fuel runs out, it can not move.
Missile ammo
Initial value 20.

Other

  • There is a ground at a position where the altitude is 0, Touching the ground reduces shielding.
  • Sourcer is pulled by gravity and gradually attracted to the ground unless it moves. Lasers and missiles are not affected by gravity.

Program

Register the program by returning function.

You can operate with the controller of the argument.

var bot = function(controller) {
  if (controller.altitude() < 100) {
    // ascent when the altitude goes down.
    controller.ascent();
  }
  controller.ahead();
};
return bot;

Entry commands by the controller => Command execution => Entry command => Execution => ... will be repeated.

Behavior that can be done with the controller.

Move
Ahead, back, ascent, descent.
Radar
Scanning enemies, Scanning flying attacks.
Attack
Laser launch, missile launch.
Check status
Check shield, temperature, fuel, missile ammo.

If you use radar, the time to the next action will be longer.

Only one attack is accepted in a single action.

The missile program is specified as an argument when fire command.

var missile = function(controller) {
  if(controller.scanEnemy(90, 180)) {
    controller.turnLeft();
  } else {
    controller.turnRight();
  }
  controller.speedUp();
};

var bot = function(controller) {
  // ...
  controller.fireMissile(missile);
  // ...
};
return bot;

API Documents

SourcerController

Controller for operating sourcer.

Methods

frame()

Get the number of frames since starting.

returns {number}
The number of frames since starting.
altitude()

Get current altitude.

returns {number}
Current altitude.
wait(frame)

Wait for the specified number of frames.

{number} frame
Number of frames to make to wait.
shield()

Get the shield value.

returns {number}
The shield value.
fuel()

Get the fuel value.

returns {number}
The fuel value.
temperature()

Get the temperature value.

returns {number}
The temperature value.
missileAmmo()

Get the missile ammo value.

returns {number}
The missile ammo value.
scanEnemy(direction, angle, renge)

Scans for enemies in the specified direction, range and distance.

{number} direction
Direction of the radar. The direction of Sourcer is 0, the upward direction is a positive value, the downward direction is a negative value.
{number} angle
The width angle of the radar.
{number} renge
The distance renge of the radar. If omitted, it is judged regardless of the distance.
returns {boolean}
True if an enemy was in the specified range.
Sample
controller.scanEnemy(45, 60, 75);

In case of rightward

In case of leftward

controller.scanEnemy(-45, 120, 50);

In case of rightward

In case of leftward

scanAttack(direction, angle, renge)

Scans for enemy attack in the specified direction, range and distance.

{number} direction
Direction of the radar. The direction of Sourcer is 0, the upward direction is a positive value, the downward direction is a negative value.
{number} angle
The width angle of the radar.
{number} renge
The distance renge of the radar. If omitted, it is judged regardless of the distance.
returns {boolean}
True if an enemy attack was in the specified range.
ahead()

Move forward.

back()

Move backward.

ascent()

Move upward.

descent()

Move downward.

turn()

Turn the opposite direction.

fireLaser(direction, power)

Fire the laser.

{number} direction
Direction of the radar. The direction of Sourcer is 0, the upward direction is a positive value, the downward direction is a negative value.
{number} power
Power to launch.
fireMissile(source)

Fire the missile.

{function} source
Function for controlling missiles.
log(message)

Show the message to the screen.

{string} message
Message to output

You can also use console.log()

scanDebug(direction, angle, renge)

Show the circular sector for the specified direction, range and distance.

{number} direction
Direction of the circular sector. The direction of Sourcer is 0, the upward direction is a positive value, the downward direction is a negative value.
{number} angle
The width angle of the circular sector.
{number} renge
The distance renge of the circular sector. If omitted, It is filled with tentative value.

MissileController

Controller for operating missile.

Methods

frame()

Get the number of frames since starting.

returns {number}
The number of frames since starting.
altitude()

Get current altitude.

returns {number}
Current altitude.
wait(frame)

Wait for the specified number of frames.

{number} frame
Number of frames to make to wait.
fuel()

Get the fuel value.

returns {number}
The fuel value.
direction()

Get the direction of the missile.
The right horizontal direction is 0, the counterclockwise direction is a positive value, the clockwise direction is a negative value.

returns {number}
The direction of the missile.
scanEnemy(direction, angle, renge)

Scans for enemies in the specified direction, range and distance.
Please note that the range specification method is different from Source.

{number} direction
Direction of the radar. The direction of missile is 0, the counterclockwise direction is a positive value, the clockwise direction is a negative value.
{number} angle
The width angle of the radar.
{number} renge
The distance renge of the radar. If omitted, it is judged regardless of the distance.
returns {boolean}
True if an enemy attack was in the specified range.
Sample
controller.scanEnemy(45, 60, 75);

In case of upward

In case of downward

In case of rightward

In case of leftward

speedUp()

Increase the speed.

speedDown()

Reduce the speed.

turnRight()

Turn to the right.

turnLeft()

Turn to the left.

log(message)

Show the message to the screen.

{string} message
Message to output

You can also use console.log()

scanDebug(direction, angle, renge)

Show the circular sector for the specified direction, range and distance.

{number} direction
Direction of the circular sector. The direction of Sourcer is 0, the upward direction is a positive value, the downward direction is a negative value.
{number} angle
The width angle of the circular sector.
{number} renge
The distance renge of the circular sector. If omitted, It is filled with tentative value.