Skip to content

Instantly share code, notes, and snippets.

@webfacer
Created December 8, 2012 14:29
Show Gist options
  • Save webfacer/4240457 to your computer and use it in GitHub Desktop.
Save webfacer/4240457 to your computer and use it in GitHub Desktop.
jinfu
// cloned robot from other gamer for understanding
var Robot = function(robot)
{
myID = robot.id;
direction = 1;
directionClone = -1;
robot.clone();
};
Robot.prototype.onIdle = function(ev)
{
var robot = ev.robot;
if(robot.parentId == null)
{
if(direction == 1){robot.ahead(20);}
if(direction == -1){robot.back(20);}
robot.rotateCannon(10);
robot.fire(1);
}
else
{
if(directionClone == 1){robot.ahead(20);}
if(directionClone == -1){robot.back(20);}
robot.rotateCannon(-10);
robot.fire(1);
}
};
Robot.prototype.onScannedRobot = function(ev)
{
var robot = ev.robot;
var target = ev.scannedRobot;
robot.gunCoolDownTime = 0;
if(robot.parentId == null)
{
if (target.id != myID && target.parentId != myID)
{
robot.fire(1);
robot.rotateCannon(-20)
}
}
else
{
if (target.id != myID && target.parentId != myID)
{
robot.fire(1);
robot.rotateCannon(20);
}
}
};
// ohhh... we were hit by another robot...
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.fire(1);
if(robot.parentId == null)
{
robot.turn(33.33);
//robot.rotateCannon(-33.33);
if(direction == 1){robot.ahead(20);}
if(direction == -1){robot.back(20);}
}
else
{
robot.turn(33.33);
//robot.rotateCannon(-33.33);
if(directionClone == 1){robot.ahead(20);}
if(directionClone == -1){robot.back(20);}
}
};
Robot.prototype.onRobotCollision = function(ev)
{
var robot = ev.robot;
if(robot.parentId == null)
{
direction *= -1;
if(direction == 1){robot.ahead(20);}
if(direction == -1){robot.back(20);}
robot.turn(30);
//robot.rotateCannon(-30);
}
else
{
directionClone *= -1;
if(directionClone == 1){robot.ahead(20);}
if(directionClone == -1){robot.back(20);}
robot.turn(35);
//robot.rotateCannon(-35);
}
};
Robot.prototype.onWallCollision = function(ev)
{
var robot = ev.robot;
robot.stop();
//robot.ignore(Robot.prototype.onHitByBullet);
if(robot.parentId == null)
{
direction *= -1;
if(direction == 1){robot.ahead(20);}
if(direction == -1){robot.back(20);}
robot.turn(29);
//robot.rotateCannon(-29);
}
else
{
directionClone *= -1;
if(directionClone == 1){robot.ahead(20);}
if(directionClone == -1){robot.back(20);}
robot.turn(34);
//robot.rotateCannon(-34);
}
//robot.listen(Robot.prototype.onHitByBullet);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment