Skip to content

Instantly share code, notes, and snippets.

@pedrotoliveira
Created December 7, 2012 13:10
Show Gist options
  • Save pedrotoliveira/4233188 to your computer and use it in GitHub Desktop.
Save pedrotoliveira/4233188 to your computer and use it in GitHub Desktop.
D2
//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.ahead(60);
robot.turn(45);
robot.ahead(30);
robot.turn(45);
robot.ahead(30);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var collidedRobot = ev.collidedRobot;
if (collidedRobot.parentId == null
&& robot.parentId != collidedRobot.id) {
if (robot.availableClones > 0) {
robot.clone();
}
robot.fire(); // YAY!
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(90);
robot.ahead(100);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scannedRobot = ev.scannedRobot;
if (robot.availableClones > 0) {
robot.clone();
}
if (scannedRobot.parentId == null
&& scannedRobot.id != robot.parentId) {
robot.stop()
robot.fire(); // YAY!
robot.fire(); // YAY!
robot.fire(); // YAY!
robot.onIdle();
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.rotateCannon(ev.bearing);
robot.turn(45);
robot.ahead(50);
robot.turn(45);
robot.rotateCannon(ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment