G
G
Gucci chef2021-08-20 09:37:04
C++ / C#
Gucci chef, 2021-08-20 09:37:04

How to check where a player can go?

There is a method

CalculateMoveVariant()

, it should fill the sheet with all possible options for the move.

Sheet:

private List<Cell> _moveVariants = new List<Cell>();


The Cell class has a Vector2 Position field (stores x, y values. You can add vectors and do whatever you want)

There is a grid where the position is indicated and each cell has a position.

The player is in a cell with position x: 4, y: 4 (The grid is ten by ten, so the player is in the middle).

There are two variables:

private int _horizontalCellMove;
    private int _verticalCellMove;


They mean how many horizontal/vertical cells the player can move.

That is, if there were values ​​1 and 1,

then the player could move one cell horizontally forward / backward and one cell vertically forward / backward.

How to calculate where he can go knowing the position, the number of cells that the player can move and the fact that the field is not infinite?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question