Skip to content

Instantly share code, notes, and snippets.

@H1D
Forked from Shipow/robot.js
Created December 5, 2012 11:51
Show Gist options
  • Select an option

  • Save H1D/4214967 to your computer and use it in GitHub Desktop.

Select an option

Save H1D/4214967 to your computer and use it in GitHub Desktop.

Revisions

  1. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 2 additions and 17 deletions.
    19 changes: 2 additions & 17 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,12 @@
    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {
    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    //robot.clone();
    robot.ahead();
    //robot.rotateCannon(Math.floor((Math.random()-0.5))*360);
    //robot.back(10);


    //i'll add a clone but i need to refactor collision
    //robot.clone();
    };

    Robot.prototype.onScannedRobot = function(ev) {
    @@ -22,27 +17,17 @@ Robot.prototype.onScannedRobot = function(ev) {
    robot.rotateCannon(-15);
    robot.rotateCannon(15);
    }else{
    //robot.ahead(-40);
    }


    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    //robot = ev.robot;
    //robot.turn(90 - ev.bulletBearing);
    //robot.ahead(-50);
    //robot.turn(60 - ev.bulletBearing);
    //robot.back(90);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.rotateCannon(90);
    //robot.ahead(robot.position+5);
    //robot.ahead(robot.position-15);
    //robot.turn(180 - ev.Bearing);
    // trying to run away
    };

    Robot.prototype.onWallCollision = function(ev) {
  2. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@ Robot.prototype.onHitByBullet = function(ev) {

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.rotateCannon(90);
    //robot.ahead(robot.position+5);
    //robot.ahead(robot.position-15);
    //robot.turn(180 - ev.Bearing);
  3. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ Robot.prototype.onScannedRobot = function(ev) {
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    robot.fire();
    //robot.rotateCannon(30);
    //robot.rotateCannon(-30);
    robot.rotateCannon(-15);
    robot.rotateCannon(15);
    }else{
    //robot.ahead(-40);
    }
  4. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 21 additions and 16 deletions.
    37 changes: 21 additions & 16 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {

    robot.rotateCannon(-90);
    };

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(100);
    robot.rotateCannon(Math.floor((Math.random()-0.5))*360);
    robot.back(10);
    robot.rotateCannon(360);
    //robot.clone();
    robot.ahead();
    //robot.rotateCannon(Math.floor((Math.random()-0.5))*360);
    //robot.back(10);


    };

    @@ -19,27 +19,32 @@ Robot.prototype.onScannedRobot = function(ev) {
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    robot.fire();
    robot.rotateCannon(30);
    robot.rotateCannon(-30);
    //robot.rotateCannon(30);
    //robot.rotateCannon(-30);
    }else{
    robot.ahead(-40);
    //robot.ahead(-40);
    }


    };
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(60 - ev.bulletBearing);
    //robot = ev.robot;
    //robot.turn(90 - ev.bulletBearing);
    //robot.ahead(-50);
    //robot.turn(60 - ev.bulletBearing);
    //robot.back(90);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.ahead(robot.position+5);
    robot.ahead(robot.position-15);

    //robot.ahead(robot.position+5);
    //robot.ahead(robot.position-15);
    //robot.turn(180 - ev.Bearing);
    // trying to run away
    };

    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turn(-90+ev.bearing);
    };
  5. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ Robot.prototype.onHitByBullet = function(ev) {
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(60 - ev.bulletBearing);
    robot.back(90);
    //robot.back(90);
    };

    Robot.prototype.onRobotCollision = function(ev) {
  6. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@ Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(100);
    robot.rotateCannon(360);
    robot.back(100);
    robot.rotateCannon(Math.floor((Math.random()-0.5))*360);
    robot.back(10);
    robot.rotateCannon(360);

    };
  7. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -19,10 +19,10 @@ Robot.prototype.onScannedRobot = function(ev) {
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    robot.fire();
    robot.rotateCannon(-3);
    robot.rotateCannon(30);
    robot.rotateCannon(-30);
    }else{
    robot.ahead(30);
    robot.ahead(-40);
    }


  8. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 27 additions and 5 deletions.
    32 changes: 27 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    //FightCode can only understand your robot
    //if its class is called Robot
    var Robot = function(robot) {
    @@ -7,6 +6,7 @@ var Robot = function(robot) {

    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.clone();
    robot.ahead(100);
    robot.rotateCannon(360);
    robot.back(100);
    @@ -15,9 +15,31 @@ Robot.prototype.onIdle = function(ev) {
    };

    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    robot.stop();
    var robot = ev.robot;
    var scanned =ev.scannedRobot;
    if(scanned.id !== robot.parentId && scanned.parentId !== robot.id) {
    robot.fire();

    robot.rotateCannon(-3);
    robot.rotateCannon(-30);
    }else{
    robot.ahead(30);
    }


    };

    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(-50);
    robot.turn(60 - ev.bulletBearing);
    robot.back(90);
    };

    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    robot.ahead(robot.position+5);
    robot.ahead(robot.position-15);

    // trying to run away
    };
  9. @Shipow Shipow revised this gist Dec 5, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ Robot.prototype.onIdle = function(ev) {

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

    };
  10. @Shipow Shipow created this gist Dec 5, 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.ahead(100);
    robot.rotateCannon(360);
    robot.back(100);
    robot.rotateCannon(360);

    };

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

    };