Skip to content

Instantly share code, notes, and snippets.

@zachiPL
Created December 6, 2012 10:47
Show Gist options
  • Save zachiPL/4223603 to your computer and use it in GitHub Desktop.
Save zachiPL/4223603 to your computer and use it in GitHub Desktop.
WallScanner
var Robot = function(robot) {
robot.ignore('onScannedRobot');
robot.rotateCannon(-90);
robot.listen('onScannedRobot');
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(30);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ignore('onHitByBullet');
robot.turn(-45);
robot.ahead(100);
robot.listen('onHitByBullet');
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.stop();
robot.ignore('onWallCollision');
robot.fire(3);
robot.ahead(50);
robot.turn(-30);
robot.listen('onWallCollision');
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.stop();
robot.back(10);
robot.listen('onScannedRobot');
robot.ignore('onWallCollision');
robot.turn(90);
robot.listen('onWallCollision');
robot.listen('onScannedRobot');
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing - 90);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment