Skip to content

Instantly share code, notes, and snippets.

@folkien
Forked from sinbonders/robot.js
Created December 4, 2012 04:23
Show Gist options
  • Save folkien/4200565 to your computer and use it in GitHub Desktop.
Save folkien/4200565 to your computer and use it in GitHub Desktop.
Folkien TTC
var cloned;
var direction;
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
cloned = 0;
direction = 1;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(15);
robot.turn(23)
robot.rotateCannon(-direction);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var i = 0;
robot.clone();
if ((ev.scannedRobot.parentId == robot.id)||(ev.scannedRobot.id == robot.parentId)) {
robot.turn(15);
} else {
direction = (ev.bearing>0) ? 1 : -1;
for(i=0;i<5;i++) {
robot.fire();
robot.ahead(10);
}
robot.rotateCannon(ev.bearing);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.back(10);
robot.turn(-ev.bearing); // turn enought to be in a straight
// angle with the wall.
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment