Skip to content

Instantly share code, notes, and snippets.

@rolemos
Created December 4, 2012 13:08
Show Gist options
  • Save rolemos/4203728 to your computer and use it in GitHub Desktop.
Save rolemos/4203728 to your computer and use it in GitHub Desktop.
[qx3] RoLemosRobot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.clone();
robot.rotateCannon(robot.bearing);
robot.ahead(50);
robot.turn(50);
robot.rotateCannon(180);
robot.back(50);
robot.rotateCannon(180);
};
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(-5);
robot.rotateCannon(-30);
}
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.ahead(robot.position+5);
robot.ahead(robot.position-15);
robot.fire();
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.rotateCannon(cannonAbsoluteAngle+ev.bulletBearing);
robot.fire();
robot.turn(90 - ev.bulletBearing);
robot.ahead(50);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment