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)
        {
            try
            {
                manager.BeginDraw(gameTime);
                bloom.BeginDraw();
                GraphicsDevice.Clear(Color.Black);
                // Draw any thing
                switch (state)
                {
                case GameState.game_login:
                    spriteBatch.Begin();
                    spriteBatch.Draw(mainBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                    spriteBatch.End();
                    break;

                case GameState.game_characterselector:
                    spriteBatch.Begin();
                    spriteBatch.Draw(mainBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                    spriteBatch.End();
                    if (charEntity != null)
                    {
                        // reset GraphicDeviceSettings to draw3D meshes
                        GraphicsDevice.BlendState        = BlendState.Opaque;
                        GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        charEntity.Draw(Matrix.CreateLookAt(new Vector3(0.0f, 5.0f, 20.0f), Vector3.Zero, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), graphics.GraphicsDevice.Viewport.AspectRatio, 1.0f, 10000.0f));
                    }
                    break;

                case GameState.game_charactercreator:
                    spriteBatch.Begin();
                    spriteBatch.Draw(mainBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                    spriteBatch.End();
                    if (charEntity != null)
                    {
                        // reset GraphicDeviceSettings to draw3D meshes
                        GraphicsDevice.BlendState        = BlendState.Opaque;
                        GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        charEntity.Draw(Matrix.CreateLookAt(new Vector3(0.0f, 5.0f, 20.0f), Vector3.Zero, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), graphics.GraphicsDevice.Viewport.AspectRatio, 1.0f, 10000.0f));
                    }
                    break;

                case GameState.game_map:
                    switch (gameHandler.currentState())
                    {
                    case GameState.map_warping:
                        // Loading screen...
                        spriteBatch.Begin();
                        spriteBatch.Draw(loadingBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                        spriteBatch.End();
                        break;

                    case GameState.map_warp:
                        // Loading screen...
                        spriteBatch.Begin();
                        spriteBatch.Draw(loadingBackground, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
                        spriteBatch.End();
                        break;

                    case GameState.none:
                        spriteBatch.Begin();
                        // reset GraphicDeviceSettings to draw3D meshes
                        graphics.GraphicsDevice.BlendState        = BlendState.Opaque;
                        graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        short mapid = gameHandler.getCurrentMapID();
                        if (mapid > 0 && mapEntities.ContainsKey(mapid))
                        {
                            mapEntities[mapid].Draw(gameCamera.getView(), gameCamera.getProjection());
                            //shadow.setMap(mapEntities[mapid].getModel());
                            //shadow.Draw(gameTime);
                        }
                        spriteBatch.End();
                        // Drawing 3d Meshes
                        gameHandler.Draw(gameTime);
                        // Drawing particle
                        spriteBatch.Begin();
                        graphics.GraphicsDevice.BlendState        = BlendState.AlphaBlend;
                        graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        particle.Draw(gameTime);
                        spriteBatch.End();
                        // Draw particle additive
                        spriteBatch.Begin();
                        graphics.GraphicsDevice.BlendState        = BlendState.Additive;
                        graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                        particle.DrawAdditive(gameTime);
                        spriteBatch.End();
                        break;
                    }
                    break;

                default:
                    break;
                }
                base.Draw(gameTime);
                manager.EndDraw();
                // Draw selected Inventory Item
                if (guiGameInventory.getSelectedItemIndex() >= 0)
                {
                    guiGameInventory.drawSelectedItemTexturePosition(spriteBatch);
                }
                if (guiGameEquipment.getSelectedItemIndex() >= 0)
                {
                    guiGameEquipment.drawSelectedItemTexturePosition(spriteBatch);
                }
            }
            catch (Exception e)
            {
                manager.EndDraw();
                Debug.WriteLine(e.StackTrace);
            }
        }