How do I spawn an entity in a blank space

Get help using Construct 2

Post » Thu Jul 09, 2015 4:49 pm

Ok, so you indeed need a function that checks neighboring cells, but you also need another one that will find you a random spot for a particular enemy type. First, the checking function.

Image

Then, it might be a good idea to keep a list of each location of type of tiles. Best place to do it would be when you create your "cleaned copy". Now HOW to do it is another question. I would use multiple instances of a two-dimensional array. First, create the arrays.

Image

Each array has a size of (0,2,1) and it will expand as we fill them.

Then add this when you create your cleaned copy, just under the line 13 in your events screenshot, as a sub-event of line 11. You might also want to set cave.CurValue to 1 in line 13 too, and not just in your cleaned copy.

Image

Afterwards, when you want to spawn your enemies, all you have to do to pick a location, is get a random position in the correct CellTypePos array, and pop it, so it doesn't get picked again.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Thu Jul 09, 2015 9:10 pm

That is AWESOME! I should use functions more frequently... Sincerely, thank you for all the trouble I got you into, it´s exactly what I needed :)

This is the kind of thing that make these forums shine!
Last edited by CloveltOc on Thu Jul 09, 2015 9:49 pm, edited 1 time in total.
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Thu Jul 09, 2015 9:25 pm

No problem! I'm interested to see how you implement what I just provided you though, if you're not too shy about it! ;)
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Thu Jul 09, 2015 9:50 pm

No problem, as soon as I have my 500 rp ;)
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Fri Jul 10, 2015 8:57 pm

Hmm, it works great, but I might be picking random positions from CellTypePos in the incorrect way because even when I pop the picked position, objects still spawn twice sometimes... Sorry for disturbing you again @Magistross

Which would be the correct way of doing it? Last thing, I don´t know what you meant with "You might also want to set cave.CurValue to 1 in line 13 too" Image Am I doing it right?

Again, thank you sincerely for all the help. (and sorry for being such a dummy with arrays)
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Fri Jul 10, 2015 9:15 pm

Show me how you did the position picking/popping part, I'll tell you if something isn't right.

And concerning that highlighted event, it should be exactly the same as the one above, but change the "cave" array instead of the "clean copy" array.
So we have : cave -> Set value at (cave.CurX, cave.CurY) to 1
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Fri Jul 10, 2015 9:29 pm

I actually scrapped the last method because I think I got it wrong from the base, used [removed] to pick a random position of the array... Maybe I did not understand what you provided correctly? It´s litterally my first week with arrays, I´m really sorry... Just curious, which would be the best way of doing it, @Magistross? I´m actually confused

Edit: I can´t post urls yet, it got removed but you get the idea :I
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Fri Jul 10, 2015 10:09 pm

What you basically have to do is get a random integer between 0 and array's width - 1, retrieve the info at that index (Array.At(randomInt, 0) for x coord and Array.At(randomInt, 1) for y). Once you have the coordinates, you delete that index from the array. (Delete index randomInt from X axis)

Hope this helps.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Sat Jul 11, 2015 11:27 am

Hmm... The coordinates "getcelltype" function creates seem weird looking at the debug screen... I still don´t know what i´m doing wrong!
Image
Is this the way it´s supposed to be?
Image
I got a mess doing the first failed method, and this simply gives no result... I´ll keep trying, i´m such an idiot with arrays
B
9
S
3
Posts: 153
Reputation: 1,272

Post » Sat Jul 11, 2015 4:28 pm

The coordinates in the array are actually "tile" coordinates, so to get the real X/Y on the layout, you have to multiply them by the correct tile width/height.

On line 22 of your previous picture, you are calling the the "GetCellType" function with no parameter, so it's constantly checking the type of tile 0,0. However I don't why you are checking for a "FakeWallSpot" while we already have all possibile position... On line 23, before looking inside a CellTypePos array, you have to limit the SOL to the correct array (the one with CellTypePos.cellType = "FakeWallSpot"), you can use pick by evaluate or compare instance variable for this. Here's a screenshot of how I'd do it all. I supposed your tiles were of size 32x32.

Image

Enemy generation should be done after the world generation, I can't really see if that's the case currently, so I'm telling you just in case. ;)
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 22 guests