Skip to content

Instantly share code, notes, and snippets.

@ruzz311
Created August 22, 2013 15:01
Show Gist options
  • Save ruzz311/6308357 to your computer and use it in GitHub Desktop.
Save ruzz311/6308357 to your computer and use it in GitHub Desktop.
fightcode.turretbot.js
/**
objectives = ['seek', 'attack', 'evade', 'shit']
**/
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
this.rotate = 180;
this.direction = 1;
this.found = false;
this.directionAmount = 100;
this.objective = 'seek';
this.ticksSinceHit = 0;
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
switch(this.objective){
case 'seek':
if (!this.found) {
robot.turn(360);
}
if (this.ticksSinceHit > 50) {
this.found = false;
}
break;
case 'attack':
case 'evade':
case 'shit':
default: break;
}
this.ticksSinceHit++;
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
//over = ev.bearing > 0 ? 20 : -20
robot.stop();
robot.log(direction, ev.bearing, robot.angle);
robot.turn(ev.bearing); // Turn to wherever the bullet was fired
// so we can see who shot it
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot,
bogey = ev.scannedRobot;
robot.log(bogey)
this.found = true;
this.ticksSinceHit = 0;
robot.stop();
robot.turn( bogey.angle );
robot.stop();
robot.fire();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment