Skip to content

Instantly share code, notes, and snippets.

@neolao
Created December 6, 2012 17:08
Show Gist options
  • Save neolao/4226152 to your computer and use it in GitHub Desktop.
Save neolao/4226152 to your computer and use it in GitHub Desktop.
neolao
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.mainInstance;
this.enemyFound = false;
setInterval(this.move, 1000);
};
Robot.prototype.move = function() {
if (this.mainInstance) {
this.mainInstance.turn(45);
this.mainInstance.ahead(200);
}
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
this.mainInstance = robot;
if (!this.enemyFound) {
robot.ahead(10);
robot.turn(5);
robot.rotateCannon(5);
this.enemyFound = false;
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
this.enemyFound = true;
robot.fire();
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bulletBearing);
robot.ehead(200);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment