Skip to content

Instantly share code, notes, and snippets.

@olavph
Created December 5, 2012 18:44
Show Gist options
  • Save olavph/4218338 to your computer and use it in GitHub Desktop.
Save olavph/4218338 to your computer and use it in GitHub Desktop.
DUMMYBOT
//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