-
-
Save overfl0/4279439 to your computer and use it in GitHub Desktop.
[qx3] Dr. Dree
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) { | |
| this.turnToRight = true; | |
| this.invertedDirection = false; | |
| }; | |
| Robot.prototype.onIdle = function(ev) { | |
| var robot = ev.robot; | |
| if(this.turnToRight == true) { | |
| robot.turn(5); | |
| } else { | |
| robot.turn(-5); | |
| } | |
| if(this.invertedDirection == true) { | |
| robot.back(10); | |
| } | |
| else { | |
| robot.ahead(10); | |
| } | |
| }; | |
| Robot.prototype.onRobotCollision = function(ev) { | |
| var robot = ev.robot; | |
| var collidedRobot = ev.collidedRobot; | |
| if (robot.id == collidedRobot.parentId || robot.parentId == collidedRobot.id) { | |
| robot.turn(-10); | |
| return; | |
| } | |
| //this.invertedDirection = true; | |
| }; | |
| Robot.prototype.onWallCollision = function(ev) { | |
| var robot = ev.robot; | |
| if(ev.bearing > 0 && this.invertedDirection == false) { | |
| this.turnToRight = false; | |
| } else { | |
| this.turnToRight = true; | |
| } | |
| robot.ahead(); | |
| }; | |
| Robot.prototype.onScannedRobot = function(ev) { | |
| var robot = ev.robot; | |
| var scannedRobot = ev.scannedRobot; | |
| if (robot.id == scannedRobot.parentId || robot.parentId == scannedRobot.id) { | |
| return; | |
| } | |
| if(scannedRobot.position.x > 0 ) { | |
| this.turnToRight = true; | |
| } else { | |
| this.turnToRight = false; | |
| } | |
| robot.stop() | |
| robot.clone(); | |
| robot.fire(); | |
| robot.ahead(100); | |
| }; | |
| Robot.prototype.onHitByBullet = function(ev) { | |
| var robot = ev.robot; | |
| robot.ahead(100); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment