Skip to content

Instantly share code, notes, and snippets.

@samelinux
Created December 7, 2012 11:26
Show Gist options
  • Select an option

  • Save samelinux/4232667 to your computer and use it in GitHub Desktop.

Select an option

Save samelinux/4232667 to your computer and use it in GitHub Desktop.

Revisions

  1. samelinux revised this gist Dec 7, 2012. 1 changed file with 0 additions and 53 deletions.
    53 changes: 0 additions & 53 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,53 +0,0 @@
    var eading;
    var firesign;
    var lasthealth;
    var fired;

    var Robot = function(robot) {
    eading=1;
    firesign=1;
    lasthealth=100;
    fired=false;
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    if(eading==1)
    {
    ev.robot.ahead(30);
    }
    else
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==300 || ev.robot.cannonRelativeAngle==60)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    // if(!fired)
    ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onScannedRobot = function(ev) {
    // ev.robot.fire();
    // ev.robot.rotateCannon(-20*firesign);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(ev.bearing - 90);
    };
  2. samelinux created this gist Dec 7, 2012.
    53 changes: 53 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    var eading;
    var firesign;
    var lasthealth;
    var fired;

    var Robot = function(robot) {
    eading=1;
    firesign=1;
    lasthealth=100;
    fired=false;
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    if(eading==1)
    {
    ev.robot.ahead(30);
    }
    else
    {
    ev.robot.back(30);
    }
    if(ev.robot.cannonRelativeAngle==300 || ev.robot.cannonRelativeAngle==60)
    {
    if(firesign==1)
    {
    firesign=-1;
    }
    else
    {
    firesign=1;
    }
    }
    // if(!fired)
    ev.robot.rotateCannon(10*firesign);
    };

    Robot.prototype.onHitByBullet = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onScannedRobot = function(ev) {
    // ev.robot.fire();
    // ev.robot.rotateCannon(-20*firesign);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    eading=1-eading;
    };

    Robot.prototype.onWallCollision = function(ev) {
    ev.robot.turn(ev.bearing - 90);
    };