Skip to content

Instantly share code, notes, and snippets.

@lekoder
Created December 4, 2012 15:57
Show Gist options
  • Save lekoder/4205450 to your computer and use it in GitHub Desktop.
Save lekoder/4205450 to your computer and use it in GitHub Desktop.
aimer
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var opts = {
aim:0,
fwd:true
}
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
if (opts.aim>0)
{
robot.rotateCannon(10);
robot.rotateCannon(-10);
opts.aim--;
}
else
{
robot.rotateCannon(-3);
}
if ( opts.fwd )
{
robot.ahead(10);
}
else
{
robot.back(10);
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
robot.stop();
robot.fire();
opts.aim=5;
var ta = ev.robot.cannonRelativeAngle;
if ( ta>180 ) ta -=360;
if ( ta>20 ) ta=20;
if ( ta<-20 ) ta=-20;
robot.turn(ta);
robot.rotateCannon(-ta);
};
Robot.prototype.onWallCollision = function(ev) {
opts.fwd = !opts.fwd;
}
Robot.prototype.onRobotCollision = function(ev) {
opts.fwd = !opts.fwd;
var ta = ev.bearing - ev.robot.cannonRelativeAngle;
robot.rotateCannon(ta);
}
Robot.prototype.onHitByBullet = function(ev) {
opts.fwd = !opts.fwd;
var ta = ev.bearing - ev.robot.cannonRelativeAngle;
robot.rotateCannon(ta);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment