Created
December 5, 2012 18:47
-
-
Save gabrielgarciagava/4218361 to your computer and use it in GitHub Desktop.
NOOOOOOBO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(3); | |
robot.rotateCannon(5); | |
count += 1; | |
if(count == 70){ | |
count = 0; | |
girar = 1; | |
} | |
} | |
}else{ | |
robot.ahead(5); | |
robot.fire(); | |
if(cw){ | |
robot.rotateCannon(-5); | |
if(robot.cannonRelativeAngle > 260 && robot.cannonRelativeAngle < 275) | |
cw = 0; | |
}else{ | |
robot.rotateCannon(5); | |
if(robot.cannonRelativeAngle < 100 && robot.cannonRelativeAngle > 85) | |
cw = 1; | |
} | |
} | |
}; | |
Robot.prototype.onScannedRobot = function(ev) { | |
var robot = ev.robot; | |
if(!(ev.scannedRobot.parentId == robot.id) && !(ev.scannedRobot.id == robot.parentId)){ | |
robot.fire(); | |
if(cw) | |
robot.rotateCannon(10); | |
else | |
robot.rotateCannon(-10); | |
} | |
}; | |
Robot.prototype.onWallCollision = function(ev) { | |
var robot = ev.robot; | |
if(robot.parentId != null) | |
robot.back(30); | |
else | |
robot.turn(ev.bearing-90); | |
}; | |
Robot.prototype.onHitByBullet = function(ev) { | |
var robot = ev.robot; | |
if(robot.parentId == null){ | |
if(ev.bearing == robot.angle-180) | |
robot.turn(-60); | |
}else | |
robot.turn(35); | |
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(-45); // trying to run away | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment