Skip to content

Instantly share code, notes, and snippets.

@gabrielgarciagava
Created December 5, 2012 17:55
Show Gist options
  • Save gabrielgarciagava/4217902 to your computer and use it in GitHub Desktop.
Save gabrielgarciagava/4217902 to your computer and use it in GitHub Desktop.
ROBOBOCA
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
robot.clone();
};
var girar = 1;
var count = 0;
var cw = 1;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if(robot.parentId != null){
if(girar == 1){
robot.rotateCannon(90);
robot.turn(120);
girar = 0;
}else{
robot.ahead(5);
robot.turn(2);
robot.rotateCannon(5);
count += 1;
if(count == 70){
count = 0;
girar = 1;
}
}
}else{
robot.ahead(5);
if(cw){
robot.rotateCannon(5);
if(robot.cannonRelativeAngle > 180)
cw = 1;
}else{
robot.rotateCannon(-5);
if(robot.cannonRelativeAngle == 0)
cw = 0;
}
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
if(!(ev.scannedRobot.parentId == robot.id) && !(ev.scannedRobot.id == robot.parentId)){
robot.fire();
robot.gunCoolDownTime = 0;
robot.rotateCannon(-25);
}
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
if(robot.parentId != null)
robot.back(30);
else
robot.turn(3);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(15);
robot.ahead(90);
robot.rotateCannon(ev.bearing); // Turn to wherever the bullet was fired
// so we can see who shot it
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(-15); // trying to run away
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment