Skip to content

Instantly share code, notes, and snippets.

@vitorbcs
Created December 8, 2012 02:24
Show Gist options
  • Select an option

  • Save vitorbcs/4238248 to your computer and use it in GitHub Desktop.

Select an option

Save vitorbcs/4238248 to your computer and use it in GitHub Desktop.
Epidemic Destructor
function Robot(robot) {}
var achei = 0;
// well, we need to do something...
// whenever our robot is idle, this method gets called.
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(10);
if(achei==0)
robot.rotateCannon(3);
else{
robot.turn(20);
robot.ahead(20);
robot.turn(-40);
achei = 0;
}
if(achei==0)
robot.turn(2);
if(achei==1){
robot.ahead(5);
robot.back(5);
}
achei=0;
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(20);
robot.ahead(100); //runing away
};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(45-ev.bearing);
robot.ahead(100);
};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot;
robot = ev.robot;
robot.fire();
achei = 1;
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bearing);
robot.ahead(100);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment