Skip to content

Instantly share code, notes, and snippets.

@bgun
Created December 4, 2012 21:13
Show Gist options
  • Save bgun/4208753 to your computer and use it in GitHub Desktop.
Save bgun/4208753 to your computer and use it in GitHub Desktop.
Life Model Decoy
// Life Model Decoy - a FightCodeGame.com robot by bgun
function Robot(robot) {
this.myId = robot.id;
this.cloneId = 0;
this.hitCount = 0;
this.justCloned = false;
}
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.clone();
this.justCloned = true;
if(robot.parentId) {
// get away from parent before he shoots me!
if(this.justCloned) {
this.cloneId = robot.id;
this.justCloned = false;
robot.turn(36);
robot.back(400);
}
robot.ahead(80);
robot.rotateCannon(-60);
robot.back(160);
robot.rotateCannon(-60);
robot.turn(-20);
} else {
robot.ahead(200);
robot.rotateCannon(60);
robot.back(100);
robot.rotateCannon(60);
robot.turn(30);
}
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot;
robot = ev.robot;
sr = ev.scannedRobot;
if(sr.id != this.myId && sr.id != this.cloneId) {
robot.fire(1);
robot.rotateCannon(6)
robot.fire(1);
robot.rotateCannon(-3)
robot.fire(1);
robot.rotateCannon(-30);
}
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
this.hitCount++;
if(this.hitCount % 2 == 0) {
robot.turn(60 - ev.bulletBearing);
robot.back(150);
} else {
robot.turn(-60);
robot.ahead(200);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment