Skip to content

Instantly share code, notes, and snippets.

@bobmatnyc
Forked from folkien/robot.js
Created December 6, 2012 23:58
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 bobmatnyc/4229545 to your computer and use it in GitHub Desktop.
Save bobmatnyc/4229545 to your computer and use it in GitHub Desktop.
Folkien TT2
var direction;
var start;
var runaway;
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
if(robot.parentId){
direction = 1;
} else {
direction = -1;
}
start = 0;
runaway = 0;
robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (!start) {
if(robot.parentId){
robot.ahead(100);
robot.turnLeft(45);
robot.rotateCannon(20 * direction);
}
else {
robot.back(100);
}
start = 1;
}
robot.rotateCannon(20 * direction);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var i = 0;
if ((ev.scannedRobot.parentId == robot.id)||(ev.scannedRobot.id == robot.parentId)) {
robot.turn(15);
} else {
//Gdy szefunio
direction = (ev.bearing>0) ? 1 : -1;
for(i=0;i<5;i++) {
robot.fire();
robot.ahead(1);
robot.fire();
}
robot.rotateCannon(-20*direction);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.stop();
robot.turn(90-(ev.bearing)); // turn enought to be in a straight
if (runaway) robot.ahead(100);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var wrog = ev.collidedRobot;
if((wrog.parentId = robot.id)||(wrog.id==robot.parentId)) {
robot.turn(20*direction);
robot.ahead(100); // trying to run away
} else {
robot.turn(ev.bearing);
robot.fire();
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.stop();
runaway = 1;
if (ev.bearing > 0 ) {
robot.back(100);
direction = 1
} else {
robot.ahead(100);
direction = -1;
} // so we can see who shot it
runaway = 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment