Example #1
0
    private void CreateActiveUnitAttackCells()
    {
        Example1Unit myActiveUnit = (Example1Unit)_activeUnit;

        int range = myActiveUnit.attackRange;

        for (int y = myActiveUnit.y - range; y <= myActiveUnit.y + range; y++)
        {
            if (y < 0 || y > _map.mapHeight - 1)
            {
                continue;
            }

            for (int x = myActiveUnit.x - range; x <= myActiveUnit.x + range; x++)
            {
                if (x < 0 || x > _map.mapWidth - 1)
                {
                    continue;
                }

                int dist = SrpgGameUtils.CalcSimpleDistance(x, y, myActiveUnit.x, myActiveUnit.y);
                if (dist > range)
                {
                    continue;
                }

                Example1Cell cell = (Example1Cell)_map.InstantiateCellIntoLayer(_cellLayer, cellPrefab, x, y);
                cell.SetStateToAttackable();

                _activeUnitCells.Add(cell);
            }
        }
    }
Example #2
0
    protected override bool OnCellClicked(object sender, EventArgs e)
    {
        if (!base.OnCellClicked(sender, e))
        {
            return(false);
        }

        if (_activeUnit == null || !_activeUnit.player || _activeUnitAnimating)
        {
            return(false);
        }

        Example1Cell cell = (Example1Cell)sender;

        if (cell == null)
        {
            Debug.LogError("cell is null");
            return(false);
        }

        Example1Unit myActiveUnit = (Example1Unit)_activeUnit;

        if (myActiveUnit.State == Example1Unit.CustomState.ReadyToMove)
        {
            MoveActiveUnit(cell);
        }

        return(true);
    }
Example #3
0
    private void CreateActiveUnitMoveCells()
    {
        Example1Unit myActiveUnit = (Example1Unit)_activeUnit;

        int range = myActiveUnit.moveRange;

        for (int y = myActiveUnit.y - range; y <= myActiveUnit.y + range; y++)
        {
            if (y < 0 || y > _map.mapHeight - 1)
            {
                continue;
            }

            for (int x = myActiveUnit.x - range; x <= myActiveUnit.x + range; x++)
            {
                if (x < 0 || x > _map.mapWidth - 1)
                {
                    continue;
                }

                if (SrpgGameUtils.CalcSimpleDistance(x, y, myActiveUnit.x, myActiveUnit.y) > range)
                {
                    continue;
                }

                List <SrpgAStarNode> closedNodes = null;
                if (!MakeUnitMovePath_AStar(myActiveUnit, x, y, out closedNodes, range))
                {
                    continue;
                }

                Example1Cell cell = (Example1Cell)_map.InstantiateCellIntoLayer(_cellLayer, cellPrefab, x, y);
                if (myActiveUnit.player)
                {
                    cell.SetStateToMovable();
                }
                else
                {
                    cell.SetEnemyStateToMovable();
                }

                _activeUnitCells.Add(cell);
            }
        }
    }