Skip to content

Instantly share code, notes, and snippets.

@stol
Created December 4, 2012 12:38
Show Gist options
  • Save stol/4203393 to your computer and use it in GitHub Desktop.
Save stol/4203393 to your computer and use it in GitHub Desktop.
RobotRock1
var found = 0;
//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;
if (!found)
robot.rotateCannon(1);
};
Robot.prototype.onScannedRobot = function(ev) {
found = 1;
var robot = ev.robot ;
robot.fire();
setTimeout(function(){
found = 0;
}, 1);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
if (robot.angle < 180){
if (robot.position.x < arenaWidth)
robot.ahead(100);
else
robot.behind(100);
}
else {
if (robot.position.x > 0)
robot.ahead(100);
else
robot.behind(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment