Created
December 5, 2012 03:30
-
-
Save codexico/4211938 to your computer and use it in GitHub Desktop.
xicoloco
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Robot = function (robot) {}; | |
Robot.prototype.onIdle = function (ev) { | |
var robot = ev.robot; | |
//search | |
robot.ahead(4); | |
robot.rotateCannon(6); | |
robot.turn(1); | |
}; | |
Robot.prototype.onScannedRobot = function (ev) { | |
var robot = ev.robot, | |
scannedRobot = ev.scannedRobot; | |
if (scannedRobot.parentId) { | |
if (scannedRobot.parentId !== robot.id && scannedRobot.parentId !== robot.parentId) { | |
robot.stop(); | |
robot.fire(); | |
robot.ahead(2); | |
} | |
} else if (scannedRobot.id !== robot.id && scannedRobot.id !== robot.parentId) { | |
robot.stop(); | |
robot.fire(); | |
robot.ahead(2); | |
} | |
robot.clone(); | |
//seek and destroy | |
//robot.ahead(5); | |
//robot.rotateCannon(-5); | |
//robot.rotateCannon(5); | |
//robot.turn(-3); | |
}; | |
Robot.prototype.onHitByBullet = function (ev) { | |
var robot = ev.robot; | |
robot.stop(); | |
robot.rotateCannon(ev.bearing); // Turn to wherever the bullet was fired | |
robot.turn(ev.bearing); // Turn to wherever the bullet was fired | |
//seek and destroy | |
robot.ahead(10); | |
robot.rotateCannon(-10); | |
robot.rotateCannon(20); | |
robot.rotateCannon(10); | |
robot.turn(-10); | |
}; | |
Robot.prototype.onWallCollision = function (ev) { | |
var robot = ev.robot; | |
robot.stop(); | |
robot.turn(ev.bearing); | |
robot.rotateCannon(30); | |
robot.back(50); | |
robot.turn(90); | |
}; | |
Robot.prototype.onRobotCollision = function (ev) { | |
var robot = ev.robot, | |
collidedRobot = ev.collidedRobot; | |
robot.stop(); | |
if (!collidedRobot.parentId) { | |
robot.rotateCannon(collidedRobot.cannonAngle); | |
robot.back(20); | |
} else if (!ev.myFault) { | |
robot.turn(-collidedRobot.angle); | |
//move | |
robot.back(50); | |
} else { | |
robot.turn(-collidedRobot.angle); | |
//move | |
robot.back(50); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment