Exemplo n.º 1
0
        /// <summary>
        /// Create a new projetcile manager
        /// </summary>
        public ProjectileManager(GameManager game)
        {
            this.game = game;

            projectiles = new LinkedList<Projectile>();
            deleteProjectiles = new List<LinkedListNode<Projectile>>();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new powerup manager
        /// </summary>
        public PowerupManager(GameManager game)
        {
            this.game = game;

            powerups = new LinkedList<Powerup>();
            deletePowerups = new List<LinkedListNode<Powerup>>();
        }
Exemplo n.º 3
0
        // collision box radius
        /// <summary>
        /// Create a new player ship
        /// </summary>
        public PlayerShip(
            GameManager game,        // game manager
            int player,              // player id
            Model model,             // model for player ship
            EntityList entities,     // entity list for ship model
            float radius)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }
            if (entities == null)
            {
                throw new ArgumentNullException("entities");
            }

            // save parameters
            gameManager = game;
            shipModel = model;
            shipEntities = entities;
            playerIndex = player;

            // create movement controller
            movement = new PlayerMovement();
            movement.maxVelocity = GameOptions.MovementVelocity;

            // enable collision sound
            collisionSound = true;

            // create engine particle system with infinite life time
            particleBoost = gameManager.AddParticleSystem(
                                                ParticleSystemType.ShipTrail,
                                                transform);
            particleBoost.SetTotalTime(1e10f);
            boostTransform = shipEntities.GetTransform("engine");

            // create the ship collision box
            box = new CollisionBox(-radius, radius);

            // random bobbing offset
            random = new Random(player);
            bobbingTime = (float)random.NextDouble();

            // setup 3rd person camera parameters
            camera3rdPerson = false;
            chaseCamera = new ChaseCamera();
            chaseCamera.DesiredPositionOffset = GameOptions.CameraOffset;
            chaseCamera.LookAtOffset = GameOptions.CameraTargetOffset;
            chaseCamera.Stiffness = GameOptions.CameraStiffness;
            chaseCamera.Damping = GameOptions.CameraDamping;
            chaseCamera.Mass = GameOptions.CameraMass;
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public ShipGameGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            audioEngine = new AudioEngine("content/sounds/sounds.xgs");
            waveBank = new WaveBank(audioEngine, "content/sounds/Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, "content/sounds/Sound Bank.xsb");
            
            game = new GameManager(soundBank);

            graphics.PreferredBackBufferWidth = GameOptions.ScreenWidth;
            graphics.PreferredBackBufferHeight = GameOptions.ScreenHeight;

            //graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
            //graphics.MinimumVertexShaderProfile = ShaderProfile.VS_1_1;

            IsFixedTimeStep = renderVsync;
            graphics.SynchronizeWithVerticalRetrace = renderVsync;
        }
Exemplo n.º 7
0
        float backgroundTime = 0.0f;  // time for background animation used on menus

        // constructor
        public ScreenManager(ShipGameGame shipGame, FontManager font, GameManager game)
        {
            this.shipGame = shipGame;
            gameManager = game;
            fontManager = font;

            screens = new List<Screen>();
            inputManager = new InputManager();

            // add all screens
            screens.Add(new ScreenIntro(this, game));
            screens.Add(new ScreenHelp(this, game));
            screens.Add(new ScreenPlayer(this, game));
            screens.Add(new ScreenLevel(this, game));
            screens.Add(new ScreenGame(this, game));
            screens.Add(new ScreenEnd(this, game));

            // fade in to intro screen
            SetNextScreen(ScreenType.ScreenIntro,
                GameOptions.FadeColor, GameOptions.FadeTime);
            fade = fadeTime * 0.5f;
        }
Exemplo n.º 8
0
 // constructor
 public ScreenLevel(ScreenManager manager, GameManager game)
 {
     screenManager = manager;
     gameManager = game;
 }
Exemplo n.º 9
0
        Texture2D textureSelectCancel; // select and cancel texture

        #endregion Fields

        #region Constructors

        // constructor
        public ScreenPlayer(ScreenManager manager, GameManager game)
        {
            screenManager = manager;
            gameManager = game;
        }
Exemplo n.º 10
0
        Texture2D texturePlayerWin; // texture with winning player number

        #endregion Fields

        #region Constructors

        // constructor
        public ScreenEnd(ScreenManager manager, GameManager game)
        {
            screenManager = manager;
            gameManager = game;
        }
Exemplo n.º 11
0
 // constructor
 public ScreenIntro(ScreenManager manager, GameManager game)
 {
     screenManager = manager;
     gameManager = game;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Update projectile
        /// </summary>
        public bool Update(float elapsedTime, GameManager game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            // add elapsed time for this frame
            this.elapsedTime += elapsedTime;

            // normalize time
            float normalizedTime = Math.Min(1.0f, this.elapsedTime / totalTime);

            // compute current projectile position
            Vector3 position = Vector3.Lerp(sourcePosition, destinationPosition,
                normalizedTime);

            // set postion into projectile transform matrix
            transform.Translation = position;

            // if projectile includes a particle system update its position
            if (system != null)
                system.SetTransform(systemTransform * transform);

            // check if projectile hit any player
            int playerHit = game.GetPlayerAtPosition(position);

            // if a player is hit or reached destination explode projectile
            if ((playerHit != player && playerHit != -1) ||
                normalizedTime == 1.0f)
            {
                // compute explosion position moving hit point into hit normal direction
                Vector3 explosionPosition =
                    position + 0.5f * animatedSpriteSize * transform.Backward;

                // set transform to explosion position
                transform.Translation = explosionPosition;

                // if an animated sprite explosion is available, create it
                if (animatedSpriteSize > 0)
                    game.AddAnimSprite(animatedSprite, explosionPosition,
                        animatedSpriteSize, 10.0f, animatedSpriteFrameRate,
                        animatedSpriteDrawMode, -1);

                // if splash damage is available, apply splash damage to nearby players
                if (explosionDamageRadius > 0)
                    game.AddDamageSplash(player, explosionDamage,
                        explosionPosition, explosionDamageRadius);

                // if exploded on a player add contact damage
                if (playerHit != -1 && game.GetPlayer(playerHit).IsAlive)
                    game.AddDamage(player, playerHit, contactDamage,
                        Vector3.Normalize(destinationPosition - sourcePosition));

                // if explosion sound is available, play it
                if (explosionSound != null)
                    game.PlaySound3D(explosionSound, explosionPosition);

                // add explosion particle system
                if (projectileType == ProjectileType.Missile)
                    game.AddParticleSystem(
                                    ParticleSystemType.MissileExplode,
                                    transform);
                else
                if (projectileType == ProjectileType.Blaster)
                    game.AddParticleSystem(
                                    ParticleSystemType.BlasterExplode,
                                    transform);

                // kill trail particle system
                if (system != null)
                    system.SetTotalTime(-1e10f);

                // return false to kill the projectile
                return false;
            }

            // return true to keep projectile alive
            return true;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Update powerup for given elapsed time
        /// </summary>
        public bool Update(GameManager game, float elapsedTime)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            // add elapsed time for this frame
            this.elapsedTime += elapsedTime;

            // if waiting to respawn
            if (waitTime > 0)
            {
                // decrease wait time
                waitTime = Math.Max(0.0f, waitTime - elapsedTime);

                // if wait time is finished
                if (waitTime == 0)
                {
                    // add powerup spawn animated sprite
                    game.AddAnimSprite(AnimSpriteType.Spawn,
                        transform.Translation, 50, 40, 30, DrawMode.Additive, -1);

                    // play powerup spawn sound
                    game.PlaySound3D("powerup_spawn", transform.Translation);
                }

                // return true to keep powerup alive
                return true;
            }

            // calculate bobbing angles
            float turn_angle = (this.elapsedTime * GameOptions.PowerupTurnSpeed) %
                MathHelper.TwoPi;
            float move_angle = (this.elapsedTime * GameOptions.PowerupMoveSpeed) %
                MathHelper.TwoPi;

            // create bobbing matrix
            bobbing = Matrix.CreateRotationY(turn_angle) *
                Matrix.CreateTranslation((float)Math.Cos(move_angle) *
                        GameOptions.PowerupMoveDistance * Vector3.Up);

            // check for any player at the powerup location
            int playerHit = game.GetPlayerAtPosition(transform.Translation);
            if (playerHit != -1)
            {
                // disable powerup until respawn time
                waitTime = GameOptions.PowerupRespawnTime;

                // get player at powerup location
                PlayerShip p = game.GetPlayer(playerHit);
                switch( powerupType )
                {
                    case PowerupType.Energy:
                        p.AddEnergy(0.5f);        // add 50% energy
                        break;
                    case PowerupType.Missile:
                        p.AddMissile(3);        // add 3 missiles
                        break;
                }

                // add powerup spawn animates sprite
                game.AddAnimSprite(AnimSpriteType.Spawn,
                    transform.Translation, 40, 40, 30, DrawMode.Additive, -1);

                // play powerup get sound
                game.PlaySound("powerup_get");
            }

            // return true to keep powerup alive
            return true;
        }