コード例 #1
0
        /// <summary>
        /// Zeichnet das Mutterschiff auf den Bildschirm
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch zum Zeichnen</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            Vector3 currentPosition = PlaneProjector.Convert2DTo3D(GameItem.Position);

            //Bei jeder Bewegung wird die Worldmatrix neu gesetzt und die Hitsphere angepasst.
            if (currentPosition.X > this.lastPosition.X || currentPosition.X < this.lastPosition.X)
            {
                this.World = Matrix.CreateWorld(currentPosition, Vector3.Right, Vector3.Up);
                ((ModelHitsphere)GameItem.BoundingVolume).World = World;
                this.lastPosition = currentPosition;
            }

            //[Anji]
            mothershipEngine.EmitterLocation = PlaneProjector.ToScreenCoordinates(lastPosition + new Vector3(-45, 0, 0), graphics);
            mothershipEngine.Draw(spriteBatch);

            /*
             * WICHTIG!
             * Zurücksetzen des DepthStencils um eine fehlerfreie Kombination von 2D-Sprite und 3D-Model
             * zeichnen zu können.
             * */
            this.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.LightingEnabled = true;
                    effect.SpecularColor   = new Vector3(1.0f, 1.0f, 1.0f);
                    effect.SpecularPower   = 100.0f;
                    effect.DiffuseColor    = new Vector3(1.0f, 1.0f, 1.0f);
                    effect.Texture         = this.mothershipTexture;
                    effect.World           = this.World;
                    effect.View            = Camera;
                    effect.Projection      = Projection;
                }

                mesh.Draw();
            }
        }
コード例 #2
0
        /// <summary>
        /// Zeichnet das PowerUp.
        /// </summary>
        /// <param name="spriteBatch">spriteBatch</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            this.angle += rotationSpeed;

            Vector3 currentPosition = PlaneProjector.Convert2DTo3D(GameItem.Position);
            Matrix  rotation        = Matrix.CreateRotationZ(MathHelper.ToRadians(this.angle));

            this.World = rotation * Matrix.CreateWorld(currentPosition, Vector3.Backward, Vector3.Up);

            //Setzen der Hitsphere
            ((ModelHitsphere)GameItem.BoundingVolume).World = this.World;

            //DephStencilState setzen damit 3D und 2D Objekte gleichzeitig richtig angezeigt werden können
            this.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.LightingEnabled = true;
                    effect.SpecularColor   = new Vector3(1.0f, 1.0f, 1.0f);
                    effect.SpecularPower   = 100.0f;
                    effect.DiffuseColor    = new Vector3(1.0f, 1.0f, 1.0f);
                    effect.Texture         = this.texture;
                    effect.View            = Camera;
                    effect.Projection      = Projection;
                    effect.World           = this.World;
                }

                mesh.Draw();
            }

            //Glitter
            powerUpGlitter.EmitterLocation = PlaneProjector.ToScreenCoordinates(currentPosition, graphics);
            powerUpGlitter.Draw(spriteBatch);
        }
コード例 #3
0
        /// <summary>
        /// Zeichnet das Spielerschiff auf den Bildschirm.
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch zum Zeichnen</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            Vector3 currentPosition = PlaneProjector.Convert2DTo3D(GameItem.Position);
            Matrix  rotation        = Matrix.Identity;

            //[Anji] ShipEngine
            playerShipEngine.EmitterLocation = PlaneProjector.ToScreenCoordinates(lastPosition + new Vector3(0, 0, 45), graphics);
            playerShipEngine.Draw(spriteBatch);

            bool invincible = ((Player)this.GameItem).IsInvincible;

            if (invincible)
            {
                if (this.invincibleCount > 8)
                {
                    this.invincibleCount = 0;
                }
                this.invincibleCount++;
            }

            //Je nach Bewegungsrichtung des Spielers wird das Schiff in die entsprechende Richtung geneigt.
            if (currentPosition.X > this.lastPosition.X)
            {
                this.World        = Matrix.CreateWorld(currentPosition, Vector3.Forward, Vector3.Up);
                rotation          = Matrix.CreateRotationZ(MathHelper.ToRadians(-25));
                this.lastPosition = currentPosition;
            }
            else if (currentPosition.X < this.lastPosition.X)
            {
                this.World        = Matrix.CreateWorld(currentPosition, Vector3.Forward, Vector3.Up);
                rotation          = Matrix.CreateRotationZ(MathHelper.ToRadians(25));
                this.lastPosition = currentPosition;
            }
            ((ModelHitsphere)GameItem.BoundingVolume).World = this.World;


            /*
             * WICHTIG!
             * Zurücksetzen des DepthStencils um eine fehlerfreie Kombination von 2D-Sprite und 3D-Model
             * zeichnen zu können.
             * */
            this.graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            if (invincible && this.invincibleCount == 8)
            {
            }
            else
            {
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.LightingEnabled = true;
                        effect.SpecularColor   = new Vector3(1.0f, 1.0f, 1.0f);
                        effect.SpecularPower   = 100.0f;
                        effect.DiffuseColor    = new Vector3(1.0f, 1.0f, 1.0f);
                        effect.Texture         = this.playerTexture;
                        effect.View            = Camera;
                        effect.Projection      = Projection;
                        effect.World           = rotation * this.World;
                        //[Anji] Schifftextur ändern wenn Schild-PowerUp aktiv
                        if (GameItem.Hitpoints > GameItemConstants.PlayerHitpoints)
                        {
                            effect.Texture = this.shieldTexture;
                        }
                    }

                    mesh.Draw();
                }
            }
        }
コード例 #4
0
        /*
         * <WAHL>
         * Wird benötigt wenn eine Partikel Engine eingebaut wird.
         * private Explosion explosion;
         * */

        /// <summary>
        /// Erstellt eine Representation der Spielerfigur.
        /// </summary>
        public PlayerRepresentation(Player playerGameItem, GraphicsDeviceManager graphics)
        {
            this.graphics        = graphics;
            this.model           = ViewContent.RepresentationContent.PlayerModel;
            GameItem             = playerGameItem;
            this.playerTexture   = ViewContent.RepresentationContent.PlayerTexture;
            this.shieldTexture   = ViewContent.RepresentationContent.ShipShieldTexture;
            this.lastPosition    = PlaneProjector.Convert2DTo3D(GameItem.Position);
            this.World           = Matrix.CreateWorld(this.lastPosition, Vector3.Forward, Vector3.Up);
            this.invincibleCount = 0;

            //[Anji] Schiffs-Antrieb
            this.playerShipEngine = (PlayerShipEngine)createParticleEngine(ViewContent.RepresentationContent.ShipEngineTexture, PlaneProjector.ToScreenCoordinates(lastPosition, graphics), 0.5f, Color.LightBlue); //new Color(190,195,217));
        }
コード例 #5
0
        /// <summary>
        /// Erstellt eine Representation eines PowerUps.
        /// <param name="graphics">GraphicsDeviceManager</param>
        /// <param name="powerUp">übergebenes PowerUp-Objekt</param>
        /// <param name="texture">Textur des PowerUps</param>
        /// </summary>
        public PowerUpRepresentation(PowerUp powerUp, Texture2D texture, Color color, GraphicsDeviceManager graphics)
        {
            GameItem      = powerUp;
            this.texture  = texture;
            this.model    = ViewContent.RepresentationContent.PowerUp;
            this.position = PlaneProjector.Convert2DTo3D(GameItem.Position);
            this.graphics = graphics;

            //Winkel in °
            this.angle         = 0.0f;
            this.rotationSpeed = 1.0f;
            this.World         = Matrix.CreateWorld(this.position, Vector3.Forward, Vector3.Up);

            this.powerUpGlitter = (PowerUpGlitter)createParticleEngine(ViewContent.RepresentationContent.GlitterTexture, PlaneProjector.ToScreenCoordinates(position, graphics), 0.2f, color);
            this.color          = color;
        }
コード例 #6
0
        /*
         * <WAHL>
         * Wird benötigt falls eine Partikel Engine eingebaut wird
         * private Explosion explosion;
         * */


        /// <summary>
        /// Erstellt eine Representation des Mutterschiff-Aliens.
        /// </summary>
        public MothershipRepresentation(Mothership mothershipGameItem, GraphicsDeviceManager graphics)
        {
            this.graphics          = graphics;
            this.model             = ViewContent.RepresentationContent.MothershipModel;
            GameItem               = mothershipGameItem;
            this.mothershipTexture = ViewContent.RepresentationContent.MothershipTexture;
            this.lastPosition      = PlaneProjector.Convert2DTo3D(GameItem.Position);
            this.World             = Matrix.CreateWorld(lastPosition, Vector3.Right, Vector3.Up);

            //[Anji] Schiffs-Antrieb
            this.mothershipEngine = (MothershipEngine)createParticleEngine(ViewContent.RepresentationContent.MothershipEngineTexture, PlaneProjector.ToScreenCoordinates(lastPosition, graphics), 1f, new Color(255, 96, 167));
        }