Created
December 26, 2015 19:32
-
-
Save taptapdan/27e3e2a38fca0e0c8e22 to your computer and use it in GitHub Desktop.
CodeCombat: Boulder Woods Solution
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
| // Use isPathClear to move around the randomly positioned boulders. | |
| // Automatic pathfinding doesn't work in Boulder Woods. | |
| loop { | |
| var angle = Math.PI / 2 - Math.PI / 16; | |
| while (angle >= -Math.PI / 2) { | |
| var targetX = this.pos.x + 5 * Math.cos(angle); | |
| var targetY = this.pos.y + 5 * Math.sin(angle); | |
| // Use isPathClear between your current pos and the target. | |
| targetPos = { x: targetX, y: targetY }; | |
| // If the path is clear, move to the target. | |
| if (this.isPathClear(this.pos, targetPos) ) { | |
| this.move(targetPos); | |
| // Otherwise, sweep the angle clockwise a bit. | |
| } else { | |
| angle -= Math.PI / 16; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment