Ejemplo n.º 1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

            Vector2 firstSquare = new Vector2(Camera.Location.X / Tile.TileStepX, Camera.Location.Y / Tile.TileStepY);
            int     firstX      = (int)firstSquare.X;
            int     firstY      = (int)firstSquare.Y;

            Vector2 squareOffset = new Vector2(Camera.Location.X % Tile.TileStepX, Camera.Location.Y % Tile.TileStepY);
            int     offsetX      = (int)squareOffset.X;
            int     offsetY      = (int)squareOffset.Y;

            float maxdepth = ((myMap.MapWidth + 1) * ((myMap.MapHeight + 1) * Tile.TileWidth)) / 10;
            float depthOffset;

            for (int y = 0; y < squaresDown; y++)
            {
                int rowOffset = 0;
                if ((firstY + y) % 2 == 1)
                {
                    rowOffset = Tile.OddRowXOffset;
                }

                for (int x = 0; x < squaresAcross; x++)
                {
                    int mapx = (firstX + x);
                    int mapy = (firstY + y);
                    depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth);

                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].BaseTiles)
                    {
                        spriteBatch.Draw(

                            Tile.TileSetTexture,
                            new Rectangle(
                                (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX,
                                (y * Tile.TileStepY) - offsetY + baseOffsetY,
                                Tile.TileWidth, Tile.TileHeight),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            SpriteEffects.None,
                            1.0f);
                    }

                    int heightRow = 0;

                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].HeightTiles)
                    {
                        spriteBatch.Draw(
                            Tile.TileSetTexture,
                            new Rectangle(
                                (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX,
                                (y * Tile.TileStepY) - offsetY + baseOffsetY - (heightRow * Tile.HeightTileOffset),
                                Tile.TileWidth, Tile.TileHeight),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            SpriteEffects.None,
                            depthOffset - ((float)heightRow * heightRowDepthMod));
                        heightRow++;
                    }

                    foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].TopperTiles)
                    {
                        spriteBatch.Draw(
                            Tile.TileSetTexture,
                            new Rectangle(
                                (x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX,
                                (y * Tile.TileStepY) - offsetY + baseOffsetY - (heightRow * Tile.HeightTileOffset),
                                Tile.TileWidth, Tile.TileHeight),
                            Tile.GetSourceRectangle(tileID),
                            Color.White,
                            0.0f,
                            Vector2.Zero,
                            SpriteEffects.None,
                            depthOffset - ((float)heightRow * heightRowDepthMod));
                    }

                    //spriteBatch.DrawString(pericles6, (x + firstX).ToString() + ", " + (y + firstY).ToString(),
                    //    new Vector2((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX + 24,
                    //        (y * Tile.TileStepY) - offsetY + baseOffsetY + 48), Color.White, 0f, Vector2.Zero,
                    //        1.0f, SpriteEffects.None, 0.0f);
                }
            }

            spriteBatch.End();
            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws the cell.
        ///
        /// If the font is supplied and non-null, coordinates will be drawn in the center of the cell.
        /// </summary>
        /// <param name="spriteBatch">An active spritebatch to draw the cell</param>
        /// <param name="xDrawPosition">The left-x pixel coordinate to draw at</param>
        /// <param name="yDrawPosition">The top-y pixel coordinate to draw at</param>
        /// <param name="startingDepth">The depth value of the bottom-most part of the cell.</param>
        /// <param name="heightRowDepthMod">The amount to decrease the depth with each stacked tile.</param>
        /// <param name="font">The font to draw the coordinates in</param>
        /// <param name="tint">The color to tint the cell</param>
        public void DrawCell(SpriteBatch spriteBatch, int xDrawPosition, int yDrawPosition,
                             float startingDepth, float heightRowDepthMod, Color tint)
        {
            float depth        = startingDepth;
            int   heightOffset = 0;
            int   lastLevel    = 0;

            foreach (int level in Tiles.Keys)
            {
                lastLevel    = level;
                heightOffset = level * Tile.HeightTileOffset;

                foreach (int tileID in Tiles[level])
                {
                    spriteBatch.Draw(
                        Tile.TileSetTexture,
                        new Rectangle(
                            xDrawPosition,
                            yDrawPosition - heightOffset - VisualElevation,
                            Tile.TileWidth,
                            Tile.TileHeight
                            ),
                        Tile.GetSourceRectangle(tileID),
                        tint,
                        0f,
                        Vector2.Zero,
                        SpriteEffects.None,
                        depth - ((float)level) * heightRowDepthMod);

                    depth -= heightRowDepthMod;
                }
            }

            if (UseBorders)
            {
                if (UseLeftBorder)
                {
                    spriteBatch.Draw(
                        Tile.TileSetTexture,
                        new Rectangle(
                            xDrawPosition,
                            yDrawPosition - heightOffset - VisualElevation,
                            Tile.TileWidth,
                            Tile.TileHeight
                            ),
                        Tile.GetSourceRectangle(LeftBorderTileIndex),
                        tint,
                        0f,
                        Vector2.Zero,
                        SpriteEffects.None,
                        depth - ((float)lastLevel) * heightRowDepthMod);
                }

                if (UseRightBorder)
                {
                    spriteBatch.Draw(
                        Tile.TileSetTexture,
                        new Rectangle(
                            xDrawPosition,
                            yDrawPosition - heightOffset - VisualElevation,
                            Tile.TileWidth,
                            Tile.TileHeight
                            ),
                        Tile.GetSourceRectangle(RightBorderTileIndex),
                        tint,
                        0f,
                        Vector2.Zero,
                        SpriteEffects.None,
                        depth - ((float)lastLevel) * heightRowDepthMod);
                }

                if (UseTopBorder)
                {
                    spriteBatch.Draw(
                        Tile.TileSetTexture,
                        new Rectangle(
                            xDrawPosition,
                            yDrawPosition - heightOffset - VisualElevation,
                            Tile.TileWidth,
                            Tile.TileHeight
                            ),
                        Tile.GetSourceRectangle(TopBorderTileIndex),
                        tint,
                        0f,
                        Vector2.Zero,
                        SpriteEffects.None,
                        depth - ((float)lastLevel) * heightRowDepthMod);
                }

                if (UseBottomBorder)
                {
                    spriteBatch.Draw(
                        Tile.TileSetTexture,
                        new Rectangle(
                            xDrawPosition,
                            yDrawPosition - heightOffset - VisualElevation,
                            Tile.TileWidth,
                            Tile.TileHeight
                            ),
                        Tile.GetSourceRectangle(BottomBorderTileIndex),
                        tint,
                        0f,
                        Vector2.Zero,
                        SpriteEffects.None,
                        depth - ((float)lastLevel) * heightRowDepthMod);
                }
            }
        }