Skip to content

Instantly share code, notes, and snippets.

@raninho
Forked from guilhermef/robot.js
Created December 1, 2012 20:38
Show Gist options
  • Save raninho/4184873 to your computer and use it in GitHub Desktop.
Save raninho/4184873 to your computer and use it in GitHub Desktop.
Daniel San
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
};
rotated = false;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (this.shouldFire > 0){
robot.fire();
this.shouldFire = this.shouldFire - 1;
return;
}
robot.ahead(50);
robot.turn(90);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
return;
}
robot.fire();
this.shouldFire = 10;
robot.stop();
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.back(100);
robot.turn(ev.bearing + 90);
robot.rotateCannon(ev.bearing - 90);
robot.clone();
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing + 180);
robot.back(100);
robot.rotateCannon(ev.bearing);
robot.clone();
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bulletBearing);
robot.rotateCannon(ev.bearing);
robot.fire();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment