Skip to content

Instantly share code, notes, and snippets.

@rafaelcaricio
Forked from victorlcampos/robot.js
Created December 3, 2012 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafaelcaricio/4195532 to your computer and use it in GitHub Desktop.
Save rafaelcaricio/4195532 to your computer and use it in GitHub Desktop.
Bartorista
function Robot(robot) {}
// well, we need to do something...
// whenever our robot is idle, this method gets called.
Robot.prototype.onIdle = function(ev) {
var robot;
robot = ev.robot;
robot.ahead(50);
robot.turn(90);
robot.rotateCannon(10);
robot.rotateCannon(-20);
robot.rotateCannon(10);
};
// this method gets called whenever we hit another robot...
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
var collidedRobot = ev.collidedRobot;
if((robot.parentId == null && collidedRobot.parentId != robot.id)){
robot.fire();
}else if((robot.parentId != null && collidedRobot.id != robot.parentId)){
robot.fire();
}
};
// this method gets called whenever we hit a wall...
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turnRight(ev.bearing + 90);
};
// yay we see another robot! time to wreak some havoc...
Robot.prototype.onScannedRobot = function(ev) {
var robot;
var scannedRobot;
robot = ev.robot;
scannedRobot = ev.scannedRobot;
if((robot.parentId == null && scannedRobot.parentId != robot.id)){
for (var i=0; i<5; i++) {
robot.fire();
robot.ahead(10);
}
robot.clone();
}else if((robot.parentId != null && scannedRobot.id != robot.parentId)){
for (var i=0; i<5; i++) {
robot.fire();
robot.ahead(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(150);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment