Guest User

Untitled

a guest
Jul 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. function check_star_location($x,$y) {
  2.  
  3.  
  4. $star_check3 = "SELECT b_x,b_y FROM planets WHERE x = '".($x)."' AND y = '".($y)."'";
  5. $star_check2 = mysql_query($star_check3) or trigger_error("SQL", E_USER_ERROR);
  6. while ($star_check1 = mysql_fetch_assoc($star_check2)) {
  7.  
  8. $arr[] = $star_check1;
  9. }
  10.  
  11. $arr = !isset($arr) ? '' : $arr; // prevents undefine error notice
  12.  
  13. $star_loop_again = 0;
  14.  
  15. while ($star_loop_again < 1) {
  16. // random a new star location
  17. $b_x = rand(0,570);
  18. $b_y = rand(0,370);
  19. $distance = ''; // prevents undefine error notice
  20. foreach($arr as $db) {
  21.  
  22. $db_x = $db['b_x'];
  23. $db_y = $db['b_y'];
  24. $distance .= distance($b_x,$b_y,$db_x,$db_y) . "-";
  25.  
  26. }
  27.  
  28. // explodes distance variable into an array
  29. $distance_numbers = explode("-", $distance);
  30. array_pop($distance_numbers);
  31.  
  32. // counts how many planets are to close to another star
  33. $array_distances = array_filter($distance_numbers,"compare_distance");
  34. $count = count($array_distances);
  35.  
  36.  
  37. // if count is more then 0 then make it loop
  38. if($count > 0) {
  39.  
  40. $star_loop_again = 0;
  41.  
  42. }else{
  43.  
  44. ++$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
  45.  
  46. }
  47. }
  48. return array($b_x,$b_y);
  49.  
  50. }
  51.  
  52.  
  53.  
  54. function compare_distance($v) {
  55.  
  56. GLOBAL $star_distance; // grabs global variable
  57. if ($v < $star_distance) {
  58.  
  59. return true;
  60. }
  61. return false;
  62. }
Add Comment
Please, Sign In to add comment