Skip to content

Instantly share code, notes, and snippets.

@fwitzke
Forked from raninho/robot.js
Created December 5, 2012 23:33
Show Gist options
  • Save fwitzke/4220507 to your computer and use it in GitHub Desktop.
Save fwitzke/4220507 to your computer and use it in GitHub Desktop.
clone0002
//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