Generating a map procedurally only once per playthrough

Hi!

I am making this game with a procedurally-generated map. The map is basically a series of hotspots that the player has to access sequentially to complete different tasks (Across the Obelisk-style). There is some randomization in the way the map is built, so it looks a bit different in every playthrough.

The game loop is as follows: (1) every time the player touches a hotspot, the game loads a new scene with a minigame; (2) the player needs to beat the minigame; and (3), if successful, the player is sent back to the main map to continue his quest, hotspot by hotspot; if not, game over.

The issue is with the map scene. Because the map generation code is called in the ready function as the map scene is loaded, the map is generated anew when the player comes back from a minigame scene. Due to the randomization it looks different every time, which obviously feels wrong.

I want the map to be procedurally generated only once, at the beginning of the game, and stay untouched for the remainder of each playthrough, but I’m not really sure how to do it.

Any tips would be very much appreciated.

Thanks!

Are you using seeded randon number generators?

var rng := RandomNumberGenerator.new()
rng.seed = 1234
rng.randf()

Not really. I just use a random offset for the hotspots, so the map doesn’t feel like a grid. Maybe seeding would help with that. However, I am not sure it would help with the kind of hotspot I have in each location. This is determined by shuffling an array that contains all types of hotspots that could potentially be at that location.

In any case, is it really necessary that the map is developed anew every time I load the map scene? Can’t it just be developed once per playthrough?

Sure, you could save all the map data somewhere, probably a Autoload or save file.

Getting use to seeded RNG is a good idea for randomized games though. This also enables you to test troublesome seeds and allow players to easily share their run through a simple number or string. Instead of saving all map data you could save only the position of the player along hotspots.

1 Like

Oh, I see. So you are saying that instead of working out node locations and types directly in the map scene I should do it in a separate script, then import the results into the map scene to instantiate the hotspots. Correct?

1 Like

Yes that would help, also a good way to separate the data in case you make an alternative map or record. If you are using change_scene_to_file you will need to keep this data in an Autoload (not removed during change_scene functions) or a save file (kept on disk)

1 Like

Thanks very much for the tip. I cannot check if it works right now, but it feels workable. I’ll try tomorrow. :+1:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.