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.

Revisions

  1. lekoder revised this gist Dec 5, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -38,9 +38,12 @@ Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();
    robot.fire();
    opts.aim=20;
    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);
    };
  2. lekoder revised this gist Dec 4, 2012. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -49,3 +49,16 @@ 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);
    }
  3. lekoder revised this gist Dec 4, 2012. 1 changed file with 13 additions and 4 deletions.
    17 changes: 13 additions & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -22,12 +22,16 @@ Robot.prototype.onIdle = function(ev) {
    else
    {
    robot.rotateCannon(-3);
    if ( opts.fwd ) {

    }
    if ( opts.fwd )
    {
    robot.ahead(10);
    } else {
    }
    else
    {
    robot.back(10);
    }

    }
    };

    Robot.prototype.onScannedRobot = function(ev) {
    @@ -38,5 +42,10 @@ Robot.prototype.onScannedRobot = function(ev) {
    var ta = ev.robot.cannonRelativeAngle;
    if ( ta>180 ) ta -=360;
    robot.turn(ta);
    robot.rotateCannon(-ta);
    };

    Robot.prototype.onWallCollision = function(ev) {
    opts.fwd = !opts.fwd;
    }

  4. lekoder revised this gist Dec 4, 2012. 1 changed file with 23 additions and 3 deletions.
    26 changes: 23 additions & 3 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,16 +5,36 @@ var Robot = function(robot) {

    };

    var opts = {
    aim:0,
    fwd:true
    }

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.rotateCannon(36);
    robot.ahead(10);

    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=20;
    var ta = ev.robot.cannonRelativeAngle;
    if ( ta>180 ) ta -=360;
    robot.turn(ta);
  5. lekoder created this gist Dec 4, 2012.
    22 changes: 22 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@

    //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;
    robot.rotateCannon(36);
    robot.ahead(10);
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();

    var ta = ev.robot.cannonRelativeAngle;
    if ( ta>180 ) ta -=360;
    robot.turn(ta);
    };