Skip to content

Instantly share code, notes, and snippets.

@kdungs
Created December 19, 2012 13:41
Show Gist options
  • Save kdungs/4336724 to your computer and use it in GitHub Desktop.
Save kdungs/4336724 to your computer and use it in GitHub Desktop.
Gauß 2.0
var Robot = function(robot) {
};
var found = false;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (!found) {
robot.rotateCannon(1);
robot.ahead(1);
robot.turn(1);
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
if (robot.life > ev.collideRobot.life) {
robot.rotateCannon(ev.bearing); // Attack!
} else {
robot.ahead(20); // Run!
}
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
found = true;
robot.fire().notify(function() {
found = false;
});
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing + 20);
robot.ahead(20);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment