ApplyPowerup() public method

Applies the specified powerup to the ship
public ApplyPowerup ( PowerupType powerup ) : void
powerup PowerupType the indicated powerup
return void
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            LevelManager.Update(elapsedTime);

            GameObjectManager.Update(elapsedTime);

            // Process collisions
            foreach (CollisionPair pair in GameObjectManager.Collisions)
            {
                // Player collisions
                if (pair.A == Player.ID || pair.B == Player.ID)
                {
                    uint       colliderID = (pair.A == Player.ID) ? pair.B : pair.A;
                    GameObject collider   = GameObjectManager.GetObject(colliderID);

                    // Process powerup collisions
                    Powerup powerup = collider as Powerup;
                    if (powerup != null)
                    {
                        Player.ApplyPowerup(powerup.Type);
                        GameObjectManager.DestroyObject(colliderID);
                    }

                    //NOTE: Apply to more than the kamikaze enemy?
                    // Process kamakaze collisions
                    Enemy enemy = collider as Enemy;
                    if (enemy != null && enemy.GetType() == typeof(Kamikaze))
                    {
                        //Player take damage
                        GameObjectManager.DestroyObject(colliderID);
                        GameObjectManager.CreateExplosion(colliderID);
                    }
                }
            }

            base.Update(gameTime);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            player.ApplyPowerup(PowerupType.Fireball);

            // Create a Green Goblin enemy
            GameObjectManager.CreateEnemy(EnemyType.GreenGoblin, new Vector2(200, -150));
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create our viewports
            gameViewport = GraphicsDevice.Viewport;
            worldViewport = new Viewport(0, 0, 768, 720); // Twice as wide as 16 tiles
            guiViewport = new Viewport(768, 0, 512, 720); // Remaining space

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            GameObjectManager = new GameObjectManager(Content);

            // TODO: use this.Content to load your game content here
            MediaPlayer.IsRepeating = true;
            Player = GameObjectManager.CreatePlayerShip(PlayerShipType.Shrike, new Vector2(300, 300));
            Player.ApplyPowerup(PowerupType.Default);
            LevelManager.LoadContent();
            GuiManager.LoadContent();
            SplashType = SplashScreenType.GameStart;
            GameState = GameState.Splash;
            loadSplashScreen(new GameStart());
        }
示例#4
0
        /// <summary>
        /// Helper method for processing gameobject collisions
        /// </summary>
        void ProcessCollisions()
        {
            // Process collisions
            foreach (CollisionPair pair in GameObjectManager.Collisions)
            {
                GameObject objectA = GameObjectManager.GetObject(pair.A);
                GameObject objectB = GameObjectManager.GetObject(pair.B);

                // Player collisions
                if (objectA.ObjectType == ObjectType.Player || objectB.ObjectType == ObjectType.Player)
                {
                    PlayerShip player   = ((objectA.ObjectType == ObjectType.Player) ? objectA : objectB) as PlayerShip;
                    GameObject collider = (objectA.ObjectType == ObjectType.Player) ? objectB : objectA;

                    // Process powerup collisions
                    switch (collider.ObjectType)
                    {
                    case ObjectType.Powerup:
                        Powerup powerup = collider as Powerup;
                        player.ApplyPowerup(powerup.Type);
                        GameObjectManager.DestroyObject(collider.ID);
                        break;

                    case ObjectType.Enemy:
                        Enemy enemy = collider as Enemy;
                        if (enemy.GetType() == typeof(Kamikaze) || enemy.GetType() == typeof(Mandible) ||
                            enemy.GetType() == typeof(SuicideBomber) || enemy.GetType() == typeof(Mine))
                        {
                            //Player take damage
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        break;

                    case ObjectType.EnemyProjectile:
                        Projectile projectile = collider as Projectile;

                        // Damage player
                        player.Health -= projectile.Damage;
                        if (player.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(player.ID);
                            GameObjectManager.CreateExplosion(player.ID);
                        }

                        GameObjectManager.DestroyObject(collider.ID);
                        break;
                    }
                }

                // Player Projectile collisions
                else if (objectA.ObjectType == ObjectType.PlayerProjectile || objectB.ObjectType == ObjectType.PlayerProjectile)
                {
                    Projectile playerProjectile = ((objectA.ObjectType == ObjectType.PlayerProjectile) ? objectA : objectB) as Projectile;
                    GameObject collider         = (objectA.ObjectType == ObjectType.Player) ? objectB : objectA;

                    // Process collisions
                    switch (collider.ObjectType)
                    {
                    case ObjectType.Enemy:
                        Enemy enemy = collider as Enemy;
                        //Enemy take damage
                        enemy.Health -= playerProjectile.Damage;

                        // If health <= 0, kill enemy
                        if (enemy.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        // Destroy projectile
                        // Note, if there are special things for the bullet, add them here
                        GameObjectManager.DestroyObject(playerProjectile.ID);
                        break;

                    case ObjectType.Boss:
                        Boss boss = collider as Boss;
                        // Boss take damage
                        boss.Health -= playerProjectile.Damage;

                        // If health <= 0, kill boss
                        if (boss.Health <= 0)
                        {
                            GameObjectManager.DestroyObject(collider.ID);
                            GameObjectManager.CreateExplosion(collider.ID);
                        }
                        // Destroy projectile
                        // Note, if there are special things for the bullet, add them here
                        GameObjectManager.DestroyObject(playerProjectile.ID);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            player = new ShrikeShip(Content);
            player.ApplyPowerup(Powerups.Fireball);
        }
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     #if TEST
     IsMouseVisible = true;
     #endif
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     // TODO: use this.Content to load your game content here
     player = new ShrikeShip(Content);
     GUIHealthBar hBar1 = new GUIHealthBar(Content, new Vector2(GraphicsDevice.Viewport.Width-10-150,10), 100, 100);
     GUIHealthBar hBar2 = new GUIHealthBar(Content, new Vector2(10, 10), 100, 100);
     gManager.Add(hBar1);
     gManager.Add(hBar2);
     player.ApplyPowerup(Powerups.Fireball);
 }