Skip to content

Instantly share code, notes, and snippets.

@n-west
Forked from guilhermebruzzi/robot.js
Created December 4, 2012 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-west/4202147 to your computer and use it in GitHub Desktop.
Save n-west/4202147 to your computer and use it in GitHub Desktop.
Merry Go round
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot){
//robot.clone();
this.robotOptions = {
clone: {
canStartFight: false,
goBackOnCollision: false
}
};
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId == null) {
robot.turn(1);
} else {
if (this.robotOptions.clone.canStartFight) {
robot.turn(1);
} else {
robot.back(100);
this.robotOptions.clone.canStartFight = true;
}
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot,
scannedRobot = ev.scannedRobot;
//if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
//return;
//}
for (var i=0; i<5; i++) {
robot.fire();
robot.ahead(10);
}
};
Robot.prototype.onWallCollision = function(ev) {
ev.robot.turn(10);
};
Robot.prototype.onRobotCollided = function(ev) {
if (ev.robot.parentId == null) {
ev.robot.back(20);
} else {
ev.robot.ahead(20);
}
};
Robot.prototype.onHitByBullet = function(ev) {
ev.robot.turn(ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment