This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

What should I do to keep record of map usage?

petercuipetercui Posts: 1Member

Hi guys, I am developing a Stardew Valley like 2d pixel game.
Now I have a confused point to figure out. What should I do to keep record of each items' location, and when I instance new item on the ground, they won't overlap.
For example, at (16,16) I placed a corn seed which occupy 16 * 16. And if I place another cord seed on this spot, it should reject. What should I do to apply this logic to this game?

My thoughts so far:
create a data structure to keep record of all items' location and their size, when instancing new object, check this data structure to make sure the position I am going to place has no conflict.

Is there any other thoughts that makes more sense? or do you know how Stardew Valley handle this?




  • SaitodepaulaSaitodepaula Posts: 48Member

    I have no idea if it's the best way, but what comes to my mind is a two dimensional array, of form Array[x][y].
    So, every time anything is instanced or moves, this array keeps track. Basically, all of your world information will be in this array.
    If you instance something that is 4x4 for example, a FOR LOOP will store a number or string (or anything) in each of the 16 spaces inside the array. So, everytime something else wants to use any of this spaces, it will check the array and see that it is already in use.

Sign In or Register to comment.