public void Draw(SpriteBatch spriteBatch)
 {
     if (bVisible)
     {
         asSprite.Draw(spriteBatch, 0, 0);
     }
 }
Beispiel #2
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);



            gameTime = new GameTime();
            switch (CurrentGameState)
            {
            //Menu..
            case MainMenu.GameState.MainMenu:
                spriteBatch.Begin();
                spriteBatch.Draw(Content.Load <Texture2D>(@"fonds\ReversiMenu"), new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
                btnPlay.Draw(spriteBatch);
                btnQuit.Draw(spriteBatch);
                btnOptions.Draw(spriteBatch);
                spriteBatch.End();
                break;

            case MainMenu.GameState.Paused:
                spriteBatch.Begin();
                spriteBatch.Draw(Content.Load <Texture2D>(@"fonds\image_pause"), new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
                btnPlay.Draw(spriteBatch);
                btnQuit.Draw(spriteBatch);
                btnMenu.Draw(spriteBatch);
                btnOptions.Draw(spriteBatch);
                spriteBatch.End();
                break;


            case MainMenu.GameState.Jeu:
                #region ;
                GraphicsDevice.Clear(Color.Black);

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

                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;

                Point vladMapPoint = myMap.WorldToMapCell(new Point((int)vlad.Position.X, (int)vlad.Position.Y));

                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);

                        if ((mapx >= myMap.MapWidth) || (mapy >= myMap.MapHeight))
                        {
                            continue;
                        }

                        foreach (int tileID in myMap.Rows[mapy].Columns[mapx].BaseTiles)
                        {
                            spriteBatch.Draw(
                                Tile.TileSetTexture,
                                Camera.WorldToScreen(
                                    new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
                                Tile.GetSourceRectangle(tileID),
                                Color.White,
                                0.0f,
                                Vector2.Zero,
                                1.0f,
                                SpriteEffects.None,
                                1.0f);
                        }
                        int heightRow = 0;

                        foreach (int tileID in myMap.Rows[mapy].Columns[mapx].HeightTiles)
                        {
                            spriteBatch.Draw(
                                Tile.TileSetTexture,
                                Camera.WorldToScreen(
                                    new Vector2(
                                        (mapx * Tile.TileStepX) + rowOffset,
                                        mapy * Tile.TileStepY - (heightRow * Tile.HeightTileOffset))),
                                Tile.GetSourceRectangle(tileID),
                                Color.White,
                                0.0f,
                                Vector2.Zero,
                                1.0f,
                                SpriteEffects.None,
                                depthOffset - ((float)heightRow * heightRowDepthMod));
                            heightRow++;
                        }

                        foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].TopperTiles)
                        {
                            spriteBatch.Draw(
                                Tile.TileSetTexture,
                                Camera.WorldToScreen(
                                    new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
                                Tile.GetSourceRectangle(tileID),
                                Color.White,
                                0.0f,
                                Vector2.Zero,
                                1.0f,
                                SpriteEffects.None,
                                depthOffset - ((float)heightRow * heightRowDepthMod));
                        }

                        if ((mapx == vladMapPoint.X) && (mapy == vladMapPoint.Y))
                        {
                            vlad.DrawDepth = depthOffset - (float)(heightRow + 2) * 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);
                        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    }
                }

                vlad.Draw(spriteBatch, 0, -myMap.GetOverallHeight(vlad.Position));

                Vector2 hilightLoc   = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
                Point   hilightPoint = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));

                int hilightrowOffset = 0;
                if ((hilightPoint.Y) % 2 == 1)
                {
                    hilightrowOffset = Tile.OddRowXOffset;
                }

                spriteBatch.Draw(
                    hilight,
                    Camera.WorldToScreen(
                        new Vector2(
                            (hilightPoint.X * Tile.TileStepX) + hilightrowOffset,
                            (hilightPoint.Y + 2) * Tile.TileStepY)),
                    new Rectangle(0, 0, 64, 32),
                    Color.White * 0.3f,
                    0.0f,
                    Vector2.Zero,
                    1.0f,
                    SpriteEffects.None,
                    0.0f);
                spriteBatch.End();
                break;
            }

            #endregion ;


            base.Draw(gameTime);
        }