Skip to content

Instantly share code, notes, and snippets.

@Azuxul
Created April 5, 2016 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azuxul/61913a3dcddde740ed5f2518f3aa99ad to your computer and use it in GitHub Desktop.
Save Azuxul/61913a3dcddde740ed5f2518f3aa99ad to your computer and use it in GitHub Desktop.
/*
* 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