F
F
Folifolo2020-08-25 15:17:00
Game development
Folifolo, 2020-08-25 15:17:00

How to implement the interaction of a unit with a map?

I'm making an "artificial life" simulator. There is a rectangular field where at each point there can be emptiness / wall / food / acid / cell, there is also a class that describes the genetic code of the cell and other parameters. A cell can affect the field (for example, eat food), as well as other cells (for example, cause damage). I would like to know how to properly connect (or implement) a cell (unit) and a map.

Now this is implemented as a two-dimensional array of integers that correspond to the type of the object and the list of cells: each move is polled for each cell of the list, it is told what is next to it, based on which it tells what move it wants to make. After that, the appropriate changes are made to the map. For example, if a cell is moved, then "emptiness" is placed in its place in the array, and "cell" is placed at the new position. To interact with other cells, according to their coordinates on the map, the object itself is in the list and changes accordingly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Vodakov, 2020-08-25
@WaterSmith

And what confuses you in your current implementation?
Personally, it's not clear to me just what you will do in case of collisions. For example, there are two cells with food between them, and they both decide to eat it. What will happen? (another version of the collision - one cell is about to attack, and the other leaves the attacked position)
And I have no objections to storing the game state in an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question