private void DrawModel(ref Particle particle, bool texturepath)
        {
            foreach (ModelMesh mesh in particle.model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();

                    effect.View       = camera.getView();
                    effect.Projection = camera.getProjection();
                    effect.World      = particle.World;
                    effect.Alpha      = particle.Alpha;
                    if (texturepath)
                    {
                        effect.Texture = particle.texture;
                    }
                    effect.TextureEnabled = true;
                    effect.FogEnabled     = true;
                    effect.FogEnd         = 256;
                    effect.FogStart       = 1;
                }
                mesh.Draw();
            }
        }
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)
        {
            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);
            }
        }
        public void Draw(GameTime gameTime)
        {
            Matrix view       = camera.getView();
            Matrix projection = camera.getProjection();

            try
            {
                if (playerEntity != null)
                {
                    if (!targetPos.Equals(normalTargetPos))
                    {
                        game.getWayToGoEffect().Draw(view, projection, targetPos, Vector3.Zero, 1.0f);
                    }
                    if (targetNode != null)
                    {
                        game.getWayToGoEffect().Draw(view, projection, targetNode.getPosition(), Vector3.Zero, 1.0f);
                    }
                    foreach (WarpEntity ent in warpsEntity.Values)
                    {
                        if (ent != null)
                        {
                            ent.Draw(view, projection);
                        }
                    }
                    foreach (ItemEntity ent in itemsEntity.Values)
                    {
                        if (ent != null)
                        {
                            ent.Draw(view, projection);
                        }
                    }
                    // Draw all entity
                    foreach (UnitEntity ent in monstersEntity.Values)
                    {
                        if (ent != null)
                        {
                            if (playerEntity.getDistanceFrom(ent) <= 256)
                            {
                                ent.Draw(view, projection);
                            }
                            if (playerEntity.getDistanceFrom(ent) <= 128)
                            {
                                ent.DrawInfo(view, projection);
                                ent.DrawDamage(view, projection);
                            }
                        }
                    }
                    foreach (UnitEntity ent in npcsEntity.Values)
                    {
                        if (ent != null)
                        {
                            if (playerEntity.getDistanceFrom(ent) <= 256)
                            {
                                ent.Draw(view, projection);
                            }
                            if (playerEntity.getDistanceFrom(ent) <= 128)
                            {
                                ent.DrawInfo(view, projection);
                                ent.DrawDamage(view, projection);
                            }
                        }
                    }
                    foreach (UnitEntity ent in playersEntity.Values)
                    {
                        if (ent != null)
                        {
                            if (playerEntity.getDistanceFrom(ent) <= 256)
                            {
                                ent.Draw(view, projection);
                            }
                            if (playerEntity.getDistanceFrom(ent) <= 128)
                            {
                                ent.DrawInfo(view, projection);
                                ent.DrawDamage(view, projection);
                            }
                        }
                    }
                    playerEntity.Draw(view, projection);
                    playerEntity.DrawInfo(view, projection);
                    playerEntity.DrawDamage(view, projection);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }
        }