Skip to content

Instantly share code, notes, and snippets.

@lenybernard
Created December 8, 2012 15:40
Show Gist options
  • Select an option

  • Save lenybernard/4240778 to your computer and use it in GitHub Desktop.

Select an option

Save lenybernard/4240778 to your computer and use it in GitHub Desktop.
Silent killbot
var Robot = function(robot) {
robot.turnLeft(robot.angle % 90);
robot.turnGunRight(90);
robot.clone();
this.direcao = 1;
this.encontrado = false;
this.numPerda = 0;
this.numIdle1 = 0;
this.numIdle2 = 0;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
if(this.encontrado) {
robot.turnGunRight(5 * this.direcao);
andar(robot,5);
robot.turn(1*this.direcao*-1);
if(this.numPerda>5) {
this.encontrado=false;
this.direcao *= -1;
}
this.numPerda=this.numPerda+1;
this.numIdle1++;
if(this.numIdle1>500&&(this.numIdle1%10)>0) {
robot.fire();
}
} else {
andar(robot,5);
robot.rotateCannon(2*this.direcao);
robot.turn(2*this.direcao);
}
} else {
andar(robot,1);
this.numIdle2++;
if(this.numIdle2>500&&(this.numIdle2%10)==0) {
robot.fire();
}
}
};
function andar(robot,i) {
if(this.direcao>0) {
robot.ahead(i);
} else {
robot.back(i);
}
}
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot, collidedRobot = ev.collidedRobot;
robot.ignore('onRobotCollision')
if (ev.bearing > -90 && ev.bearing < 90) {
robot.back(100);
} else {
robot.ahead(100);
}
robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle *-1);
robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle *-1);
robot.listen('onRobotCollision')
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
if (robot.parentId) {
robot.back(30);
} else {
robot.turnLeft((ev.bearing -90));
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
if(robot.parentId!=null){
robot.turn(ev.bearing);
robot.fire();
robot.fire();
robot.fire();
robot.fire();
robot.fire();
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot;
var scannedRobot;
robot = ev.robot;
scannedRobot = ev.scannedRobot;
if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
this.numIdle1 = 0;
this.numIdle2 = 0;
return;
}
if (robot.parentId) {
this.encontrado=true;
if(!this.encontrado) {
robot.rotateCannon(80*this.direcao);
}
for (var i=0; i<5; i++) {
robot.fire();
robot.fire();
robot.fire();
andar(robot,9);
}
this.direcao *= -1;
this.numIdle1=0;
this.numPerda=0;
}else {
robot.fire();
robot.fire();
robot.fire();
this.numIdle2=0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment