Created
December 3, 2012 15:04
-
-
Save AndreMeira/4195537 to your computer and use it in GitHub Desktop.
skaicoo
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
//FightCode can only understand your robot | |
//if its class is called Robot | |
var id; | |
var Robot = function(robot) { | |
id = this.id; | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
robot.ahead(50); | |
robot.clone(); | |
robot.life = 100; | |
robot.turn(90); | |
robot.log(robot); | |
if (robot.parentId != id) { | |
robot.rotateCannon(45); | |
robot.rotateCannon(90); | |
robot.turn(60); | |
robot.ahead(250); | |
return; | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if (scannedRobot.parentId == robot.id | |
|| scannedRobot.id == robot.parentId) { | |
return; | |
} | |
if (robot.parentId == id) { | |
robot.fire(); | |
robot.stop(); | |
robot.rotateCannon(40); | |
robot.stop(); | |
robot.fire(); | |
robot.stop(); | |
robot.ahead(10); | |
robot.fire(); | |
robot.turn(-30); | |
robot.ahead(10); | |
return; | |
} | |
for (var i=0; i<10; i++) { | |
robot.fire(); | |
robot.stop(); | |
robot.fire(); | |
robot.stop(); | |
robot.ahead(10); | |
robot.fire(); | |
robot.turn(-30); | |
robot.ahead(10); | |
} | |
return; | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.back(150); | |
robot.turn(60); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
robot.back(150); | |
robot.turn(60); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment