-
-
Save rfloriano/4209019 to your computer and use it in GitHub Desktop.
RoBoB
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
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
robot.clone(); | |
}; | |
var speed = 2; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (robot.parentId == null ? speed > 0 : speed < 0) | |
robot.ahead(speed); | |
else | |
robot.back(speed); | |
robot.turn(1); | |
robot.rotateCannon(2); | |
}; | |
Robot.prototype.onRobotCollision = function(ev) { | |
speed = -speed; | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
speed = -speed; | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
var scannedRobot = ev.scannedRobot; | |
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) | |
return; | |
robot.fire(); | |
robot.turn(-20); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment