Created
December 4, 2012 20:56
-
-
Save AndreMeira/4208570 to your computer and use it in GitHub Desktop.
white poney and the big shark
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; | |
this.locked = false; | |
robot.ahead(50); | |
robot.clone(); | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (this.locked) { | |
return; | |
} | |
robot.ahead(150); | |
robot.turn(45); | |
if (robot.parentId == id) { | |
robot.turn(45); | |
robot.ahead(5); | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if (scannedRobot.parentId == robot.id | |
|| scannedRobot.id == robot.parentId) { | |
return; | |
} | |
if (this.locked) { | |
return; | |
} | |
this.locked = true; | |
robot.stop(); | |
for (var i=0; i<10; i++) { | |
robot.fire(); | |
} | |
this.locked = false; | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
robot.turn(ev.bearing); | |
robot.back(50); | |
robot.turn(ev.bearing - 45); | |
robot.back(50); | |
robot.turn(ev.bearing - 45); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
var robot = ev.robot; | |
robot.back(150); | |
robot.turn(60); | |
robot.ahead(150); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment