Пример #1
0
    public static void GetNextTilePosByTileDirection(eTileDirection direction, ref sTilePosition tilePos)
    {
        switch (direction)
        {
        case eTileDirection.NORTH_WEST:
            tilePos.tileY++;
            break;

        case eTileDirection.NORTH_EAST:
            tilePos.tileX++;
            break;

        case eTileDirection.SOUTH_EAST:
            tilePos.tileY--;
            break;

        case eTileDirection.SOUTH_WEST:
            tilePos.tileX--;
            break;

        case eTileDirection.IN_TILE:
            break;

        default:
            break;
        }
    }
Пример #2
0
 public void SetTilePosition(int tileX, int tileY)
 {
     _tileX = tileX;
     _tileY = tileY;
     if (null == _tilePosition)
     {
         _tilePosition = new sTilePosition(_tileX, _tileY);
     }
     else
     {
         _tilePosition.tileX = _tileX;
         _tilePosition.tileY = _tileY;
     }
 }
Пример #3
0
    void FindPath()
    {
        TileSystem tileSystem = TileSystem.Instance;

        while (0 != _pathfindingQueue.Count)
        {
            //제일 앞 타일을 하나 꺼낸다.
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);

            //방문한 타일인가?
            if (false == command.tileCell.IsVisit())
            {
                command.tileCell.Visit();

                if (_targetTileCell.GetTilePosition().Equals(command.tileCell.GetTilePosition()))
                {
                    _reverseTileCell = _targetTileCell;
                    return;
                }

                for (int direction = 0; direction < (int)eDirection.MAX; direction++)
                {
                    sTilePosition nextTilePos = new sTilePosition(command.tileCell.GetTileX(), command.tileCell.GetTileY());
                    TileHelper.GetNextTilePosByDirection((eDirection)direction, ref nextTilePos);
                    TileCell nextTileCell = tileSystem.GetTileCell(nextTilePos);

                    if (((true == tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY)) && false == nextTileCell.IsVisit()) ||
                        (nextTilePos.tileX == _targetTileCell.GetTileX() && nextTilePos.tileY == _targetTileCell.GetTileY()))
                    {
                        float newDistanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight();
                        float newHeuristic         = CalcAstarHeuristic(newDistanceFromStart, nextTileCell, _targetTileCell);

                        if (null == nextTileCell.GetPrevCell())
                        {
                            nextTileCell.SetDistanceFromStart(newDistanceFromStart);
                            nextTileCell.SetPrevCell(command.tileCell);                                 //이전 타일 기억

                            sPathCommand newCommand = new sPathCommand();
                            newCommand.heuristic = newHeuristic;
                            newCommand.tileCell  = nextTileCell;
                            PushCommand(newCommand);
                        }
                    }
                }
            }
        }
    }
Пример #4
0
    public List <TileCell> GetTilecellInAttackRange(TileCell startCell, eDirection direction, eAttackRangeType rangeType, int range)
    {
        List <TileCell> tileCells = new List <TileCell>();

        tileCells.Add(startCell);               //캐릭터가 밟고있는 셀을 넣어준다.

        sTilePosition tilePos = startCell.GetTilePosition();

        //STRAIGHT
        for (int i = 0; i < range; i++)
        {
            TileHelper.GetNextTilePosByDirection(direction, ref tilePos);
            TileCell tilecell = GetTileCell(tilePos.tileX, tilePos.tileY);
            if (null != tilecell)
            {
                tileCells.Add(tilecell);
            }
        }

        return(tileCells);
    }
Пример #5
0
    public void UpdatePosition(Vector2 position)
    {
        float   speed       = _status.speed + GetCurrentTileCell().GetProperties(eTileLayer.GROUND).speed;
        Vector2 destination = (Vector2)(_transform.position) + (position.normalized * speed * Time.deltaTime);

        TileSystem     tileSystem        = TileSystem.Instance;
        TileCell       curTileCell       = GetCurrentTileCell();
        eTileDirection boundaryDirection = curTileCell.CheckTileBoundary(destination);
        sTilePosition  nextTilePos       = new sTilePosition(_tileX, _tileY);

        TileHelper.GetNextTilePosByTileDirection(boundaryDirection, ref nextTilePos);

        if (tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY))
        {
            //타일 오프셋에 따른 캐릭터 y값 보정(des = des + (next.offset - cur.offset))
            if (eTileDirection.IN_TILE != boundaryDirection)
            {
                int layerOrder = tileSystem.GetTileCell(nextTilePos.tileX, nextTilePos.tileY).GetGroundLayerOrder();
                var sprites    = GetComponentsInChildren <SpriteRenderer>(true);
                foreach (var spriteRenderer in sprites)
                {
                    spriteRenderer.sortingOrder = layerOrder;
                }

                float curOffset  = curTileCell.GetOffset();
                float nextOffset = tileSystem.GetTileCell(nextTilePos.tileX, nextTilePos.tileY).GetOffset();
                destination.y = destination.y + (nextOffset - curOffset);

                var layer = GetCurrentLayer();
                tileSystem.GetTileCell(_tileX, _tileY).RemoveObject(this, layer);
                tileSystem.GetTileCell(nextTilePos).AddObject(this, layer);
            }

            _tileX = nextTilePos.tileX;
            _tileY = nextTilePos.tileY;

            //z값 -1 : 동일한 레이어 + 동일한 order 에서 캐릭터들이 타일보다 뒤에 있으면 안됨
            transform.position = new Vector3(destination.x, destination.y, -1.0f);
        }
    }
Пример #6
0
    public static void GetNextTilePosByDirection(eDirection direction, ref sTilePosition tilePos)
    {
        switch (direction)
        {
        //case eDirection.NORTH:
        //	tilePos.tileX++;
        //	tilePos.tileY++;
        //	break;
        case eDirection.NORTH_EAST:
            tilePos.tileX++;
            break;

        //case eDirection.EAST:
        //	tilePos.tileX++;
        //	tilePos.tileY--;
        //	break;
        case eDirection.SOUTH_EAST:
            tilePos.tileY--;
            break;

        //case eDirection.SOUTH:
        //	tilePos.tileX--;
        //	tilePos.tileY--;
        //	break;
        case eDirection.SOUTH_WEST:
            tilePos.tileX--;
            break;

        //case eDirection.WEST:
        //	tilePos.tileX--;
        //	tilePos.tileY++;
        //	break;
        case eDirection.NORTH_WEST:
            tilePos.tileY++;
            break;

        default:
            break;
        }
    }
Пример #7
0
 public TileCell GetTileCell(sTilePosition tilePosition)
 {
     return(GetTileCell(tilePosition.tileX, tilePosition.tileY));
 }
Пример #8
0
    public override void Update()
    {
        base.Update();

        _searchingDuration += Time.deltaTime;

        if (_character.HasDestination())
        {
            _patrolDuration -= Time.deltaTime;
            if (_patrolDuration < 0.0f)
            {
                _character.ResetDestination();
                _patrolDuration = _patrolCooltime;
                return;
            }

            Vector2 lookDirection = _character.GetLookDirection();
            Vector2 newPosition   = TileHelper.GetSlopeDirection(lookDirection);
            newPosition.x += lookDirection.x;
            newPosition.y += lookDirection.y;

            _character.UpdatePosition(newPosition);
        }
        else
        {
            TileCell      destination = null;
            eDirection    direction   = (eDirection)Random.Range(0, (int)eDirection.MAX);
            sTilePosition nextTile    = _character.GetTilePosition();
            TileHelper.GetNextTilePosByDirection(direction, ref nextTile);
            destination = TileSystem.Instance.GetTileCell(nextTile);
            if (null != destination)
            {
                _character.SetDestination(destination);
            }
            else
            {
                return;
            }

            //update animation
            Vector2Int lookDirection = TileHelper.GetDirectionVector(_character.GetCurrentTileCell(), destination);
            _character.UpdateDirection(lookDirection);
        }

        if (_searchingCooltime < _searchingDuration)
        {
            var mapObjects = TileSystem.Instance.FindObjectsByRange(eMapObjectType.PLAYER, _character.GetCurrentLayer(),
                                                                    _character.GetCurrentTileCell(), 4);

            if (null != mapObjects)
            {
                foreach (var target in mapObjects)
                {
                    _character.SetPathTarget(target);
                    _nextState = eStateType.CHASE;
                    return;
                }
            }
            _searchingDuration = 0.0f;
        }
    }
Пример #9
0
    void TestFunc()
    {
        //TEST: Print tile position
        if (Input.GetKeyDown(KeyCode.T))
        {
            sTilePosition tilePos = _player.GetTilePosition();
            Debug.Log(tilePos.ToString());
        }

        //TEST: Print tiles that player stepped on
        if (Input.GetKeyDown(KeyCode.Y))
        {
            sTilePosition tilePos = _player.GetTilePosition();
            int           tileX   = tilePos.tileX;
            int           tileY   = tilePos.tileY;
            for (int y = tileY + 1; y >= tileY - 1; y--)
            {
                string str = "";
                for (int x = tileX - 1; x <= tileX + 1; x++)
                {
                    if (tileX == x && tileY == y)
                    {
                        str += "● ";
                    }
                    else
                    {
                        if (TileSystem.Instance.GetTileCell(x, y).InCharacter())
                        {
                            str += "O ";
                        }
                        else
                        {
                            str += "X ";
                        }
                    }
                }
                Debug.Log(str);
            }
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            MessageParam msg = new MessageParam();
            msg.sender   = null;
            msg.receiver = _player;
            msg.message  = "Attack";
            msg.damageInfo.damagePoint = 10;
            msg.damageInfo.attackType  = eDamageType.STUN;

            MessageSystem.Instance.Send(msg);
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            var lists     = TileSystem.Instance.GetTileCell(8, 7)._mapObjectListByLayer;
            var layerList = lists[(int)eTileLayer.GROUND];
            for (int i = 0; i < layerList.Count; i++)
            {
                Debug.Log($"8, 7: {layerList[i].name}");
            }
        }
    }
Пример #10
0
 public bool Equals(sTilePosition tilePos)
 {
     return((tileX == tilePos.tileX) && (tileY == tilePos.tileY));
 }