Пример #1
0
        public int SpikeAtTileCoord(int tx, int ty)
        {
            TiledMapTile?tile;

            spikeLayer.TryGetTile(tx, ty, out tile);
            return(tile.Value.GlobalIdentifier);
        }
Пример #2
0
        public int CellAtTileCoord(int tx, int ty)
        {
            if (tx < 0 || tx >= map.Width || ty < 0)
            {
                return(1);
            }
            if (ty >= map.Height)
            {
                return(0);
            }

            TiledMapTile?tile;

            collisionLayer.TryGetTile(tx, ty, out tile);
            return(tile.Value.GlobalIdentifier);
        }
Пример #3
0
        public int CellAtTileCoord(int tx, int ty)
        {
            if (tx < 0 || tx >= map.Width || ty < 0)
            {
                return(1);
            }
            // let the player drop of the bottom of the screen (this means death)
            if (ty >= map.Height)
            {
                return(0);
            }
            TiledMapTile?tile;

            collisionLayer.TryGetTile(tx, ty, out tile);
            return(tile.Value.GlobalIdentifier);
        }
Пример #4
0
        /// <summary>
        /// Gets tile info for a specific tile on the map
        /// </summary>
        /// <param name="position">map position of the tile</param>
        /// <returns>tile info, or null when no tile info is available</returns>
        public TileInfo GetTileInfo(MapPosition position)
        {
            if (this.TileMap == null)
            {
                return(null);
            }

            int mapX = position.X;
            int mapY = position.Y;

            if (this.CurrentMap.EdgeType == Map.MapEdgeType.WrapAround)
            {
                if (mapX > this.TileMap.Width)
                {
                    mapX %= this.TileMap.Width;
                }

                if (mapY > this.TileMap.Height)
                {
                    mapY %= this.TileMap.Height;
                }
            }

            if (mapX < 0 ||
                mapY < 0 ||
                mapX >= this.TileMap.Width ||
                mapY >= this.TileMap.Height)
            {
                return(null);
            }

            TiledMapTileLayer layer = this.TileMap.TileLayers.FirstOrDefault();

            if (layer == null)
            {
                return(null);
            }

            if (!layer.TryGetTile((ushort)mapX, (ushort)mapY, out TiledMapTile? tile) ||
                !tile.HasValue)
            {
                return(null);
            }

            return(GameData.GetTileInfo(tile.Value.GlobalIdentifier - 1));
        }
Пример #5
0
 private static bool IsRoomEmpty(TiledMapTileLayer layer, int startX, int startY)
 {
     for (int y = startY; y < startY + Room.NumTilesHeight; ++y)
     {
         for (int x = startX; x < startX + Room.NumTilesWidth; ++x)
         {
             // If one tile exists in this Room, then we consider it not empty.
             TiledMapTile?tile;
             if (layer.TryGetTile((ushort)x, (ushort)y, out tile))
             {
                 if (!tile.Value.IsBlank)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Пример #6
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            var initialPos = _playerPosition;
            // TODO: Add your update logic here
            var padState = GamePad.GetState(PlayerIndex.One);

            _tiledMapRenderer.Update(gameTime);
            if (_playerPosition == Vector2.Zero)
            {
                _playerPosition = _startPosition;
            }
            Vector2 finalPos = MovePlayerWithPad(gameTime);
            var     height   = _borders.TileHeight;
            var     width    = _borders.TileWidth;
            var     tx       = (_playerPosition.X - 20f) / width;
            var     ty       = (_playerPosition.Y + 20f) / height;

            _borders.TryGetTile((ushort)tx, (ushort)ty, out TiledMapTile? tile);
            if (tile.HasValue)
            {
                var rect = new Rectangle(tile.Value.X, tile.Value.Y, width, height);
                if (rect.Contains(_playerPosition))
                {
                    _playerPosition = initialPos;
                }
                else
                {
                    _playerPosition = finalPos;
                }
            }
            else
            {
                _playerPosition = finalPos;
            }
            MoveCamera(_playerPosition);

            base.Update(gameTime);
        }