Skip to content

Instantly share code, notes, and snippets.

@guilhermef
Created November 28, 2012 16:23
Show Gist options
  • Save guilhermef/4162323 to your computer and use it in GitHub Desktop.
Save guilhermef/4162323 to your computer and use it in GitHub Desktop.
exterminussun do futuro
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
this.shouldFire = 0;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (this.shouldFire > 0){
robot.ahead(10);
robot.fire();
this.shouldFire = this.shouldFire - 1;
return;
}
robot.clone();
robot.listen('onScannedRobot');
robot.ahead(100);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
this.shouldFire = 10;
robot.ignore('onScannedRobot');
robot.stop();
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.listen('onScannedRobot');
if (robot.parentId){
robot.turn(ev.bearing + 90);
robot.rotateCannon(ev.bearing + 90);
} else {
robot.turn(ev.bearing - 90);
robot.rotateCannon(ev.bearing - 90);
}
robot.ahead(40);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.rotateCannon(ev.bearing);
robot.turn(ev.bearing + 90);
robot.ahead(20)
this.shouldFire = 10;
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(45 - ev.bulletBearing);
robot.rotateCannon(ev.bulletBearing);
robot.fire();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment