Esempio n. 1
0
    //Calculate Attack Range
    private void GetAttackRange(Vector2Int position, int Range)
    {
        if (Range < 2)
        {
            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 0:
                    to_position = position + Vector2Int.up;
                    place       = new Vector3Int(position.x, position.y + 1, (int)Overlay.transform.position.y);
                    break;

                case 1:
                    to_position = position + Vector2Int.left;
                    place       = new Vector3Int(position.x - 1, position.y, (int)Overlay.transform.position.y);
                    break;

                case 2:
                    to_position = position + Vector2Int.right;
                    place       = new Vector3Int(position.x + 1, position.y, (int)Overlay.transform.position.y);
                    break;

                case 3:
                    to_position = position + Vector2Int.down;
                    place       = new Vector3Int(position.x, position.y - 1, (int)Overlay.transform.position.y);
                    break;

                default:                         //Never should end up here
                    break;
                }
                //Checks if The Tile within the map.
                if (data.Within_Map(to_position))
                {
                    if (!(Attackable_Spaces.Contains(to_position)))
                    {
                        Attackable_Spaces.Add(to_position);
                        Overlay.SetTile(place, Overlay_Tile[1]);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    //Recursive Part
    private void GetValidMoves_Rec(Vector2Int position, float?Movement)
    {
        if (!(Movement < 0))
        {
            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 0:                         //Checks Top Tile from Base
                    to_position = position + Vector2Int.up;
                    place       = new Vector3Int(position.x, position.y + 1, (int)Overlay.transform.position.y);
                    break;

                case 1:                         //Checks Left Tile from Base
                    to_position = position + Vector2Int.left;
                    place       = new Vector3Int(position.x - 1, position.y, (int)Overlay.transform.position.y);
                    break;

                case 2:                         //Checks Right Tile from Base
                    to_position = position + Vector2Int.right;
                    place       = new Vector3Int(position.x + 1, position.y, (int)Overlay.transform.position.y);
                    break;

                case 3:                         //Checks Bottom Tile from Base
                    to_position = position + Vector2Int.down;
                    place       = new Vector3Int(position.x, position.y - 1, (int)Overlay.transform.position.y);
                    break;

                default:                         //Never should end up here
                    break;
                }
                //Checks if The Tile within the map. As too not show movement outside the game confines
                if (data.Within_Map(to_position))
                {
                    var Movement_Cost = Selected_Unit_Script.Movement_Costs.Get_Cost(data.Get_Tile(to_position).Type); //Calcuate Movement Cost based on the Unit Movement Type
                    if (CanWalk(to_position) & (Movement >= Movement_Cost))                                            //Check if unit can legally walk into the tile and if it has enough movement left to do so

                    {
                        if (!(Walkable_Spaces.Contains(to_position)))
                        {
                            Walkable_Spaces.Add(to_position);
                            Overlay.SetTile(place, Overlay_Tile[0]);
                            GetValidMoves_Rec(to_position, Movement - Movement_Cost);
                        }
                    }
                }
            }
        }
    }