Ember

AddCoins

May 16th, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Since these are zones, we just need to pick a random one and add coins
  2.  
  3. //Variables
  4. var i, s, xx, yy;
  5.  
  6. //Pick a random zone
  7. i = round(random(instance_number(OBJECT_ZONE)-1))+1;
  8.  
  9. //Now get the zone's id
  10. i = instance_find(OBJECT_ZONE,i);
  11.  
  12. //Also get the zone's radius size
  13. s = sprite_get_width(OBJECT.ZONE.sprite_index)/2;
  14.  
  15. //Now create a coin randomly in the zone
  16.  
  17. //First, start the infinite loop to keep checking if the position is free
  18. while(1)
  19. {
  20.     //Get a random position
  21.     xx = i.x-s+random(s*2);
  22.     yy = i.y-s+random(s*2);
  23.    
  24.     //Loop through all the coins and see if any are too close to the point
  25.     for(i=0; i!=instance_number(OBJECT_ZONE); i += 1)
  26.     {
  27.         with(instance_find(OBJECT_ZONE,i))
  28.         {
  29.             //Check if it's too close
  30.             if point_distance(x,y,xx,yy)<=other.s
  31.             break; //Leave this loop and try again
  32.             else //If it isn't..
  33.             {
  34.                 instance_create(xx,yy,OBJECT_COIN);
  35.                 exit;
  36.                 //All done!
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment