Created
December 4, 2012 12:38
-
-
Save stol/4203393 to your computer and use it in GitHub Desktop.
RobotRock1
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 found = 0; | |
//FightCode can only understand your robot | |
//if its class is called Robot | |
var Robot = function(robot) { | |
}; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
if (!found) | |
robot.rotateCannon(1); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
found = 1; | |
var robot = ev.robot ; | |
robot.fire(); | |
setTimeout(function(){ | |
found = 0; | |
}, 1); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
if (robot.angle < 180){ | |
if (robot.position.x < arenaWidth) | |
robot.ahead(100); | |
else | |
robot.behind(100); | |
} | |
else { | |
if (robot.position.x > 0) | |
robot.ahead(100); | |
else | |
robot.behind(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment