Skip to content

Instantly share code, notes, and snippets.

@fabiotnt
Forked from Ghabriel/robot.js
Created December 5, 2012 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiotnt/4217479 to your computer and use it in GitHub Desktop.
Save fabiotnt/4217479 to your computer and use it in GitHub Desktop.
Robot04
//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.rotateCannon(360);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.stop();
robot.fire();
for (var i = 0; i < 3; i++){
robot.turn(20);
robot.ahead(18);
robot.turn(-20);
robot.fire();
}
};
Robot.prototype.onWallCollision = function(ev){
var robot = ev.robot;
robot.turn(ev.bearing + 95);
robot.ahead(180);
robot.turn(85 - ev.bearing);
};
Robot.prototype.onHitByBullet = function(ev){
var robot = ev.robot;
robot.stop();
robot.ahead(300);
robot.turn(ev.bearing + 50);
robot.ahead(180);
robot.turn(-50);
robot.fire();
robot.fire();
robot.turn(-15);
robot.fire();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment