-
-
Save folkien/4200565 to your computer and use it in GitHub Desktop.
Folkien TTC
This file contains 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 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