Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Since these are zones, we just need to pick a random one and add coins
- //Variables
- var i, s, xx, yy;
- //Pick a random zone
- i = round(random(instance_number(OBJECT_ZONE)-1))+1;
- //Now get the zone's id
- i = instance_find(OBJECT_ZONE,i);
- //Also get the zone's radius size
- s = sprite_get_width(OBJECT.ZONE.sprite_index)/2;
- //Now create a coin randomly in the zone
- //First, start the infinite loop to keep checking if the position is free
- while(1)
- {
- //Get a random position
- xx = i.x-s+random(s*2);
- yy = i.y-s+random(s*2);
- //Loop through all the coins and see if any are too close to the point
- for(i=0; i!=instance_number(OBJECT_ZONE); i += 1)
- {
- with(instance_find(OBJECT_ZONE,i))
- {
- //Check if it's too close
- if point_distance(x,y,xx,yy)<=other.s
- break; //Leave this loop and try again
- else //If it isn't..
- {
- instance_create(xx,yy,OBJECT_COIN);
- exit;
- //All done!
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment