Created
April 5, 2016 10:29
-
-
Save Azuxul/61913a3dcddde740ed5f2518f3aa99ad to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Jeux Blocky : Pond JS, level 10 | |
* Created by Azuxul on Monday April 5th | |
*/ | |
var deafultDirection = 0; | |
while(true) { | |
var direction = -1; | |
var swim_ = true; | |
var minDistance = 500; | |
// Detect enemy | |
for(var i = 0; i <= 315; i+=45) { | |
var distance = scan(i, 100); // Get enemy distance at i angle | |
if(distance != Infinity && distance < minDistance) { | |
direction = i; | |
if(distance <= 30) { | |
cannon(direction, distance); | |
swim_ = false; | |
} else { | |
swim_ = true; | |
} | |
} | |
} | |
// If enemy are not found go to default direction | |
direction = direction < 0 ? deafultDirection : direction; | |
// Test if is out of border | |
if(loc_x() <= 1) { | |
deafultDirection = 315; | |
direction = deafultDirection; | |
} else if(loc_x() >= 99) { | |
deafultDirection = 135; | |
direction = deafultDirection; | |
} else if(loc_y() <= 1) { | |
deafultDirection = 225; | |
direction = deafultDirection; | |
} else if(loc_y() >= 99) { | |
deafultDirection = 45; | |
direction = deafultDirection; | |
} | |
if(swim_) | |
swim(direction, 30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment