Skip to content

Instantly share code, notes, and snippets.

@rfloriano
Forked from olavph/robot.js
Created December 4, 2012 21:40
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 rfloriano/4209019 to your computer and use it in GitHub Desktop.
Save rfloriano/4209019 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