Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function check_star_location($x,$y) {
- $star_check3 = "SELECT b_x,b_y FROM planets WHERE x = '".($x)."' AND y = '".($y)."'";
- $star_check2 = mysql_query($star_check3) or trigger_error("SQL", E_USER_ERROR);
- while ($star_check1 = mysql_fetch_assoc($star_check2)) {
- $arr[] = $star_check1;
- }
- $arr = !isset($arr) ? '' : $arr; // prevents undefine error notice
- $star_loop_again = 0;
- while ($star_loop_again < 1) {
- // random a new star location
- $b_x = rand(0,570);
- $b_y = rand(0,370);
- $distance = ''; // prevents undefine error notice
- foreach($arr as $db) {
- $db_x = $db['b_x'];
- $db_y = $db['b_y'];
- $distance .= distance($b_x,$b_y,$db_x,$db_y) . "-";
- }
- // explodes distance variable into an array
- $distance_numbers = explode("-", $distance);
- array_pop($distance_numbers);
- // counts how many planets are to close to another star
- $array_distances = array_filter($distance_numbers,"compare_distance");
- $count = count($array_distances);
- // if count is more then 0 then make it loop
- if($count > 0) {
- $star_loop_again = 0;
- }else{
- ++$star_loop_again; // increases the counter so its more then 1 so the loop stops since no name matches any names in the data base
- }
- }
- return array($b_x,$b_y);
- }
- function compare_distance($v) {
- GLOBAL $star_distance; // grabs global variable
- if ($v < $star_distance) {
- return true;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment