How do I spawn an entity in a blank space

0 favourites
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • 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

  • 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

  • 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.

  • Hmm... The coordinates "getcelltype" function creates seem weird looking at the debug screen... I still don´t know what i´m doing wrong!

    Is this the way it´s supposed to be?

    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

  • 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.

    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.

  • It finally works, kinda! In my first method I called the function, then checked the cellType and so on, kind of the same thing but longer and in a slight different order... A mess. It now generates the walls if I change *32 to cellSize but they don´t look like they are being placed correctly. EDIT: I just realized i´m over 500 rp, i´m uploading the damn .capx that would have made all of this way easier HERE: (requires litetween) https://www.dropbox.com/s/6t9zfd4dc4231 ... .capx?dl=0

    Or else, they will spawn like these:

  • It seems that I require the "ParticlesWH" plugin from Scirra... However, I have no idea what that is...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh really sorry, totally forgot about this one: (just a variant of the original particles)

  • I finally got to take a look at it. It seems I botched the GetCellType function, had a second look at it and I had the value representing an empty and filled cell mixed up. Just adjust the value for "FakeWallSpot" to =1 and "Wall" to =3.

  • It works as intented now! It picks all the possible spots but it also picks wall spots for some reason? You can see the well placed ones because they aren´t overlapping any wall.

    Here´s the .capx

    https://www.dropbox.com/s/4qyo33rhfnsnq ... .capx?dl=0

    Again, I can´t thank you enough for all the help!

  • Oops, I've added a condition in your previous capx and forgot to tell you about it. In event 20, be sure to restrict function calls to empty cells. So add a "Cave : Value at cave.CurX, cave.CurY = 1" before the "Pick CellTypePos..." and everything should be good.

  • Works 100%. Enormous thanks to you, Magistross !

  • After a bit of testing I stumbled upon a rare occurrence of a "bug" that leads to some cells getting wrongly "typed" (a "Corner" getting labeled as "FakeWallSpot", for instance). The problem comes from the "cleaning" part where lone obstacle "cell" get removed. It's a bummer, but the only way to ensure that the bug never happen is to do the cell "typing" in a separate "For each XY" on the cleaned array, thus increasing the generation algorithm run time.

  • I can´t see exactly what part of the cleaning process you are talking about, but I know what you mean, I´ll see if I can fix it...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)