Example #1
0
    public void WalkTo(Point tile, Faction faction, float speed = 3f)
    {
        if (PerformAction(tile))
        {
            return;
        }

        if (hasMoved)
        {
            return;
        }
        UnitPiece unit = unitGrid[tile.x, tile.y];

        // Already selected unit clicked
        if (selectedUnit == unit)
        {
            UnselectUnit();
        }

        else if (unit == null)
        {
            foreach (Point move in moves)
            {
                if (move == tile)
                {
                    hasMoved = true;
                    Move(selectedUnit, tile);
                    selectedUnit.MoveTo(mapManager, move, speed);
                    mapManager.RemoveMarkings();
                    combatManager.MoveDone();
                }
            }
        }

        else if (unit.unit.faction == faction)
        {
            SelectUnit(tile, faction);
        }
    }
Example #2
0
    /*==================================================================
    *  UNITS
    * ================================================================*/

    public void AddUnit(Point position, Unit unitData, Faction faction, int identifier = -1)
    {
        UnitPiece unit = Instantiate(unitPrefab, transform);

        unit.identifier = identifier;
        unit.SetUnit(unitData);
        unit.unit.faction = faction;
        unitGrid[position.x, position.y] = unit;

        if (faction == Faction.Player)
        {
            army.Add(unit);
        }
        else
        {
            unit.spriteRenderer.flipX = true;
            monsters.Add(unit);
        }
        initiativeOrder.Add(unit);
        unit.MoveTo(mapManager, position, -1);
    }