Skip to content

Instantly share code, notes, and snippets.

@lekoder
Created December 4, 2012 14:42
Show Gist options
  • Save lekoder/4204636 to your computer and use it in GitHub Desktop.
Save lekoder/4204636 to your computer and use it in GitHub Desktop.
Snipe
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.sa=360;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.rotateCannon(this.sa);
robot.rotateCannon(-this.sa);
this.sa*=1.5;
if ( this.sa>180 )this.sa=180;
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.stop();
robot.fire();
this.sa=1;
robot.log(this.sa);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.ahead(50);
var a = Math.random()*90-45;
robot.turn(a);
robot.rotateCannon(ev.bearing-a); // Turn to wherever the bullet was fired
// so we can see who shot it
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment