简体   繁体   中英

Concave hull on procedural 2d dungeon

Currently we have pre-made dungeon levels in our game, but we are working on an algorithm, that generates random dungeons for our game. The generation part is okay, but there is jumping in our game, so the player can jump over certain sized gaps (lets say ~5 tiles). (See the image and yellow lines) The jumping area is filled with tiles that act as walls when on the ground, but as ground when the player is "gliding over".

My idea was to make some kind of "concave hull" around the dungeon (see the picture and the white outlines) and fill the empty insides with "jump tiles". Even then, there would be a problem, that the gaps inside are not necessary small enough (see the big hole in the middle of a map with blue and yellow linese).

So how can I detect when the empty areas are not to be filled with jump tiles (blue lines) and when I should add the jump tiles (yellow lines).

I had no luck finding anything useful by searching about concave hulls and convex hulls (red lines in the image).

MS Paint演示

You only allow jumping straight east-west or north-south, right?

Pseudocode:

for all floor tiles
   find the next floor tile traveling south, stop when one is found or after examining 6 tiles
   if a floor tile was found then mark the intervening tiles as jump tiles

   find the next floor tile traveling east, stop when one is found or after examining 6 tiles
   if a floor tile was found then mark the intervening tiles as jump tiles

Beware that this could allow jumping over longer walls if you have say a rectangle of 8x5 tiles. Such a rectangle would be marked with jumping tiles because you can jump over it in the direction where it's only 5 tiles wide. But then it would allow jumping over a 8-tile-long wall. That's a limit of your data model though. You'd need jump-x, jump-y and jump-both tiles to encode all variations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM