Beispiel #1
0
        private void OnDrawTile(TileEventArgs e)
        {
            var tileWidth  = e.TileSize.Width;
            var tileHeight = e.TileSize.Height;
            var tilePos    = e.TileLocation.ToVector();


            var npc = m_mapMeta?.GetNPC(tilePos);

            if (npc != null)
            {
                var destRect = new Rectangle(e.Location.X - npc.Animation.spriteWidth + tileWidth, e.Location.Y - npc.Animation.spriteHeight + tileHeight, npc.Animation.spriteWidth, npc.Animation.spriteHeight);
                m_actorManager.Graphics = e.Graphics;
                e.Graphics.DrawImage(m_actorManager.Actors[npc.CharSet], destRect, npc.Animation.SourceRect.X, npc.Animation.SourceRect.Y, npc.Animation.spriteWidth, npc.Animation.spriteHeight, GraphicsUnit.Pixel, new System.Drawing.Imaging.ImageAttributes());
            }

            var eventId = m_mapMeta?.GetEventId(tilePos);

            if (eventId != null)
            {
                var destRect   = new Rectangle(e.Location.X, e.Location.Y, tileWidth, tileHeight);
                var tileBitmap = Properties.Resources.Event_32;
                e.Graphics.DrawImage(tileBitmap, destRect, 0, 0, tileWidth, tileHeight, GraphicsUnit.Pixel, new System.Drawing.Imaging.ImageAttributes());
            }
        }
Beispiel #2
0
        public void Draw(Vector pos)
        {
            for (var y = 0; y <= WindowRows; y++)
            {
                for (var x = 0; x <= WindowColumns; x++)
                {
                    // don't draw extra tile if on the boundary
                    if (pos.Y >= Height - Screen.HalfHeight && y == WindowRows)
                    {
                        break;
                    }
                    if (pos.X >= Width - Screen.HalfWidth && x == WindowColumns)
                    {
                        continue;
                    }

                    int playerTileX, playerTileY;
                    int offsetX = 0, offsetY = 0;

                    // handle player X coordinate
                    if (pos.X < Screen.HalfWidth)
                    {
                        // offset player when near the left boundary of the map
                        playerTileX = 0;
                    }
                    else if (pos.X > Width - Screen.HalfWidth)
                    {
                        // offset player when near the right boundary of the map
                        playerTileX = (Width - Screen.Width) / TileWidth;
                    }
                    else
                    {
                        // position the player in the middle of the screen
                        playerTileX = (pos.X - Screen.HalfWidth) / TileWidth;
                        offsetX     = pos.X % TileWidth;
                    }

                    // handle player Y coordinate
                    if (pos.Y < Screen.HalfHeight)
                    {
                        // offset player when near the top boundary of the map
                        playerTileY = 0;
                    }
                    else if (pos.Y > Height - Screen.HalfHeight)
                    {
                        // offset player when near the bottom boundary of the map
                        playerTileY = (Height - Screen.Height) / TileHeight;
                    }
                    else
                    {
                        // position the player in the middle of the screen
                        playerTileY = (pos.Y - Screen.HalfHeight) / TileHeight;
                        offsetY     = (pos.Y + TileHeight / 2) % TileHeight;
                    }

                    // draw all tile layers
                    for (var layer = 0; layer < Layers.Length; layer++)
                    {
                        var tile = Layers[layer].Tiles[x + playerTileX, y + playerTileY];

                        if (tile?.Tileset != null)
                        {
                            var drawRect = new Rect(x * TileWidth - offsetX, y * TileHeight - offsetY, TileWidth, TileHeight);

                            _tilesetManager.Draw(tile.Tileset, drawRect, tile.SpriteRect);

                            if (layer == 0)
                            {
                                DrawEventCollection(MapMeta.GetEventId(new Vector(x + playerTileX, y + playerTileY)), new Vector(x * TileWidth - offsetX, y * TileHeight - offsetY));
                            }
                        }
                    }
                }
            }
        }