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
  • I´m trying to do some procedural cave-like generation, but after being able of generating/resetting the terrain, I need different entities to spawn in empty spaces within the layout. It uses arrays with "miners" that clear up "wall" sprites while generating.

    I would like to know how to detect specific locations like hallways, corners or open spaces if possible.

    Thanks a lot! Hope someone answers this time, heheh...

  • Off the top of my head I'd say that you should create a function a receive a point (x,y), and it returns the state of that particular tile in the array. If tile is empty, and have obstacles to the left, top and right, then return 1... do so for all your combination, and then use that function whenever you need to test a particular tile.

  • Oh I see... I don´t really have much an idea of how would I do that, but I´ll give it a try, thanks!

    Though further explanation would be greatly appreciated

  • How is your terrain data represented, is it an array, or a tilemap ?

  • Sorry for the wait, I used to try tilemaps, but switched to sprites and found Yann´s post about procedural generation with miners. I can´t post plain URL´s (for the .capx) yet but it looks like there´s no problem with images so I´ll post the process:

    They are pretty much three arrays of 10 w each

    Edit: c2 missed an event when making the screenshot that generated a wall for each XY element, it basically created the grid of sprites.

  • I´m still stuck with this, if anyone could help, that would be awesome

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's still tough to determine what you want exactly. Care to elaborate a bit more ?

  • Yes, sorry Magistross :

    -The array gets cleaned, then generates a grid of sprites which gets carved by "miners" (miner method).

    -An empty cell is represented as 1 in the array

    -Everything is generated from a center point in which the player is positioned so it´s never stuck

    So what I want is to make the engine look for an empty space xy pixels far from the player pe enemies items... And if possible detecting special cases like an empty space surrounded by three sides (for a fake wall), a corner, a wall (turret)... like represented in the first post. I know I could do this with invisible high speed solid bullets, but the second part would require proper logic.

    I apologise if I still did not explain it enough.

  • I still can't grasp exactly your need. A function that check neighboring cells and return its "type" is dead easy to do, but obviously you want more. Maybe you could draw another diagram?

  • Here it is, I hope it´s better explained. (ignore that green arrow too, it got in the way)

    As I said, I use a method really similar to Yann´s "miners" procedural generation, an array that is translated to a sprite grid, carving rooms and hallways from a center point.

    What I want is to pick coordinates of an empty space so enemies can spawn. My main concern was that it would be pretty lame having all enemies spawning in random locations (in fact, it would be malfunctional because some depend on the terrain like turrets or worms), and I´m really bad with arrays so I was asking for a way to detect special areas like the ones shown in the image.

    I don´t know if I could explain this in a better way, i´m an absolute noob with procedural generation

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

    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.

    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.

    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.

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

  • No problem! I'm interested to see how you implement what I just provided you though, if you're not too shy about it!

  • No problem, as soon as I have my 500 rp

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

    Am I doing it right?

    Again, thank you sincerely for all the help. (and sorry for being such a dummy with arrays)

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