Пример #1
0
 public void Awake()
 {
     sprite = GetComponentInChildren <SpriteRenderer>();
     animationTimer.onFinish += NextStep;
     animationTimer.Start();
     targetPosition = transform.position;
     currentChunk   = MapChunkManager.GetChunkAt(transform.position);
 }
Пример #2
0
 private void Awake()
 {
     if (_ == null)
     {
         _ = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
     registry = GetComponent <ChunkRegistry>();
 }
Пример #3
0
        protected bool CanJumpTo(Vector3 position)
        {
            bool     canJump = false;
            MapChunk chunk   = MapChunkManager.GetChunkAt(position);

            if (!chunk)
            {
                return(false);
            }
            Vector3Int tilePosition = chunk.permissionLayer.WorldToCell(position);
            TileBase   tile         = chunk.permissionLayer.GetTile(tilePosition);

            canJump = (tile.name == Constants.TILE_PERMISSION_WALKABLE || tile.name == Constants.TILE_PERMISSION_ABOVE_LEVEL);

            if (canJump && chunk != currentChunk)
            {
                currentChunk = chunk;
                MapChunkManager._.PerformShift(position, (position - transform.position) / 2f);
            }

            return(canJump);
        }
Пример #4
0
        protected override bool DestinationBlocked(Vector3 position)
        {
            bool     blocked = false;
            MapChunk chunk   = MapChunkManager.GetChunkAt(position);

            if (!chunk)
            {
                return(true);
            }
            Vector3Int tilePosition = chunk.permissionLayer.WorldToCell(position);
            TileBase   tile         = chunk.permissionLayer.GetTile(tilePosition);

            if (!tile)
            {
                return(false);
            }

            // Try Jump
            if (tile.name == Constants.TILE_PERMISSION_JUMP_LEFT && facing == Facing.Left)
            {
                if (CanJumpTo(position + Vector3.left))
                {
                    targetPosition += Vector3.left;
                    jumpNext        = true;
                    return(false);
                }
            }

            if (tile.name == Constants.TILE_PERMISSION_JUMP_RIGHT && facing == Facing.Right)
            {
                if (CanJumpTo(position + Vector3.right))
                {
                    targetPosition += Vector3.right;
                    jumpNext        = true;
                    return(false);
                }
            }

            if (tile.name == Constants.TILE_PERMISSION_JUMP_UP && facing == Facing.Up)
            {
                if (CanJumpTo(position + Vector3.up))
                {
                    targetPosition += Vector3.up;
                    jumpNext        = true;
                    return(false);
                }
            }

            if (tile.name == Constants.TILE_PERMISSION_JUMP_DOWN && facing == Facing.Down)
            {
                if (CanJumpTo(position + Vector3.down))
                {
                    targetPosition += Vector3.down;
                    jumpNext        = true;
                    return(false);
                }
            }

            blocked = !(tile.name == Constants.TILE_PERMISSION_WALKABLE || tile.name == Constants.TILE_PERMISSION_ABOVE_LEVEL);

            if (!blocked && chunk != currentChunk)
            {
                currentChunk = chunk;
                MapChunkManager._.PerformShift(position, position - transform.position);
            }

            return(blocked);
        }