Skip to content

Instantly share code, notes, and snippets.

@mwclarkson
Forked from HugoLnx/robot.js
Created December 3, 2012 20:28
Show Gist options
  • Select an option

  • Save mwclarkson/4197744 to your computer and use it in GitHub Desktop.

Select an option

Save mwclarkson/4197744 to your computer and use it in GitHub Desktop.
CrazyGiroscope
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
function include(el, array) {
for(var i = 0; i < array.length; i++){
if(el === array[i]) return true;
}
return false;
}
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
if(robot.position.y > 20) {
if(robot.parentId) {
robot.turn(90-robot.angle);
robot.ahead(300);
}
robot.turn(-robot.angle);
robot.ahead(robot.position.y);
robot.turn(90);
}
robot.rotateCannon(180);
robot.rotateCannon(-180);
robot.ahead(100);
robot.ahead(100);
robot.back(100);
robot.back(100);
//robot.ahead(100);
//robot.rotateCannon(360);
//robot.back(100);
//robot.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned = ev.scannedRobot;
if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
robot.fire();
robot.rotateCannon(20);
robot.fire();
robot.rotateCannon(-20);
robot.fire();
robot.rotateCannon(-20);
robot.fire();
robot.rotateCannon(20);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment