Exemple #1
0
        public EGameState Update(GameTime time)
        {
            if (!character.sprite.Intersects(mapRectangle))
            {
                return(EGameState.Lost);
            }

            character.Update(time);

            enemyHandler.Update(time);

            if (!enemyHandler.BossIsStillAlive)
            {
                return(EGameState.Won);
            }

            List <Character> c = enemyHandler.List;

            c.Add(character);

            BulletsEverywhere.Update(time, map, c);

            character.Collide(map);

            enemyHandler.Collide(map);

            camera.Position = character.collision.Center.ToVector2();
            camera.SetVisibilityContainedIn(mapRectangle);

            effect.Parameters["Time"].SetValue((float)time.TotalGameTime.TotalSeconds);
            if (character.dead)
            {
                return(EGameState.Lost);
            }

            return(EGameState.InGame);
        }
Exemple #2
0
 public override void Update(double deltaTime)
 {
     _enemyHandler.Update(deltaTime);
 }
Exemple #3
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            CheckIfGameOver();

            pressTimerPrimary     -= gameTime.ElapsedGameTime.Milliseconds * 2;
            pressTimerSecondary   -= gameTime.ElapsedGameTime.Milliseconds;
            pressTimerSpellBrowse -= gameTime.ElapsedGameTime.Milliseconds;
            drinkPotionTimer      -= gameTime.ElapsedGameTime.Milliseconds;

            GamePadState  playerState = GamePad.GetState(player.PlayerIndexSaved);
            KeyboardState keyboard    = Keyboard.GetState();

            cameraZoom += playerState.ThumbSticks.Right.Y / 50.0f;
            if (cameraZoom <= 0.2f)
            {
                cameraZoom = 0.2f;
            }

            if (cameraZoom >= 1.76f)
            {
                cameraZoom = 1.76f;
            }


            camera.Position = new Vector3(0 * cameraZoom, 1688.753f * cameraZoom, -2228.385f);

            // Browse spells to the right
            if ((playerState.Buttons.RightShoulder == ButtonState.Pressed || keyboard.IsKeyDown(Keys.D)) && pressTimerSpellBrowse < 0)
            {
                int ss = (int)spellHandler.SelectedSpellIndex;
                if (ss < spellHandler.LearnedSpells.Count - 1)
                {
                    spellHandler.SelectedSpellIndex++;
                    spellHandler.SelectedSpell = spellHandler.LearnedSpells[spellHandler.SelectedSpellIndex];
                }
                pressTimerSpellBrowse = 100;
            }

            // Browse spells to the left
            if ((playerState.Buttons.LeftShoulder == ButtonState.Pressed || keyboard.IsKeyDown(Keys.A)) && pressTimerSpellBrowse < 0)
            {
                int ss = (int)spellHandler.SelectedSpellIndex;
                if (ss > 0)
                {
                    spellHandler.SelectedSpellIndex--;
                    spellHandler.SelectedSpell = spellHandler.LearnedSpells[spellHandler.SelectedSpellIndex];
                }
                pressTimerSpellBrowse = 100;
            }

            // Shoot primary spell
            if ((playerState.Buttons.X == ButtonState.Pressed || keyboard.IsKeyDown(Keys.LeftControl)) && pressTimerPrimary < 0)
            {
                int manaCost = spellHandler.GetManaCost(GameObjects.SpellHandler.Spells.Fireball);
                if (player.Mana >= manaCost)
                {
                    pressTimerPrimary = player.CalculateSpellRecharge();
                    spellHandler.AddSpell(player.Position, GameObjects.SpellHandler.Spells.Fireball, Vector3.Zero);
                    player.Mana -= manaCost;
                    player.PlayAnimation(3);

                    //shootCue = soundBank.GetCue("shoot");
                    //if (!shootCue.IsPlaying)
                    //{
                    //    shootCue.Play();
                    //}
                }
            }

            // Shoot secondary spell
            if ((playerState.Buttons.A == ButtonState.Pressed || keyboard.IsKeyDown(Keys.LeftAlt)) && pressTimerSecondary < 0)
            {
                int manaCost = spellHandler.GetManaCost(spellHandler.SelectedSpell);
                if (player.Mana >= manaCost)
                {
                    //shootCue = soundBank.GetCue("shoot");
                    //if (!shootCue.IsPlaying)
                    //{
                    //    shootCue.Play();
                    //}

                    pressTimerSecondary = player.CalculateSpellRecharge();
                    if (enemyHandler.EnemiesList.Count > 0)
                    {
                        Random rndEnemyOnScreen = new Random();
                        if (spellHandler.SelectedSpell == SpellHandler.Spells.MagicMissileX2 || spellHandler.SelectedSpell == SpellHandler.Spells.MagicMissileX4)
                        {
                            spellHandler.AddSpell(player.Position, SpellHandler.Spells.MagicMissile, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                        }
                        else
                        {
                            spellHandler.AddSpell(player.Position, spellHandler.SelectedSpell, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                        }

                        // some special rules regarding some spells are defined under here
                        if (spellHandler.SelectedSpell == SpellHandler.Spells.MagicMissileX2)
                        {
                            spellHandler.AddSpell(player.Position, SpellHandler.Spells.MagicMissile, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                        }

                        if (spellHandler.SelectedSpell == MageDefenderDeluxe.GameObjects.SpellHandler.Spells.MagicMissileX4)
                        {
                            spellHandler.AddSpell(player.Position, SpellHandler.Spells.MagicMissile, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                            spellHandler.AddSpell(player.Position, SpellHandler.Spells.MagicMissile, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                            spellHandler.AddSpell(player.Position, SpellHandler.Spells.MagicMissile, enemyHandler.EnemiesList[rndEnemyOnScreen.Next(0, enemyHandler.EnemiesList.Count)].Position);
                        }
                    }
                    else
                    {
                        spellHandler.AddSpell(player.Position, spellHandler.SelectedSpell, new Vector3(player.Position.X, 300, player.Position.Z));
                    }

                    player.Mana -= manaCost;
                    player.PlayAnimation(3);
                }
            }

            // Drink a health potion
            if ((playerState.Buttons.B == ButtonState.Pressed || keyboard.IsKeyDown(Keys.W)) && drinkPotionTimer < 0)
            {
                if (player.HealthPotions > 0)
                {
                    drinkPotionTimer      = 1000;
                    player.HealthPotions -= 1;
                    player.Health        += 50 + (player.Strength * 5);
                    if (player.Health >= player.MaxHealth)
                    {
                        player.Health = player.MaxHealth;
                    }
                }
            }

            // Drink a mana potion
            if ((playerState.Buttons.Y == ButtonState.Pressed || keyboard.IsKeyDown(Keys.S)) && drinkPotionTimer < 0)
            {
                if (player.ManaPotions > 0)
                {
                    drinkPotionTimer    = 1000;
                    player.ManaPotions -= 1;
                    player.Mana        += 50 + (player.Constitution * 5);
                    if (player.Mana >= player.MaxMana)
                    {
                        player.Mana = player.MaxMana;
                    }
                }
            }

            enemyHandler.IsCollidingWithSpell(spellHandler);
            enemyHandler.IsCollidingWithPlayer(player.Position);

            scenery.Update(gameTime);
            player.Update(gameTime);
            castleHandler.Update(gameTime);
            camera.Update(gameTime);
            spellHandler.Update(gameTime, playerState.ThumbSticks.Right.X);
            enemyHandler.Update(gameTime);


            // Set proj and view matrix on particles
            fireBallParticles.SetCamera(camera.ViewMatrix, camera.ProjectionMatrix);
            slowEnemyParticles.SetCamera(camera.ViewMatrix, camera.ProjectionMatrix);
            poisonEnemyParticles.SetCamera(camera.ViewMatrix, camera.ProjectionMatrix);
            magicMissilePartilces.SetCamera(camera.ViewMatrix, camera.ProjectionMatrix);
            dirtPartilces.SetCamera(camera.ViewMatrix, camera.ProjectionMatrix);

            if (player.Position.X < -1200)
            {
                for (int i = 0; i < 2; i++)
                {
                    magicMissilePartilces.AddParticle(new Vector3(player.Position.X * 0.008f, player.Position.Y * 0.008f, player.Position.Z * 0.008f), Vector3.Zero);
                }
            }
            else
            {
                for (int i = 0; i < 1; i++)
                {
                    dirtPartilces.AddParticle(new Vector3(player.Position.X * 0.008f, player.Position.Y * 0.008f, player.Position.Z * 0.008f), Vector3.Zero);
                }
            }

            // Update particles
            poisonEnemyParticles.Update(gameTime);
            slowEnemyParticles.Update(gameTime);
            fireBallParticles.Update(gameTime);
            magicMissilePartilces.Update(gameTime);
            dirtPartilces.Update(gameTime);


            if (enemyHandler.AllEnemiesDead && enemyHandler.WaveFinishedTimer < 0)
            {
                // Hardcode some storymode

                // If the level you completed was 6, go to undead mode
                if (castleHandler.Castle.Level == 6)
                {
                    castleHandler.Castle.StoryStage = 2;
                    NextState = (int)MageDefenderStates.Story;
                }
                // If the level you completed was 12, go to XXX mode
                else if (castleHandler.Castle.Level == 12)
                {
                    NextState = (int)MageDefenderStates.Story;
                }
                else
                {
                    NextState = (int)MageDefenderStates.Shop;
                }

                ChangeState = true;

                PrepareNextLevel();
            }



            base.Update(gameTime);
        }