Skip to content

Instantly share code, notes, and snippets.

@peterjaric
Created December 4, 2012 13:51
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 peterjaric/4204071 to your computer and use it in GitHub Desktop.
Save peterjaric/4204071 to your computer and use it in GitHub Desktop.
GnuPower
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.rotateCannon(90);
};
state = {shouldTurn: 0, forward: true};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (state.forward) {
robot.ahead(5);
}
else {
robot.back(5);
}
if (state.shouldTurn <= 0) {
robot.turn(state.forward ? 10 : -10);
}
state.shouldTurn--;
};
function notClone(robot1, robot2) {
return robot1.parentId != robot2.id && robot2.parentId != robot1.id;
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var enemy = ev.scannedRobot;
if (notClone(robot, enemy)) {
robot.fire();
state.shouldTurn = 10;
//robot.turn(state.forward ? 1 : -1);
}
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
state.shouldTurn = 0;
};
Robot.prototype.onWallCollision = function(ev) {
state.forward = !state.forward;
};
Robot.prototype.onRobotCollision = Robot.prototype.onWallCollision;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment