Skip to content

Instantly share code, notes, and snippets.

@mati0090
Forked from sinbonders/robot.js
Created December 4, 2012 02:15
Show Gist options
  • Save mati0090/4199913 to your computer and use it in GitHub Desktop.
Save mati0090/4199913 to your computer and use it in GitHub Desktop.
DRONE_A2
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var rotateDir = 'right';
var cloned = 0;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(3);
robot.rotateCannon(3);
};
Robot.prototype.onScannedRobot = function(ev) {
var robot = ev.robot, scannedRobot = ev.scannedRobot;
if (robot.id === scannedRobot.parentId || robot.parentId === scannedRobot.id) {
return;
}
robot.fire();
if (rotateDir == 'right'){
robot.rotateCannon(-20);
rotateDir == 'left';
}
else {
robot.rotateCannon(20);
rotateDir == 'right';
}
robot.fire();
};
Robot.prototype.onWallCollision = function(ev) {
var robot = ev.robot;
robot.stop();
robot.turn(ev.bearing-90);
robot.ahead(20);
};
Robot.prototype.onRobotCollision = function(ev) {
var robot = ev.robot;
robot.turn(30);
robot.ahead(100);
};
Robot.prototype.onHitByBullet = function(ev) {
var robot;
robot = ev.robot;
robot.turn(90 - ev.bulletBearing);
if(cloned == 0){
robot.clone();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment