Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
Created December 5, 2012 22:52
Show Gist options
  • Save leandromoreira/4220235 to your computer and use it in GitHub Desktop.
Save leandromoreira/4220235 to your computer and use it in GitHub Desktop.
dreampeppers99
var Robot = function(robot) {
};
var firstTime = true;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
var moveAhead = Math.floor(Math.random()*101);
robot.ahead(moveAhead);
robot.turn(35);
robot.ahead(moveAhead);
robot.turn(36);
robot.ahead(69);
if (firstTime) {
robot.clone();
firstTime = false;
}
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scannedRobot = ev.scannedRobot;
if (scannedRobot.parentId !== robot.id ||
robot.id !== scannedRobot.parentId){
robot.ahead(50);
robot.fire();
robot.ahead(50);
robot.fire();
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(20);
robot.ahead(100); // trying to run away
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(20);
robot.ahead(100);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.turn(ev.bearing);
robot.ahead(100);
robot.clone(233);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment