Skip to content

Instantly share code, notes, and snippets.

@tarsisazevedo
Created December 3, 2012 13:11
Show Gist options
  • Select an option

  • Save tarsisazevedo/4194972 to your computer and use it in GitHub Desktop.

Select an option

Save tarsisazevedo/4194972 to your computer and use it in GitHub Desktop.

Revisions

  1. tarsisazevedo revised this gist Dec 3, 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
    @@ -40,6 +40,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    Robot.prototype.onHitByBullet = function(ev) {
    var robot = ev.robot;
    robot.turnGunRight(ev.bearing);
    robot.ahead(100);
    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
  2. tarsisazevedo revised this gist Dec 3, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,6 @@ Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId) {
    robot.turnRight(ev.bearing - 90);
    robot.turnGunLeft(180);
    robot.turnGunRight(180);
    } else
    robot.turnRight(ev.bearing + 90);
    };
  3. tarsisazevedo revised this gist Dec 3, 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
    @@ -17,11 +17,11 @@ Robot.prototype.onIdle = function(ev) {
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    if(!robot.parentId) {
    robot.turnRight(ev.bearing - 90);
    robot.turnGunLeft(180);
    robot.turnGunRight(180);
    else
    } else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
  4. tarsisazevedo revised this gist Dec 3, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -12,17 +12,17 @@ Robot.prototype.onIdle = function(ev) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    }
    else {
    robot.turnGunRight(360);
    }
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    robot.turnGunLeft(180);
    robot.turnGunRight(180);
    else
    hsuarobot.turnRight(ev.bearing + 90);
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
  5. tarsisazevedo revised this gist Dec 3, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -12,17 +12,17 @@ Robot.prototype.onIdle = function(ev) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    robot.turnGunRight(180);
    robot.turnGunRight(-180);
    }

    else {
    robot.turnGunRight(360);
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    hsuarobot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
  6. tarsisazevedo revised this gist Dec 3, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,8 @@ Robot.prototype.onRobotCollision = function(ev) {
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    var robot = ev.robot;
    robot.turnGunRight(ev.bearing);
    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
  7. tarsisazevedo revised this gist Dec 3, 2012. No changes.
  8. tarsisazevedo revised this gist Dec 3, 2012. No changes.
  9. tarsisazevedo revised this gist Dec 3, 2012. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@ Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    robot.turnGunRight(180);
    robot.turnGunRight(-180);
    }

    };
    @@ -48,5 +48,4 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    //robot.log('firing');
    };
  10. Zolmeister revised this gist Dec 2, 2012. No changes.
  11. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 47 additions and 31 deletions.
    78 changes: 47 additions & 31 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,52 @@
    var Robot = function(robot) {
    this.dir=1;
    this.once=false
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.rotateCannon(-1*this.dir);
    else{
    robot.rotateCannon(-1);
    }
    if(robot.parentId && !this.once){
    this.once=true;
    robot.back(100);
    }
    robot.clone();
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    var srobo = ev.scannedRobot;
    var id1 = robot.parentId || robot.id;
    var id2 = srobo.parentId || srobo.id;
    if(id1!=id2){

    if(!robot.parentId){
    robot.stop();
    robot.fire();
    robot.rotateCannon(-30*this.dir);
    this.dir*=-1;
    }
    else{
    robot.rotateCannon(15);
    robot.fire(5);
    }
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    }
    robot.fire();
    //robot.log('firing');
    };
  12. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 31 additions and 47 deletions.
    78 changes: 31 additions & 47 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,52 +1,36 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    var Robot = function(robot) {
    this.dir=1;
    this.once=false
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    var robot = ev.robot;
    if(!robot.parentId)
    robot.rotateCannon(-1*this.dir);
    else{
    robot.rotateCannon(-1);
    }
    if(robot.parentId && !this.once){
    this.once=true;
    robot.back(100);
    }
    robot.clone();
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

    };
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot, scannedRobot = ev.scannedRobot;
    if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) {
    return;
    Robot.prototype.onScannedRobot = function(ev) {
    var robot = ev.robot;
    var srobo = ev.scannedRobot;
    var id1 = robot.parentId || robot.id;
    var id2 = srobo.parentId || srobo.id;
    if(id1!=id2){

    if(!robot.parentId){
    robot.stop();
    robot.fire();
    robot.rotateCannon(-30*this.dir);
    this.dir*=-1;
    }
    else{
    robot.rotateCannon(15);
    robot.fire(5);
    }
    }
    robot.fire();
    //robot.log('firing');
    };
  13. Zolmeister revised this gist Dec 2, 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
    @@ -28,7 +28,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    //robot.back(100);
    robot.back(100);
    } else {
    robot.ahead(100);
    }
  14. Zolmeister revised this gist Dec 2, 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
    @@ -19,13 +19,16 @@ Robot.prototype.onIdle = function(ev) {
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    if(!robot.parentId)
    robot.turnRight(ev.bearing - 90);
    else
    robot.turnRight(ev.bearing + 90);
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    //robot.back(100);
    } else {
    robot.ahead(100);
    }
  15. Zolmeister revised this gist Dec 2, 2012. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    robot.turnGunRight(90);
    //robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    //if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    // this.direction *= -1;
    //}
    //robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }
    @@ -20,7 +20,6 @@ Robot.prototype.onIdle = function(ev) {
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turnRight(ev.bearing + 90);

    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;
  16. @cezarsa cezarsa revised this gist Dec 2, 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
    @@ -46,5 +46,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    robot.log('firing');
    //robot.log('firing');
    };
  17. @cezarsa cezarsa revised this gist Dec 2, 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
    @@ -46,4 +46,5 @@ Robot.prototype.onScannedRobot = function(ev) {
    return;
    }
    robot.fire();
    robot.log('firing');
    };
  18. @cezarsa cezarsa revised this gist Nov 30, 2012. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,20 @@ var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    robot.turnGunRight(90);
    robot.clone();
    this.direction = 1;
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    if (robot.parentId) {
    robot.turnGunRight(1)
    if (robot.cannonRelativeAngle > 270 || robot.cannonRelativeAngle < 90) {
    this.direction *= -1;
    }
    robot.turnGunRight(this.direction);
    //robot.turnGunRight(180);
    //robot.turnGunRight(-180);
    }

    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
  19. @cezarsa cezarsa revised this gist Nov 30, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,10 @@ var Robot = function(robot){
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;
    robot.ahead(1);
    robot.ahead(1);
    if (robot.parentId) {
    robot.turnGunRight(1)
    }
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    @@ -14,7 +17,6 @@ Robot.prototype.onWallCollision = function(ev) {
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot, collidedRobot = ev.collidedRobot;

    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
  20. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  21. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  22. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  23. @cezarsa cezarsa revised this gist Nov 29, 2012. No changes.
  24. @cezarsa cezarsa revised this gist Nov 29, 2012. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -13,18 +13,20 @@ Robot.prototype.onWallCollision = function(ev) {

    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;
    var robot = ev.robot, collidedRobot = ev.collidedRobot;

    robot.ignore('onRobotCollision');
    robot.ignore('onRobotCollision')
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }

    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    robot.listen('onRobotCollision');
    if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    }
    robot.listen('onRobotCollision')
    };
    Robot.prototype.onHitByBullet = function(ev) {

  25. @cezarsa cezarsa revised this gist Nov 29, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion robot.js
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ Robot.prototype.onWallCollision = function(ev) {
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;

    robot.stop();
    robot.ignore('onRobotCollision');
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    @@ -24,6 +24,7 @@ Robot.prototype.onRobotCollision = function(ev) {

    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    robot.listen('onRobotCollision');
    };
    Robot.prototype.onHitByBullet = function(ev) {

  26. @cezarsa cezarsa revised this gist Nov 29, 2012. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -14,13 +14,16 @@ Robot.prototype.onWallCollision = function(ev) {
    };
    Robot.prototype.onRobotCollision = function(ev) {
    var robot = ev.robot;

    robot.stop();
    if (ev.bearing > -90 && ev.bearing < 90) {
    robot.back(100);
    } else {
    robot.ahead(100);
    }
    robot.turnGunLeft(ev.bearing - 90);
    robot.turnGunRight(ev.bearing - 90);

    robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
    robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
    };
    Robot.prototype.onHitByBullet = function(ev) {

  27. @cezarsa cezarsa revised this gist Nov 28, 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
    @@ -9,7 +9,7 @@ Robot.prototype.onIdle = function(ev) {
    };
    Robot.prototype.onWallCollision = function(ev) {
    var robot = ev.robot;
    robot.turnRight(90);
    robot.turnRight(ev.bearing + 90);

    };
    Robot.prototype.onRobotCollision = function(ev) {
  28. @cezarsa cezarsa revised this gist Nov 28, 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
    @@ -20,6 +20,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    robot.ahead(100);
    }
    robot.turnGunLeft(ev.bearing - 90);
    robot.turnGunRight(ev.bearing - 90);
    };
    Robot.prototype.onHitByBullet = function(ev) {

  29. @cezarsa cezarsa revised this gist Nov 28, 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
    @@ -19,6 +19,7 @@ Robot.prototype.onRobotCollision = function(ev) {
    } else {
    robot.ahead(100);
    }
    robot.turnGunLeft(ev.bearing - 90);
    };
    Robot.prototype.onHitByBullet = function(ev) {

  30. @cezarsa cezarsa revised this gist Nov 28, 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
    @@ -1,7 +1,7 @@
    var Robot = function(robot){
    robot.turnLeft(robot.angle % 90);
    robot.turnGunRight(90);
    ev.robot.clone();
    robot.clone();
    };
    Robot.prototype.onIdle = function(ev) {
    var robot = ev.robot;