Пример #1
0
        public MapChunk GetChunkData(Vector2Int coord)
        {
            string     entry     = AsCoordinate(coord.x, coord.y);
            GameObject chunk     = null;
            MapChunk   chunkData = null;

            if (registeredChunks.ContainsKey(entry))
            {
                chunk     = registeredChunks[entry];
                chunkData = chunk.GetComponent <MapChunk>();
            }
            else
            {
                Debug.LogWarning($"Chunk for {coord.x}{coord.y} was not found!");
            }

            return(chunkData);
        }
Пример #2
0
        private void Register(GameObject chunk)
        {
            MapChunk chunkData = chunk.GetComponent <MapChunk>();

            if (!chunkData)
            {
                return;
            }

            string entry = $"{chunkData.X.ToString()}{chunkData.Y.ToString()}";

            if (registeredChunks.ContainsKey(entry))
            {
                Debug.LogWarning($"A duplicated registry for {entry} was intended.");
            }
            else
            {
                registeredChunks.Add(entry, chunk);
            }
        }
Пример #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);
        }