Skip to content

Instantly share code, notes, and snippets.

@Isinlor
Forked from Shipow/robot.js
Created December 5, 2012 11:51
Show Gist options
  • Save Isinlor/4214969 to your computer and use it in GitHub Desktop.
Save Isinlor/4214969 to your computer and use it in GitHub Desktop.
Shipow#002 - New branch
var Robot = function(robot) {
robot.rotateCannon(-90);
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead();
//i'll add a clone but i need to refactor collision
robot.clone();
};
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(-15);
robot.rotateCannon(15);
}else{
}
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot, collidedRobot = ev.collidedRobot;
robot.ignore('onRobotCollision')
if (ev.bearing > -90 && ev.bearing < 90) {
robot.back(100);
}
else {
robot.ahead(100);
}
if (robot.id != collidedRobot.parentId && robot.parentId != collidedRobot.id) {
robot.turnGunRight(ev.bearing - robot.cannonRelativeAngle);
robot.turnGunLeft(ev.bearing - robot.cannonRelativeAngle);
}
robot.listen('onRobotCollision')
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.turn(-90+ev.bearing);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment