Skip to content

Instantly share code, notes, and snippets.

@patwork
Forked from fabiopimentel/robot.js
Created December 4, 2012 14:59
Show Gist options
  • Select an option

  • Save patwork/4204822 to your computer and use it in GitHub Desktop.

Select an option

Save patwork/4204822 to your computer and use it in GitHub Desktop.

Revisions

  1. patwork revised this gist Dec 4, 2012. No changes.
  2. @fabiopimentel fabiopimentel revised this gist Dec 4, 2012. No changes.
  3. @fabiopimentel fabiopimentel revised this gist Dec 4, 2012. No changes.
  4. @fabiopimentel fabiopimentel revised this gist Dec 4, 2012. 1 changed file with 3 additions and 12 deletions.
    15 changes: 3 additions & 12 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -16,27 +16,18 @@ Robot.prototype.onIdle = function(ev) {
    };

    Robot.prototype.onScannedRobot = function(ev) {
    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);
    }


    };

    // ohhh... we were hit by another robot...
    /*Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(10);
    robot.turn(80 - ev.bulletBearing);
    robot.back(10);
    };
    */
    // ohhh... we were hit by another robot...
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
  5. @fabiopimentel fabiopimentel revised this gist Dec 4, 2012. 1 changed file with 22 additions and 5 deletions.
    27 changes: 22 additions & 5 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,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,27 +16,43 @@ Robot.prototype.onIdle = function(ev) {
    };

    Robot.prototype.onScannedRobot = function(ev) {
    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);


    }


    };

    // ohhh... we were hit by another robot...
    Robot.prototype.onHitByBullet = function(ev) {
    /*Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(10);
    robot.turn(80 - ev.bulletBearing);
    robot.back(10);
    };
    */
    // ohhh... we were hit by another robot...
    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
    };



  6. @fabiopimentel fabiopimentel revised this gist Dec 3, 2012. No changes.
  7. @fabiopimentel fabiopimentel created this gist Dec 3, 2012.
    41 changes: 41 additions & 0 deletions robot.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@

    //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();
    robot.rotateCannon(-3);
    robot.rotateCannon(-30);




    };

    // ohhh... we were hit by another robot...
    Robot.prototype.onHitByBullet = function(ev) {
    var robot;
    robot = ev.robot;
    robot.turn(90 - ev.bulletBearing);
    robot.ahead(10);
    robot.turn(80 - ev.bulletBearing);
    robot.back(10);
    };