Esempio n. 1
0
        /// <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)
        {
            inputHelper.Update();
            SoundEffectHelpers soundEffectHelper = new SoundEffectHelpers();


            //Mouse control
            if (Status == status.menu)
            {
                this.IsMouseVisible = true;
            }
            if (Status == status.running || Status == status.winner)
            {
                this.IsMouseVisible = false;
            }
            //Theme song control
            if (inputHelper.IsNewPress(Keys.M))
            {
                if (themeSongLoop.State == SoundState.Playing)
                {
                    themeSongLoop.Pause();
                }
                else
                {
                    themeSongLoop.Play();
                }
            }
            if (Status == status.running)
            {
                //Spawn powerups cheats

                if (inputHelper.IsNewPress(Keys.F9))
                {
                    powerups.Add(new Sprite(cowTexture, type.cow));
                    soundEffectHelper.playSound(cowSoundEffects);
                }
                if (inputHelper.IsNewPress(Keys.F10))
                {
                    powerups.Add(new Sprite(mjod, type.mjod));
                    soundEffectHelper.playSound(beerSoundEffects);
                }
                if (inputHelper.IsNewPress(Keys.F11))
                {
                    powerups.Add(new Sprite(kottbulle, type.kottbulle));
                    soundEffectHelper.playSound(kottbullarSoundEffects);
                }
                if (inputHelper.IsNewPress(Keys.F12))
                {
                    powerups.Add(new Sprite(bomb, type.bomb));
                    soundEffectHelper.playSound(bombSoundEffects);
                }


                //THE ACTUAL GAME UPDATE STUFF

                //Redbeard move
                if (inputHelper.IsCurPress(Keys.W))
                {
                    redbeard.Move(dir.North);
                }
                if (inputHelper.IsCurPress(Keys.A))
                {
                    redbeard.Move(dir.West);
                }
                if (inputHelper.IsCurPress(Keys.S))
                {
                    redbeard.Move(dir.South);
                }
                if (inputHelper.IsCurPress(Keys.D))
                {
                    redbeard.Move(dir.East);
                }

                //Greybeard Move
                if (inputHelper.IsCurPress(Keys.Up))
                {
                    greybeard.Move(dir.North);
                }
                if (inputHelper.IsCurPress(Keys.Left))
                {
                    greybeard.Move(dir.West);
                }
                if (inputHelper.IsCurPress(Keys.Down))
                {
                    greybeard.Move(dir.South);
                }
                if (inputHelper.IsCurPress(Keys.Right))
                {
                    greybeard.Move(dir.East);
                }

                //Attack Buttons
                //redbeard attack


                if (inputHelper.IsNewPress(Keys.V) && redbeard.hitbox.Intersects(greybeard.hitbox))
                {
                    greybeard.Hurt(redbeard.strenght, greybeardHurt);
                    redbeard.DrawAttack();

                    if (hurtSoundEffect.Next(1, 3) == 1)
                    {
                        soundEffectHelper.playSound(hurtSoundEffects);
                    }
                }

                //greybeard attack
                if (inputHelper.IsNewPress(Keys.NumPad2) && greybeard.hitbox.Intersects(redbeard.hitbox))
                {
                    redbeard.Hurt(greybeard.strenght, redbeardHurt);
                    greybeard.DrawAttack();

                    if (hurtSoundEffect.Next(1, 3) == 1)
                    {
                        soundEffectHelper.playSound(hurtSoundEffects);
                    }
                }

                //end Attcks

                //Display winner
                if (redbeard.health < 0)
                {
                    Winner = winner.greybeard; Status = status.winner; soundEffectHelper.playSound(winSoundEffects);
                }
                if (greybeard.health < 0)
                {
                    Winner = winner.redbeard; Status = status.winner; soundEffectHelper.playSound(winSoundEffects);
                }

                // add powerups
                if (powerups == null || powerups.Count < 10)
                {
                    powerup = powerupNumber.Next(0, 1000);

                    if (powerup < 3)
                    {
                        powerups.Add(new Sprite(cowTexture, type.cow));
                        soundEffectHelper.playSound(cowSoundEffects);
                    }
                    if (powerup > 3 && powerup < 9)
                    {
                        powerups.Add(new Sprite(mjod, type.mjod));
                        soundEffectHelper.playSound(beerSoundEffects);
                    }
                    if (powerup > 9 && powerup < 15)
                    {
                        powerups.Add(new Sprite(kottbulle, type.kottbulle));
                        soundEffectHelper.playSound(kottbullarSoundEffects);
                    }
                    if (powerup == 16)
                    {
                        powerups.Add(new Sprite(bomb, type.bomb));
                        soundEffectHelper.playSound(bombSoundEffects);
                    }
                }

                //pick up powerups
                for (int i = 0; i < powerups.Count; ++i)
                {
                    //greybeard

                    if (inputHelper.IsNewPress(Keys.NumPad2) && greybeard.hitbox.Intersects(powerups[i].hitbox))
                    {
                        //check which powerup and apply effect
                        if (powerups[i].type == type.mjod)
                        {
                            greybeard.strenght += 10;
                        }
                        if (powerups[i].type == type.cow)
                        {
                            greybeard.speedBoost     += 3;
                            greybeard.speedBoostTimer = 0;
                        }
                        if (powerups[i].type == type.kottbulle)
                        {
                            greybeard.health += 100;
                        }
                        if (powerups[i].type == type.bomb)
                        {
                            timer = 0;
                        }
                        //remove powerup
                        powerups.Remove(powerups[i]); i = 0;
                    }

                    //redbeard
                    if (inputHelper.IsNewPress(Keys.V) && redbeard.hitbox.Intersects(powerups[i].hitbox))
                    {
                        //check which powerup and apply effect
                        if (powerups[i].type == type.mjod)
                        {
                            redbeard.strenght += 10;
                        }
                        if (powerups[i].type == type.cow)
                        {
                            redbeard.speedBoost     += 3;
                            redbeard.speedBoostTimer = 0;
                        }
                        if (powerups[i].type == type.kottbulle)
                        {
                            redbeard.health += 100;
                        }
                        if (powerups[i].type == type.bomb)
                        {
                            timer = 0;
                        }

                        //remove powerup
                        powerups.Remove(powerups[i]); i = 0;
                    }

                    if (timer < 2001)
                    {
                        timer++;
                    }

                    if (timer == 2000)
                    {
                        kalle.X = powerups[i].hitbox.X - 128;
                        kalle.Y = powerups[i].hitbox.Y - 128;

                        if (greybeard.hitbox.Intersects(kalle))
                        {
                            greybeard.Hurt(100, greybeardHurt);
                        }
                        if (redbeard.hitbox.Intersects(kalle))
                        {
                            redbeard.Hurt(100, redbeardHurt);
                        }

                        kalle.X = -1000;
                        kalle.Y = -1000;
                    }
                }    //end powerups

                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }

                if (inputHelper.IsNewPress(Keys.Escape))
                {
                    Status = status.menu;
                }
            }     //End if running

            //menu
            if (Status == status.menu)
            {
                if (MenuSelected == menuSelected.play)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        Status = status.running;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected += 1;
                    }

                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected += 2;
                    }
                }

                else if (MenuSelected == menuSelected.restart)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        Status = status.running; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); powerups.Clear();
                    }
                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected -= 1;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected += 1;
                    }
                }

                else if (MenuSelected == menuSelected.exit)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        this.Exit();
                    }
                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected -= 1;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected -= 2;
                    }
                }

                //Musgrejor
                MouseState mouseState = Mouse.GetState();
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 300, 300, 100)))
                {
                    Status = status.running;
                }
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 400, 300, 100)))
                {
                    Status = status.running; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); greybeard.Retexture(greybeardWest1); redbeard.Retexture(redbeardEast1);
                }
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 500, 300, 100)))
                {
                    this.Exit();
                }
            }     //End menu

            if (Status == status.winner)
            {
                if (inputHelper.IsNewPress(Keys.Enter))
                {
                    Status = status.menu; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); powerups.Clear();
                }
            }

            // TODO: Add your update logic here
            inputHelper.Update();
            base.Update(gameTime);
        }
Esempio n. 2
0
        /// <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)
        {
            inputHelper.Update();

            //Mouse control
            if (Status == status.menu)
            {
                this.IsMouseVisible = true;
            }
            if (Status == status.running || Status == status.winner)
            {
                this.IsMouseVisible = false;
            }

            if (Status == status.running)
            {
                //THE ACTUAL GAME UPDATE STUFF

                //Redbeard move
                if (inputHelper.IsCurPress(Keys.W))
                {
                    redbeard.Move(dir.North);
                }
                if (inputHelper.IsCurPress(Keys.A))
                {
                    redbeard.Move(dir.West); redbeard.Retexture(redbeardWest1);
                }
                if (inputHelper.IsCurPress(Keys.S))
                {
                    redbeard.Move(dir.South);
                }
                if (inputHelper.IsCurPress(Keys.D))
                {
                    redbeard.Move(dir.East); redbeard.Retexture(redbeardEast1);
                }

                //Greybeard Move
                if (inputHelper.IsCurPress(Keys.Up))
                {
                    greybeard.Move(dir.North);
                }
                if (inputHelper.IsCurPress(Keys.Left))
                {
                    greybeard.Move(dir.West); greybeard.Retexture(greybeardWest1);
                }
                if (inputHelper.IsCurPress(Keys.Down))
                {
                    greybeard.Move(dir.South);
                }
                if (inputHelper.IsCurPress(Keys.Right))
                {
                    greybeard.Move(dir.East); greybeard.Retexture(greybeardEast1);
                }

                //Attack Buttons
                //redbeard attack
                if (inputHelper.IsNewPress(Keys.V) && redbeard.hitbox.Intersects(greybeard.hitbox))
                {
                    greybeard.Hurt(redbeard.strenght, hurt);
                    redbeard.DrawAttack();
                }

                //greybeard attack
                if (inputHelper.IsNewPress(Keys.NumPad2) && greybeard.hitbox.Intersects(redbeard.hitbox))
                {
                    redbeard.Hurt(greybeard.strenght, hurt);
                    greybeard.DrawAttack();
                }

                //end Attcks

                //Display winner
                if (redbeard.health < 0)
                {
                    Winner = winner.greybeard; Status = status.winner;
                }
                if (greybeard.health < 0)
                {
                    Winner = winner.redbeard; Status = status.winner;
                }

                // add powerups
                if (powerups == null || powerups.Count < 10)
                {
                    powerup = powerupNumber.Next(0, 5);

                    if (powerup == 0)
                    {
                        powerups.Add(new Sprite(cowTexture, type.cow));
                    }
                    if (powerup == 1)
                    {
                        powerups.Add(new Sprite(mjod, type.mjod));
                    }
                    if (powerup == 2)
                    {
                        powerups.Add(new Sprite(kottbulle, type.kottbulle));
                    }
                }

                //pick up powerups
                for (int i = 0; i < powerups.Count; ++i)
                {
                    //greybeard
                    if (inputHelper.IsNewPress(Keys.NumPad2) && greybeard.hitbox.Intersects(powerups[i].hitbox))
                    {
                        //check which powerup and apply effect
                        if (powerups[i].type == type.mjod)
                        {
                            greybeard.strenght += 60;
                        }
                        if (powerups[i].type == type.cow)
                        {
                            greybeard.speed += 2;
                        }
                        if (powerups[i].type == type.kottbulle)
                        {
                            greybeard.health += 60;
                        }
                        //remove powerup
                        powerups.Remove(powerups[i]); i = 0;
                    }

                    //redbeard
                    if (inputHelper.IsNewPress(Keys.V) && redbeard.hitbox.Intersects(powerups[i].hitbox))
                    {
                        //check which powerup and apply effect
                        if (powerups[i].type == type.mjod)
                        {
                            redbeard.strenght += 60;
                        }
                        if (powerups[i].type == type.cow)
                        {
                            redbeard.speed += 2;
                        }
                        if (powerups[i].type == type.kottbulle)
                        {
                            redbeard.strenght += 60;
                        }

                        //remove powerup
                        powerups.Remove(powerups[i]); i = 0;
                    }
                }//end powerups

                // Allows the game to exit
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                {
                    this.Exit();
                }

                if (inputHelper.IsNewPress(Keys.Escape))
                {
                    Status = status.menu;
                }
            } //End if running

            //menu
            if (Status == status.menu)
            {
                if (MenuSelected == menuSelected.play)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        Status = status.running;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected += 1;
                    }

                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected += 2;
                    }
                }

                else if (MenuSelected == menuSelected.restart)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        Status = status.running; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); powerups.Clear();
                    }
                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected -= 1;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected += 1;
                    }
                }

                else if (MenuSelected == menuSelected.exit)
                {
                    if (inputHelper.IsNewPress(Keys.Enter))
                    {
                        this.Exit();
                    }
                    if (inputHelper.IsNewPress(Keys.Up))
                    {
                        MenuSelected -= 1;
                    }
                    if (inputHelper.IsNewPress(Keys.Down))
                    {
                        MenuSelected -= 2;
                    }
                }

                //Musgrejor
                MouseState mouseState = Mouse.GetState();
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 300, 300, 100)))
                {
                    Status = status.running;
                }
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 400, 300, 100)))
                {
                    Status = status.running; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); greybeard.Retexture(greybeardWest1); redbeard.Retexture(redbeardEast1);
                }
                if (mouseState.LeftButton == ButtonState.Pressed && new Rectangle(mouseState.X, mouseState.Y, 10, 10).Intersects(new Rectangle(490, 500, 300, 100)))
                {
                    this.Exit();
                }
            } //End menu

            if (Status == status.winner)
            {
                if (inputHelper.IsNewPress(Keys.Enter))
                {
                    Status = status.menu; greybeard.Reset(1052, 300); redbeard.Reset(100, 300); powerups.Clear();
                }
            }

            // TODO: Add your update logic here
            inputHelper.Update();
            base.Update(gameTime);
        }