Created
December 4, 2012 03:52
-
-
Save folkien/4200349 to your computer and use it in GitHub Desktop.
Folkien TT2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
robot.stop(); | |
//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