Skip to content

Instantly share code, notes, and snippets.

@sivartydrup
Last active December 11, 2015 05:38
Show Gist options
  • Save sivartydrup/4553404 to your computer and use it in GitHub Desktop.
Save sivartydrup/4553404 to your computer and use it in GitHub Desktop.
Next iteration
var Robot = function(robot) {
robot.rotateCannon(90);
};
Robot.prototype.onIdle = function(ev) {
ev.robot.clone();
if (ev.robot.parentId !== null) {
ev.robot.turn(90);
ev.robot.rotateCannon(3);
ev.robot.rotateCannon(30);
}
ev.robot.ahead(1000);
};
Robot.prototype.onScannedRobot = function(ev) {
if(ev.scannedRobot.id !== ev.robot.parentId && ev.scannedRobot.parentId !== ev.robot.id) {
ev.robot.fire(1);
if (ev.robot.parentId !== null) {
ev.robot.rotateCannon(-10);
ev.robot.rotateCannon(-10);
}
}
};
Robot.prototype.onWallCollision = function(ev) {
if (ev.robot.parentId == null) {
ev.robot.turn(ev.bearing + 90);
}
else {
ev.robot.back(100);
ev.robot.rotateCannon(-180);
ev.robot.turn(ev.bearing + 150);
}
};
Robot.prototype.onRobotCollision = function(ev) {
ev.robot.back(100);
ev.robot.turn(90);
};
Robot.prototype.onHitByBullet = function(ev) {
if (ev.robot.parentId !== null) {
ev.robot.turn(90 - ev.bulletBearing);
}
else
{
ev.robot.turn(90 - (ev.bulletBearing*2));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment