Skip to content

Instantly share code, notes, and snippets.

@fwitzke
Forked from Shipow/robot.js
Created December 5, 2012 16:01
Show Gist options
  • Save fwitzke/4216881 to your computer and use it in GitHub Desktop.
Save fwitzke/4216881 to your computer and use it in GitHub Desktop.
cheater666
var Robot = function(robot) {
robot.rotateCannon(-90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead();
};
function isClone(robot1, robot2) {
return robot1.id == robot2.parentId || robot1.parentId == robot2.id;
}
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot;
var scanned = ev.scannedRobot;
if(!isClone(robot, scanned)) {
robot.fire();
robot.rotateCannon(-15);
robot.rotateCannon(15);
} else {
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot = ev.robot;
robot.clone();
robot.ahead(60);
robot.back(60);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.rotateCannon(90);
robot.back(100);
robot.rotateCannon(-90);
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
if(robot.parentId) { //clone
robot.turn(90-ev.bearing);
} else {
robot.turn(-90+ev.bearing);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment