Skip to content

Instantly share code, notes, and snippets.

@bobmatnyc
Forked from ronualdo/robot.js
Created December 11, 2012 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobmatnyc/4258774 to your computer and use it in GitHub Desktop.
Save bobmatnyc/4258774 to your computer and use it in GitHub Desktop.
Proto1
var cannonRotation = 5;
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.turn(360 - robot.angle);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(10);
if (robot.cannonRelativeAngle <= 90) {
cannonRotation = 5;
} else if (robot.cannonRelativeAngle >= 270) {
cannonRotation = -5;
}
robot.rotateCannon(cannonRotation);
if (robot.energy < 50 && robot.availableClones) {
robot.clone;
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scannedRobot = ev.scannedRobot;
if (scannedRobot.parentId == null || !scanneRobot.parentId == robot.id) {
robot.fire();
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(90);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.back(200);
}
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.back(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment