示例#1
0
        /// <summary>
        /// Draws the entity as a billboard sprite.
        /// </summary>
        public void Draw(QuadDrawer quadDrawer, Vector3 cameraPosition,
                         Matrix view, Matrix projection, Matrix world)
        {
            Matrix worldModifiers = Matrix.CreateScale(texture.Width / 2, texture.Height / 2, 1)
                                    * Matrix.CreateRotationX(Up.X) * Matrix.CreateRotationY(Up.Y) * Matrix.CreateRotationZ(Up.Z) * Matrix.CreateRotationZ(MathHelper.Pi)
                                    * (Matrix.CreateTranslation(position + new Vector3(texture.Width / 2, texture.Height / 2, 0)));

            quadDrawer.DrawQuad(Texture, 1, world * worldModifiers, view, projection);
            quadDrawer.DrawQuad(Texture, 1, world * Matrix.CreateRotationY(MathHelper.Pi) * worldModifiers, view, projection);
        }
示例#2
0
        public void Draw(GraphicsDevice device, Level level, Player[] players, bool inTwoPlayer, int playerNo, ContentManager Content, Options options)
        {
            device.Clear(Color.BlueViolet);

            device.BlendState = BlendState.AlphaBlend;


            Matrix view = players[playerNo - 1].camera.get_transformation_3d(device) * Matrix.CreateLookAt(cameraPosition, cameraPosition + cameraForward, cameraUp);

            Matrix projection = Matrix.CreatePerspectiveFieldOfView((float)Math.Atan(Math.Max(options.screenWidth, options.screenHeight) / cameraPosition.Z) * 1.07f,
                                                                    device.Viewport.AspectRatio, 0.001f, 3000);

            Matrix groundTransform = Matrix.CreateScale(1, -1, 1) * Matrix.CreateRotationX(MathHelper.Pi);

            quadDrawer.DrawQuad(Sprite.AddTint(level.background, level.backgroundColor), 1, groundTransform * Matrix.CreateScale((float)level.levelWidth / 2, (float)level.levelHeight / 2, 0)
                                * Matrix.CreateTranslation((float)level.levelWidth / 2, (float)level.levelHeight / 2, 0), view, projection);

            quadDrawer.DrawQuad(Sprite.AddTint(level.background, level.backgroundColor), 1, groundTransform * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateScale((float)level.levelWidth / 2, (float)level.levelHeight / 2, 0)
                                * Matrix.CreateTranslation((float)level.levelWidth / 2, (float)level.levelHeight / 2, 0), view, projection);

            foreach (Solid solid in level.backSolids)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = solid.sprite.getTexture();
                sprite.Position = new Vector3(solid.sprite.vector.X, solid.sprite.vector.Y, 0);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Drop drop in level.drops)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = drop.sprite.getTexture();
                sprite.Position = new Vector3(drop.sprite.vector.X, drop.sprite.vector.Y, 0);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Solid solid in level.solids)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = solid.sprite.getTexture();
                sprite.Position = new Vector3(solid.sprite.vector.X, solid.sprite.vector.Y, 0);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Vector2 spawner in level.zombieSpawners)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = Content.Load <Texture2D>("ZombieSpawner");
                sprite.Position = new Vector3(spawner.X, spawner.Y, 0);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Zombie zombie in level.zombies)
            {
                _3DSprite sprite = new _3DSprite();

                sprite.Texture  = zombie.sprite.getTintedTexture();
                sprite.Position = new Vector3(zombie.sprite.vector - new Vector2(zombie.sprite.getTexture().Width / 2, zombie.sprite.getTexture().Height / 2), 0);
                sprite.Up       = new Vector3(0, 0, zombie.rotation);

                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (BasicWeaponBullet bullet in level.basicWeaponBullets)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = bullet.sprite.getTexture();
                sprite.Position = new Vector3(bullet.sprite.vector, 0) - Vector3.Transform(new Vector3(bullet.origin, 0), Matrix.CreateRotationZ(bullet.rotation));
                sprite.Up       = new Vector3(0, 0, bullet.rotation);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Rocket bullet in level.rockets)
            {
                if (bullet.exploding == 0)
                {
                    _3DSprite sprite = new _3DSprite();
                    sprite.Texture  = bullet.sprite.getTexture();
                    sprite.Position = new Vector3(bullet.sprite.vector, 0) - Vector3.Transform(new Vector3(bullet.origin, 0), Matrix.CreateRotationZ(bullet.rotation));
                    sprite.Up       = new Vector3(0, 0, bullet.rotation);
                    sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
                }
            }

            if (inTwoPlayer)
            {
                foreach (Player player in players)
                {
                    DrawPlayer(player, Content, quadDrawer, cameraPosition, view, projection, groundTransform);
                }
            }
            else
            {
                DrawPlayer(players[0], Content, quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Solid solid in level.foreSolids)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = solid.sprite.getTexture();
                sprite.Position = new Vector3(solid.sprite.vector.X, solid.sprite.vector.Y, 0);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
            }

            foreach (Particle particle in level.bloodParticles)
            {
                _3DSprite sprite = new _3DSprite();
                sprite.Texture  = particle.sprite.getTintedTexture();
                sprite.Position = new Vector3(particle.sprite.vector.X, particle.sprite.vector.Y, particle.posZ);
                //six sided drawing
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform);
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform * Matrix.CreateRotationX(MathHelper.PiOver2));
                sprite.Draw(quadDrawer, cameraPosition, view, projection, groundTransform * Matrix.CreateRotationY(MathHelper.PiOver2));
            }
        }
示例#3
0
 /// <summary>
 /// Draws the entity as a billboard sprite.
 /// </summary>
 public void Draw(QuadDrawer quadDrawer, Vector3 cameraPosition,
                  Matrix view, Matrix projection)
 {
     quadDrawer.DrawQuad(Texture, 1, Matrix.Identity, view, projection);
 }