Skip to content

Instantly share code, notes, and snippets.

@andrewsmedina
Created December 5, 2012 23:36
Show Gist options
  • Save andrewsmedina/4220530 to your computer and use it in GitHub Desktop.
Save andrewsmedina/4220530 to your computer and use it in GitHub Desktop.
Overrun
//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;
robot.clone();
robot.ahead(100);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned = ev.scannedRobot;
if (robot.id == scanned.parentId || robot.parentId == scanned.id) {
return;
}
for (var i=0; i<10; i++) {
robot.fire();
robot.rotateCannon(5);
robot.fire();
robot.rotateCannon(-5);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing - 90);
robot.rotateCannon(-robot.cannonRelativeAngle);
robot.ahead(100);
robot.rotateCannon(30);
robot.ahead(100);
robot.rotateCannon(-30);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var collided = ev.collidedRobot;
if (collided.id !== robot.parentId && collided.parentId !== robot.id) {
robot.rotateCannon((90 - robot.cannonRelativeAngle) + collided.cannonAngle);
} else {
if (ev.myFault) {
robot.back(20);
robot.turn(180);
robot.rotateCannon(180);
robot.ahead(1000);
}
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ahead(1000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment