Assume that the objects in the game are the GameObject class, each object has a Depth field — the depth, based on which the objects overlap each other as layers with depth, the object with the highest depth will be drawn.

Пример: '.' - глубина 0, 'А' - глубина 1, '@' - глубина 2

(one)

 ..... ..@.. .A... ..... 

When you move '@' to the cell 'A', it draws '@'

(2)

 ..... ..... .@... ..... 

How to implement storage and checking for depth? So that after the reverse transition 2-> 1 the cell with 'A' was redrawn and stored in memory. There was an idea with ArrayList<GameObject>[] , but as it seems to me this is a very crooked solution

  • In theory, the character does not need to be taken into account in the "stack" of objects lying on the cell. In the cage where the character is - always show the character. Where it is not - show the topmost item in the stack (if more than one item is supposed to be in one cell). - insolor
  • @insolor The idea is that this is not a stack. And all in depth. How to store such objects - Herrgott

1 answer 1

In some cases, it is better to implement several separate arrays: Map, with data coming in solid text. Objects with coordinates and also characters.

As a result, you can draw the map in the right order. Or bottom up with overlay. Or from top to bottom ignoring already drawn sectors.

And if there are several items of the same type in the cage, then simply create a subclass of GameObject, which itself is a container for other GameObjects and stores the stack within itself, returning the character that is worth displaying. In other words, if an overlay occurs, the game logic immediately packs them into this container class.

  • And what do you mean by "several separate arrays". In the same cell can be stored infinitely many objects. How to keep them in memory - Herrgott
  • one
    @herrgott I meant object types. In this case: Map, Objects, Creatures. That Z buffer can be considered the priority of rendering. We draw a character, if it is not there - an object, if it is not, it is a landscape. And already at the level of these types it is possible to combine objects into stacks. Just so it will be easier to work with the card at the level of game logic. PS Himself would take a toy, but characters draw bad = ( - Riĥard Brugekĥaim
  • Why draw?) Dwarf Fortress, adom - ascii forever) Well, I understood your thought, I'll try - Herrgott
  • @Herrgott, in DF most of them play with tilesets, in the new adom'e there is originally tile graphics. - insolor