0
\$\begingroup\$

I'm creating a game in C++ and raylib. This is a real-time isometric game, so it is technically 2D graphics, but the rooms have a 3D structure because there will be many blocks and other objects that create obstacles, and you can jump up onto them.

What is the best way to store the objects? Ofc I want a 3D array, but it's not that simple because there are some flat objects on the floor and walls, maybe even the ceiling.

For example, flat objects on the floor: keys, scrolls, coins, etc. There can be theoretically infinite stacked on any one square of the floor (or on top of a block or crate).

Flat objects on the walls: switches, keyholes, doors, coin slots, etc.

So right now it appears that I will have to make 1 3D array, and 6 2D arrays (4 walls, floor, ceiling). This is messy enough on its own. And it's even more complicated because rooms will not always be a simple box shape. The floor layout can be any contiguous shape making interesting paths. This can lead to theoretically infinite 2D arrays for each piece of the walls...which is a nightmare to think about let alone code.

The stored objects will also include the PC and any moving characters or monsters (although they are not flat, they will take up volume like a block or crate).

Am I doomed to maintaining multiple arrays of different dimensions? There must be a better way. What is industry standard practice for this sort of room structure?

\$\endgroup\$
3
  • \$\begingroup\$ It's a bit vague question. But, it looks to me that you are looking for a way to store/represent the "levels/room/scene" for your game ? If so try checking out Tiled. You then read/load the tmx file (or use the other export formats) in your game. Of course, for actual release you might want to store them in your own custom binary file format by writing program/util to convert it. Note, even though Tiled may seem only 2D but the format is "agnostic" to it or at least it will give a reference/idea. \$\endgroup\$ Commented Feb 26 at 20:17
  • \$\begingroup\$ @Desmond Not store the levels/room/scene. Store objects and items inside the room. Normally this is done with an array but I appear to need many of them maintained against each other. \$\endgroup\$ Commented Feb 26 at 22:21
  • \$\begingroup\$ Not exactly sure yet on why you need multiple arrays, but, couldn't your objects/instances store something like the tile (i.e Floor/Wall/Ceiling) or 'tile id' and the 'tile layer level' (i.e stack level) to which it belongs or is on top of currently? Others might be able to help you if you can provide more info how you structured your objects and tile data in your game. \$\endgroup\$ Commented Feb 27 at 3:58

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.