-
-
Save samelinux/4232357 to your computer and use it in GitHub Desktop.
OpenBarbarian
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 eading; | |
| var firesign; | |
| var lasthealth; | |
| var fired; | |
| var Robot = function(robot) { | |
| eading=1; | |
| firesign=1; | |
| lasthealth=100; | |
| fired=false; | |
| robot.rotateCannon(-90); | |
| }; | |
| Robot.prototype.onIdle = function(ev) { | |
| if(eading==1) | |
| { | |
| ev.robot.ahead(30); | |
| } | |
| else | |
| { | |
| ev.robot.back(30); | |
| } | |
| if(ev.robot.cannonRelativeAngle==60 || | |
| ev.robot.cannonRelativeAngle==300) | |
| { | |
| if(firesign==1) | |
| firesign=-1; | |
| else | |
| firesign=1; | |
| } | |
| if(!fired) | |
| ev.robot.rotateCannon(10*firesign); | |
| }; | |
| Robot.prototype.onHitByBullet = function(ev) { | |
| eading=1-eading; | |
| }; | |
| Robot.prototype.onScannedRobot = function(ev) { | |
| if(lastRobotHealth>=ev.scannedRobot.life) | |
| { | |
| if(firesign==1) | |
| { | |
| firesign=-1; | |
| } | |
| else | |
| { | |
| firesign=1; | |
| } | |
| } | |
| ev.robot.fire(); | |
| ev.robot.rotateCannon(-10*firesign); | |
| }; | |
| Robot.prototype.onRobotCollision = function(ev) { | |
| eading=1-eading; | |
| }; | |
| Robot.prototype.onWallCollision = function(ev) { | |
| var robot = ev.robot; | |
| robot.turn(ev.bearing - 90); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment