Skip to content

Instantly share code, notes, and snippets.

@orian
Created December 4, 2012 01:08
Show Gist options
  • Save orian/4199596 to your computer and use it in GitHub Desktop.
Save orian/4199596 to your computer and use it in GitHub Desktop.
ZawiszaCzarny
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.lastHitAngle = 0;
this.radius = 20;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (this.lastHitAngle - robot.cannonAbsoluteAngle > 10) {
robot.rotateCannon(this.lastHitAngle - robot.cannonAbsoluteAngle);
}
robot.ahead(100);
robot.rotateCannon(this.radius);
this.radius = -2*this.radius;
robot.back(100);
robot.rotateCannon(this.radius);
this.radius = -2*this.radius;
console.log(this.radius);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.fire();
this.lastHitAngle = robot.cannonAbsoluteAngle;
this.radius = 20;
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bulletBearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment