-
-
Save aquamoogle/4213544 to your computer and use it in GitHub Desktop.
r2d2
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
| //FightCode can only understand your robot | |
| //if its class is called Robot | |
| var Robot = function(robot) { | |
| robot.turn(270 - robot.angle); | |
| robot.rotateCannon(90 - robot.cannonAbsoluteAngle); | |
| robot.clone(); | |
| this.options = { | |
| cloneInCorrectAngle: false, | |
| firing: false | |
| }; | |
| }; | |
| Robot.prototype.onIdle = function(ev) { | |
| var robot = ev.robot; | |
| if(this.options.firing){ | |
| robot.fire(); | |
| robot.ahead(25); | |
| robot.fire(); | |
| this.options.firing = false; | |
| } | |
| else{ | |
| robot.ahead(25); | |
| robot.rotateCannon(25); | |
| } | |
| if(robot.parentId){ | |
| if(!this.options.cloneInCorrectAngle){ | |
| robot.turn(90 - robot.angle); | |
| robot.rotateCannon(270 - robot.cannonAbsoluteAngle); | |
| this.options.cloneInCorrectAngle = true; | |
| } | |
| } | |
| }; | |
| Robot.prototype.onWallCollision = function(ev) { | |
| var robot = ev.robot; | |
| robot.turnRight(ev.bearing + 90); | |
| }; | |
| Robot.prototype.onScannedRobot = function(ev) { | |
| this.options.firing = true; | |
| var robot = ev.robot, scannedRobot = ev.scannedRobot; | |
| if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) { | |
| return; | |
| } | |
| robot.fire(); | |
| }; | |
| Robot.prototype.onHitByBullet = function(ev) { | |
| ev.robot.rotateCannon(ev.bearing - ev.robot.cannonRelativeAngle); | |
| ev.robot.fire(); | |
| }; | |
| 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') | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment