Skip to content

Instantly share code, notes, and snippets.

@olavph
Created December 4, 2012 15:01
Show Gist options
  • Save olavph/4204878 to your computer and use it in GitHub Desktop.
Save olavph/4204878 to your computer and use it in GitHub Desktop.
RoBoB
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
};
var speed = 2;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId == null ? speed > 0 : speed < 0)
robot.ahead(speed);
else
robot.back(speed);
robot.turn(1);
robot.rotateCannon(2);
};
Robot.prototype.onRobotCollision = function(ev) {
speed = -speed;
};
Robot.prototype.onWallCollision = function(ev) {
speed = -speed;
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id)
return;
robot.fire();
robot.turn(-20);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment