Skip to content

Instantly share code, notes, and snippets.

@danielepolencic
Created December 9, 2012 14:22
Show Gist options
  • Save danielepolencic/4245168 to your computer and use it in GitHub Desktop.
Save danielepolencic/4245168 to your computer and use it in GitHub Desktop.
daniele
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
// {
// robot: {
// // INFORMATION ON THE CURRENT GAME
// id, // Id from your robot
// angle, // Current angle from your robot in degrees
// cannonRelativeAngle, // Current angle from your cannon
// // relative to your robot
// cannonAbsoluteAngle, // Current angle from your cannon
// // relative to the board
// position: {
// x, // X position in the board from your robot
// y // Y position in the board from your robot
// },
// life, // Percentage of the life from your robot
// gunCoolDownTime, // Time remaining in the cooldown from your
// // cannon after shooting
// availableClones, // Number of available clones you can use
// parentId, // In the case of being a clone, the id
// // from your parent element. null otherwise
// arenaWidth, // Width from the board
// arenaHeight // Height from the board
//
// // AVAILABLE ACTIONS
//
// // Moves the given amount ahead
// ahead: function(amount),
//
// // Moves the given amount backwards
// back: function(amount),
//
// // Rotates your cannon angle by the specified number of degrees
// rotateCannon: function(amount),
//
// // Rotates your robot the by the specified number of degrees
// turn: function(amount),
//
// // Fires your cannon. This functin has a cooldown before you can
// // use it again.
// fire: function(),
//
// // Subscribe to get notified whenever this action gets called
// // in the queue.
// notify: function(callback),
//
// // Removes all remaining actions your robot has from the queue
// stop: function(),
//
// // Clones your robot into another robot and can only be used once
// // per fight. Remember to check the parentId property to stop
// // your clone from shooting you.
// clone: function(),
//
// // Stops your robot from listening a given event (onWallColision,
// // for instance).
// ignore: function(eventName),
//
// // Starts listening a given event (onWallColision, for instance).
// listen: function(eventName)
// }
// }
var robot = ev.robot;
robot.ahead(100);
// robot.rotateCannon(360);
// robot.back(100);
// robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
// Inside ev
// {
// robot: {
// // Same as onIdle
// },
// scannedRobot: {
// id, // Id from the robot
// position: {
// x, // X position from the other robot relative to the board
// },
// angle, // Angle from the other robot
// cannonAngle, // Cannon angle relative to the other robot
// life, // Percentage of life from the other robot
// parentId // If this is a clone, the clone's parent id.
// // null otherwise
// }
// }
var robot = ev.robot;
robot.fire();
};
Robot.prototype.onRobotCollision = function(ev) {
// Inside ev
// {
// robot: {
// // Same as onIdle
// },
// bearing, // Degrees that the other robot relative to my robot
// // this property can vary from -180 to 180 degrees
// collidedRobot: { // Information on the robot that collided with mine
// id, // Id from the robot
// position: {
// x, // X position from the other robot relative to the board
// y // Y position from the other robot relative to the board
// },
// angle, // Angle from the other robot
// cannonAngle, // Cannon angle relative to the other robot
// life, // Percentage of life from the other robot
// parentId // If this is a clone, the clone's parent id.
// // null otherwise
// },
// myFault // Boolean value that indicates whether I hit the other
// // robot or the opposite
// }
var robot = ev.robot;
robot.turn(20);
robot.ahead(100); // trying to run away
};
Robot.prototype.onWallCollision = function(ev) {
// Inside ev
// {
// robot: {
// // Same as onIdle
// },
// bearing // Degrees of the wall relative to my robot
// // this property can vary from -180 to 180 degrees
// }
var robot = ev.robot;
robot.turn(ev.bearing); // turn enought to be in a straight
// angle with the wall.
robot.turn( 90 );
var turn = 90 - robot.cannonRelativeAngle + 90;
robot.rotateCannon( turn );
};
Robot.prototype.onHitByBullet = function(ev) {
// Inside ev
// {
// robot: {
// // Same as onIdle
// },
// bearing // angle that the bullet came from relative
// // to my tank's angle
// }
var robot = ev.robot;
robot.turn(ev.bearing); // Turn to wherever the bullet was fired
// so we can see who shot it
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment