Skip to content

Instantly share code, notes, and snippets.

@brycec
Created December 4, 2012 00:57
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 brycec/4199505 to your computer and use it in GitHub Desktop.
Save brycec/4199505 to your computer and use it in GitHub Desktop.
run n gun
//FightCode can only understand your robot
//if its class is called Robot
var friends = {}, id;
var Robot = function(robot) {
id = robot.id;
// friends is the set all friendly robots
friends[id] = id;
clone = robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId == id) friends[robot.id] = robot.id;
robot.turn(-60);
robot.ahead(45);
robot.turn(250);
robot.back(20);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.stop();
robot.rotateCannon(3);
// if not friendly
if (!(ev.scannedRobot.id in friends)) {
robot.fire();
robot.log(robot);
robot.ahead(75);
robot.turn(22);
robot.turn(-23);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment