Greetings.

I have gotten trouble in coding a part of my game. The core gameplay is that a dragon goes through a randomly-generated dungeon, finds a treasure, and goes back to the start. The problem is that I had trouble knowing just how to place the dragon and the treasure. The idea is that the dragon would have to travel a considerable distance before finding the treasure, which is located at a "dead end". The code I used in the dungeon generation is here: http://www.dangerousru.in/p8/p8gen.html

I appreciate any help I get here.

My thoughts...

Treasure:

If you can't figure out dead ends during maze generation you can figure them out by scanning the maze afterwards. A dead end is a square with walls on three sides, if the path is one square wide. But in your sample everywhere is a dead end because there is no exit. I would instead place the treasure in a corner, a square with walls on two sides. Maybe even go so far as to lick a corner that is near the screen/map edge?

Dragon:

You could use a path finding algorithm to calculate the distance from the treasure/dragon/both to the player on the map. Keep cycling through squares until you find one that satisfies your distance goals.

Thank you, Matt.

I have been thinking on this matter a bit more. How would your advice change if I decided to place the dragon at the top-left corner? Moreover, how can I place the dragon in the top-left corner in a randomly-generated dungeon in the first place?

The absolute top-left corner or the general top-left corner?

Consider a 100x100 cell dungeon, where each cell is either passable or non-passable. If you want to put the dragon in the absolute top left corner, you could assign a "top-left value" to each cell that is the sum of its x/y coordinates (e.g. cell 1, 2 would have a value of 3). Then put the dragon in a passable cell with the lowest value. If you want to put it in the general top-left corner, just randomly choose a cell that is passable and has x/y coordinates that are both smaller than e.g. 25.

[Please log in to post a comment]