Skip to content

Instantly share code, notes, and snippets.

@Ghabriel
Created December 4, 2012 00:58
Show Gist options
  • Save Ghabriel/4199510 to your computer and use it in GitHub Desktop.
Save Ghabriel/4199510 to your computer and use it in GitHub Desktop.
Robot02
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
},
hasTarget = false,
emergency = false;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
//robot.stop();
//robot.log( hasTarget + '|' + emergency );
robot.clone();
if ( !hasTarget ){
robot.turn(23);
robot.ahead(20);
robot.rotateCannon(15);
} else if ( !emergency ) {
robot.ahead(5);
} else {
robot.rotateCannon(10);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot,
target = ev.scannedRobot;
//robot.stop();
if ( target.parentId == robot.id ||
target.id == robot.parentId ){
robot.turn(90);
robot.ahead(150);
return;
}
hasTarget = true;
/*robot.stop();
robot.fire();
robot.fire();
robot.back(42);
robot.turn(2);
robot.fire();*/
robot.stop();
robot.fire();
for (var i = 0; i < 3; i++){
robot.turn(20);
robot.ahead(18);
robot.turn(-20);
robot.fire();
}
hasTarget = false;
};
Robot.prototype.onWallCollision = function(ev){
var robot = ev.robot;
emergency = true;
//robot.stop();
robot.back(150);
robot.turn(60);
robot.rotateCannon(48);
robot.ahead(135);
hasTarget = false;
emergency = false;
}
Robot.prototype.onHitByBullet = function(ev){
var robot = ev.robot;
//robot.stop();
robot.turn(ev.bearing + 45);
robot.ahead(100);
robot.turn(-45);
robot.fire();
robot.turn(-10);
robot.fire();
}
Robot.prototype.onRobotCollision = function(ev){
var robot = ev.robot;
emergency = true;
//robot.stop();
robot.back(150);
robot.rotateCannon(ev.bearing);
robot.turn(ev.bearing + 15);
robot.fire();
robot.turn(60);
robot.rotateCannon(21);
robot.ahead(130)
hasTarget = false;
emergency = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment