/// <summary>
 /// Draw all projectiles
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique, 
     Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // draw all projectiles
     foreach(Projectile p in projectiles)
         p.Draw(game, gd, technique, cameraPosition, viewProjection, lights);
 }
Beispiel #2
0
        /// <summary>
        /// Draw powerup
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd, 
            RenderTechnique technique, Vector3 cameraPosition,
            Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            // if now waiting to respawn
            if (waitTime == 0)
            {
                // draw powerup model
                game.DrawModel(gd, model, technique, cameraPosition,
                    bobbing * transform, viewProjection, lights);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Draw projectile
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd,
            RenderTechnique defaultTechnique, Vector3 cameraPosition,
            Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            if (technique == RenderTechnique.ViewMapping)
            {
                game.DrawModel(gd, model, technique,
                        cameraPosition, transform, viewProjection, null);
            }
            else
            {
                game.DrawModel(gd, model, defaultTechnique,
                        cameraPosition, transform, viewProjection, lights);
            }
        }
Beispiel #4
0
        // called before screen shows
        public override void SetFocus(ContentManager content, bool focus)
        {
            // if getting focus
            if (focus == true)
            {
                // load all resources
                confirmed[0] = false;
                confirmed[1] = (gameManager.GameMode == GameMode.SinglePlayer);

                rotation[0] = Matrix.Identity;
                rotation[1] = Matrix.Identity;

                lights = LightList.Load("content/screens/player_lights.xml");

                for (int i = 0; i < NumberShips; i++)
                {
                    shipModels[i] = content.Load<Model>(
                                            "ships/" + ships[i]);
                    FixupShip(shipModels[i], "ships/" + ships[i]);
                }

                padModel = content.Load<Model>("ships/pad");
                padHaloModel = content.Load<Model>("ships/pad_halo");
                padSelectModel = content.Load<Model>("ships/pad_select");

                textureChangeShip = content.Load<Texture2D>(
                                            "screens/change_ship");
                textureRotateShip = content.Load<Texture2D>(
                                            "screens/rotate_ship");
                textureSelectBack = content.Load<Texture2D>(
                                            "screens/select_back");
                textureSelectCancel = content.Load<Texture2D>(
                                            "screens/select_cancel");
                textureInvertYCheck = content.Load<Texture2D>(
                                            "screens/inverty_check");
                textureInvertYUncheck = content.Load<Texture2D>(
                                            "screens/inverty_uncheck");
            }
            else // loosing focus
            {
                // free all resources
                lights = null;

                for (int i = 0; i < NumberShips; i++)
                    shipModels[i] = null;

                padModel = null;
                padHaloModel = null;
                padSelectModel = null;

                textureChangeShip = null;
                textureRotateShip = null;
                textureSelectBack = null;
                textureSelectCancel = null;
                textureInvertYCheck = null;
                textureInvertYUncheck = null;
            }
        }
Beispiel #5
0
        // called before screen shows
        public override void SetFocus(ContentManager content, bool focus)
        {
            // if getting focus
            if (focus)
            {
                // load all resources
                int winner = gameManager.PlayerWinner;

                shipModel = content.Load<Model>("ships/" +
                                gameManager.GetPlayerShip(winner));

                padModel = content.Load<Model>("ships/pad");
                padHaloModel = content.Load<Model>("ships/pad_halo");

                lights = LightList.Load("content/screens/end_lights.xml");

                textureContinue = content.Load<Texture2D>("screens/continue");
                if (winner == 0)
                    texturePlayerWin = content.Load<Texture2D>(
                                            "screens/player1_wins");
                else
                    texturePlayerWin = content.Load<Texture2D>(
                                            "screens/player2_wins");
            }
            else // loosing focus
            {
                // free all resources
                shipModel = null;
                padModel = null;
                padHaloModel = null;

                lights = null;

                textureContinue = null;
                texturePlayerWin = null;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Unload game files
        /// </summary>
        public void UnloadFiles()
        {
            // unload level
            levelColor = null;
            levelCollision = null;
            levelSpawns = null;
            levelLights = null;

            // unload poasticles
            particleTextures = null;
            // unload animated sprites
            animatedSpriteTextures = null;
            // unload projectiles
            projectileModels = null;
            // unload powerups
            powerupModels = null;

            // unload players
            for (int i = 0; i < GameOptions.MaxPlayers; i++)
            {
                // must displose player so that it releases its effects
                if (players[i] != null)
                    players[i].Dispose();
                players[i] = null;
            }

            // unload hud
            hudCrosshair = null;
            hudEnergy = null;
            hudMissile = null;
            hudScore = null;
            hudBars = null;

            // unload damage texture
            damageTexture = null;

            // unload powerups
            powerup.Clear();
        }
Beispiel #7
0
        /// <summary>
        /// Load the game files (level, ships, wepons, etc...)
        /// </summary>
        public void LoadFiles(ContentManager content)
        {
            String level = levelFile + "/" + levelFile;

            // load level model
            levelColor = content.Load<Model>("levels/" + level);

            // load collision model
            Model collisionModel = content.Load<Model>(
                                        "levels/" + level + "_collision");
            levelCollision = new CollisionMesh(collisionModel,
                                        GameOptions.CollisionMeshSubdivisions);
            collisionModel = null;

            // load spawns and lights
            levelSpawns = EntityList.Load("content/levels/" + level + "_spawns.xml");
            levelLights = LightList.Load("content/levels/" + level + "_lights.xml");

            // load particle textures
            if (particleTextures == null)
            {
                int i, j = particleFiles.GetLength(0);
                particleTextures = new Texture2D[j];
                for (i = 0; i < j; i++)
                    particleTextures[i] = content.Load<Texture2D>(
                            "particles/" + particleFiles[i]);
            }

            // load animated sprite textures
            if (animatedSpriteTextures == null)
            {
                int i, j = animatedSpriteFiles.GetLength(0);
                animatedSpriteTextures = new Texture2D[j];
                for (i = 0; i < j; i++)
                    animatedSpriteTextures[i] = content.Load<Texture2D>(
                            "explosions/" + animatedSpriteFiles[i]);
            }

            // load projectile models
            if (projectileModels == null)
            {
                int i, j = projectileFiles.GetLength(0);
                projectileModels = new Model[j];
                for (i = 0; i < j; i++)
                    projectileModels[i] = content.Load<Model>(
                            "projectiles/" + projectileFiles[i]);
            }

            // load powerup models
            if (powerupModels == null)
            {
                int i, j = powerupFiles.GetLength(0);
                powerupModels = new Model[j];
                for (i = 0; i < j; i++)
                    powerupModels[i] = content.Load<Model>(
                            "powerups/" + powerupFiles[i]);
            }

            // cerate players
            for (int i = 0; i < GameOptions.MaxPlayers; i++)
                if (shipFile[i] != null)
                {
                    Model ShipModel = content.Load<Model>(
                            "ships/" + shipFile[i]);

                    EntityList ShipEnities = EntityList.Load(
                            "content/ships/" + shipFile[i] + ".xml");

                    players[i] = new PlayerShip(this, i,
                        ShipModel, ShipEnities, GameOptions.CollisionBoxRadius);
                }
                else
                    players[i] = null;

            // create powerups
            EntityList powerups = EntityList.Load(
                            "content/levels/" + level + "_powerups.xml");

            foreach (Entity entity in powerups.Entities)
            {
                switch (entity.name)
                {
                    case "energy":
                        AddPowerup(PowerupType.Energy, entity.transform);
                        break;
                    case "missile":
                        AddPowerup(PowerupType.Missile, entity.transform);
                        break;
                }
            }

            // load hud textures
            if (gameMode == GameMode.SinglePlayer)
            {
                hudCrosshair = content.Load<Texture2D>(
                                    "screens/hud_sp_crosshair");
                hudEnergy = content.Load<Texture2D>(
                                    "screens/hud_sp_energy");
                hudMissile = content.Load<Texture2D>(
                                    "screens/hud_sp_missile");
                hudScore = content.Load<Texture2D>(
                                    "screens/hud_sp_score");
                hudBars = content.Load<Texture2D>(
                                    "screens/hud_sp_bars");
            }
            else
            {
                hudCrosshair = content.Load<Texture2D>(
                                    "screens/hud_mp_crosshair");
                hudEnergy = content.Load<Texture2D>(
                                    "screens/hud_mp_energy");
                hudMissile = content.Load<Texture2D>(
                                    "screens/hud_mp_missile");
                hudScore = content.Load<Texture2D>(
                                    "screens/hud_mp_score");
                hudBars = content.Load<Texture2D>(
                                    "screens/hud_mp_bars");
            }

            // load damage indicator texture
            damageTexture = content.Load<Texture2D>("screens/damage");
        }
Beispiel #8
0
        /// <summary>
        /// Draw a model using given technique and camera settings

#endregion


        /// </summary>
        public void DrawModel(GraphicsDevice gd, Model model,
            RenderTechnique technique, Vector3 cameraPosition,
            Matrix world, Matrix viewProjection, LightList lights)
        {


            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            // get model bones
            model.CopyAbsoluteBoneTransformsTo(bones);

            BlendState bs = gd.BlendState;
            DepthStencilState ds = gd.DepthStencilState;

            gd.DepthStencilState = DepthStencilState.DepthRead;
            gd.BlendState = BlendState.Additive;


            // for each mesh in model
            foreach (ModelMesh mesh in model.Meshes)
            {
                // get mesh world matrix
                Matrix worldBone = bones[mesh.ParentBone.Index] * world;
                Matrix worldBoneInverse = Matrix.Invert(worldBone);

                // compute camera position in object space
                Vector3 cameraObjectSpace = cameraPosition - worldBone.Translation;
                cameraObjectSpace = Vector3.TransformNormal(cameraObjectSpace,
                                                        worldBoneInverse);

                gd.SamplerStates[0] = SamplerState.LinearWrap;

                // for each mesh part
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    // if primitives to render
                    if (meshPart.PrimitiveCount > 0)
                    {
                        // setup vertices and indices
                        gd.SetVertexBuffer(meshPart.VertexBuffer);
                        gd.Indices = meshPart.IndexBuffer;

                        // setup effect
                        Effect effect = meshPart.Effect;
                        effect.Parameters["WorldViewProj"].SetValue(worldBone * viewProjection);
                        effect.Parameters["CameraPosition"].SetValue(cameraObjectSpace);

                        // setup technique
                        effect.CurrentTechnique =
                            meshPart.Effect.Techniques[(int)technique];


                        // if not lights specified
                        if (lights == null)
                        {
                            // begin effect
                            effect.CurrentTechnique.Passes[0].Apply();
                            // draw with plain mapping
                            gd.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                meshPart.VertexOffset, 0, meshPart.NumVertices,
                                meshPart.StartIndex, meshPart.PrimitiveCount);
                            gd.SetVertexBuffer(null);
                            gd.Indices = null;
                        }
                        else
                        {
                            gd.DepthStencilState = DepthStencilState.Default;
                            gd.BlendState = BlendState.Opaque;

                            // get light effect parameters
                            EffectParameter effectLightPosition =
                                                effect.Parameters[1];
                            EffectParameter effectLightColor =
                                                effect.Parameters[2];
                            EffectParameter effectLightAmbient =
                                                effect.Parameters[3];

                            // ambient light
                            Vector3 ambient = lights.ambient;

                            // for each light
                            foreach (Light light in lights.lights)
                            {
                                // setup light in effect
                                effectLightAmbient.SetValue(ambient);
                                light.SetEffect(effectLightPosition,
                                    effectLightColor, worldBoneInverse);

                                // begin effect
                                effect.CurrentTechnique.Passes[0].Apply();
                                // draw primitives
                                gd.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                    meshPart.VertexOffset, 0, meshPart.NumVertices,
                                    meshPart.StartIndex, meshPart.PrimitiveCount);

                                // setup additive blending with no depth write
                                gd.DepthStencilState = DepthStencilState.DepthRead;
                                gd.BlendState = BlendState.Additive;

                                // clear ambinet light (applied in first pass only)
                                ambient = Vector3.Zero;
                            }

                            // clear vertices and indices
                            gd.SetVertexBuffer(null);
                            gd.Indices = null;

                        }

                    }
                }
            }
            gd.DepthStencilState = ds;
            gd.BlendState = bs;
        }
Beispiel #9
0
 /// <summary>
 /// Draw a projectile
 /// </summary>
 public void DrawProjectile(GraphicsDevice gd, ProjectileType p,
     RenderTechnique technique, Vector3 cameraPosition,
     Matrix world, Matrix viewProjection, LightList lights)
 {
     DrawModel(gd, projectileModels[(int)p], technique,
         cameraPosition, world, viewProjection, lights);
 }
Beispiel #10
0
 /// <summary>
 /// Renders the player ship model and 
 /// blaster and missile if available and charged
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique, 
     Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // if not dead
     if (deadTime == 0.0f)
     {
         // render ship model
         gameManager.DrawModel(gd, shipModel, technique, cameraPosition,
             bobbing * transform, viewProjection, lights);
     }
 }