#How to make a map system that reveals itself as the player explores?

1 messages · Page 1 of 1 (latest)

queen wigeon
#

Hi there, I am trying to make a map system for my 2D pixel-art metroidvania in Godot 4.2.1 where the player reveals the map as they go. I haven't done this before and the way I plan on doing it will create thousands of variables, depending on how many areas the game ends up having. One map will have 220 variables each.

All these variables will need to be saved and loaded later so the game can remember how each map has been revealed.

I've made a grid of 220 squares that will cover each map. If the player's icon on the map touches a square, the square checks which map this is, then removes itself and states something like:
map01_sqaure01_revealed = true

So I'm basically making a variable for each individual square on each individual map. It will end up being one gigantic list of variables to be stored and loaded later.

Is this the dumbest way one can go about doing it? I feel like there has to a much better way with dictionaries or arrays or some other way where you can still have the game remember when the player loads their game. I almost never use arrays and dictionaries, and not sure how that would make a difference.

I wonder if somebody can help. I'm not sure if writing down 10000 variables is agood idea, especially since it feels like there must be a better way and also not sure if adding this amount of global variables will have an effect on the game's overall performance.

muted ravine
#

You should try making this dynamic so that you don't have to maintain a list of variables.

regal urchin
#
# Example of storing map reveal data in a dictionary
var map_data = {}

func _ready():
    # Initialize map data for map01
    map_data["map01"] = {}
    for i in range(1, 221):  # Assuming 220 squares per map
        map_data["map01"]["square" + str(i)] = false  # Not revealed initially

# When a square is revealed
func reveal_square(map_id, square_id):
    map_data[map_id][square_id] = true
queen wigeon
#

Oh thank you, this is very helpful. I'll probably have more questions on implementing this, but I'll use this as a starting point and see how far I can get on my own with this clear example.

muted ravine
#

Based on what those squares are in your game you might consider other approaches as well. If they are rooms which all are a separate scene you should probably introduce a system to save room specific state information, which could automatically include the map revealed information. In that way the system will adapt to you changing room layouts. But that really depends on what kind of game you are doing and how you do it.