Created
December 5, 2012 18:44
-
-
Save olavph/4218338 to your computer and use it in GitHub Desktop.
DUMMYBOT
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) { | |
}; | |
var radius = 100; | |
Robot.prototype.onIdle = function(ev) { | |
var robot = ev.robot; | |
var centerX = robot.arenaWidth / 2; | |
var centerY = robot.arenaHeight / 2; | |
var relX = centerX - robot.position.x; | |
var relY = centerY - robot.position.y; | |
var relAngle = Math.atan2(relY, relX)/Math.PI*180; | |
if (relX > radius || relY > radius) | |
robot.turn(relAngle - robot.angle + 90); | |
else if (relX < radius * 1.1 || relY < radius * 1.1) | |
robot.turn(relAngle - robot.angle + 180); | |
robot.ahead(20); | |
robot.rotateCannon(-robot.cannonRelativeAngle); | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
robot.fire(); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment