Random object spawning
Posted 19 March 2011 - 11:01 AM
I have a problem: I just started to create a cave game of some sort, and want to make caves spawn in the ground of my 2D game.
But if I said "Jump to random position", the object wont spawn in solid objects, but the caves must spawn in the ground.
So yeah, my question is: how can I make an object jump into the solid ground?
No coding please, as I am way too stupid to use it
Posted 19 March 2011 - 12:36 PM
Use Jump to position:
If there is ground and for example, rocks, and you want the cave only appear on the ground, then I believe you'll need a bit of code.. You can also do it with Drag and drop, but it's better and easier with codes...
Edited by Hazard94, 19 March 2011 - 12:45 PM.
Posted 19 March 2011 - 12:46 PM
so as i understand you are creating objects in random positions but want them not to be at the same location as a different type of object
Create or room start event
repeat lets say 32 times (may need more or less)
jump random add in grid size (guessing game is formed in a grid)
check collision (couldnt find pic) using x as x and y as y, choosing solid or all, and checking the 'Not' box
so what happens is that the object jumps to a random position, then checks to see if this place is taken, and if not stops the repeat
hope that was what you were after, and hope it helps
if you have any troubles let me know
just tried it on my computer, and while the checking objects did not overlap the solid, they could overlap each other, so i reccommend using all in collision check
Edited by GMClay, 19 March 2011 - 12:53 PM.
Posted 19 March 2011 - 12:53 PM
Set variable "visible" to "false"
If an expression "not visible" is true
Repeat 64 times
Start of block
__ Jump to random position (snap.hor: "32", snap.vert: "32")
__ If there is collision at relative position (0,0) against Solid objects
__ Start of block
____ Set variable "visible" to "true"
____ Exit this event
__ End of block
End of block
Edit: Hey! That's just what I said. But I have more icons
Edited by YellowAfterlife, 19 March 2011 - 12:54 PM.
Posted 19 March 2011 - 01:28 PM
Posted 19 March 2011 - 01:36 PM
Hmm. Indeed. Then that line should be changed to
BTW, yellow, I believe from past experience that Jump to Random automatically avoids all solid objects.
Jump to position (floor(random(room_width)/32)*32, floor(random(room_height)/32)*32)
Posted 19 March 2011 - 02:58 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users