Ejemplo 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)
        {
            // Allows the game to exit

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                this.Exit();
            }
            updateLabel(gameTime);
            game_map.Update(vandal.Rectangle, gameTime);


            // UpdateInput();
            switch (key_pressed)
            {
            //case (System.Windows.Forms.Keys.None):
            //    if (move)
            //    {
            //        vandal.SetFinalPosition(game_map);
            //        move = false;
            //    }
            //    break;
            case (System.Windows.Forms.Keys.W):

                vandal.Move(direction.up);
                break;

            case (System.Windows.Forms.Keys.S):

                vandal.Move(direction.down);
                break;

            case (System.Windows.Forms.Keys.A):

                vandal.Move(direction.left);
                break;

            case (System.Windows.Forms.Keys.D):

                vandal.Move(direction.right);
                break;

            case (System.Windows.Forms.Keys.Alt):

                vandal.changeDirectionToNext();
                break;

            case (System.Windows.Forms.Keys.Enter):
                Form.setPlayerName("enter");
                vandal.LeftDynamite();
                break;

            case (System.Windows.Forms.Keys.Escape):
                Application.Exit();
                break;

            case (System.Windows.Forms.Keys.LShiftKey):

                vandal.AttackWithRacket();
                break;

            default:
                break;
            }
            vandal.LoadCurrentTexture();

            /*  for(int i = 0;i<dynamites.Capacity;)
             * {
             *    if(dynamites[i].Rectangle.Intersects(vandal.Rectangle))
             *    {
             *       // dynamites.Remove(dynamites[i]);
             *        player.Dynamite++;
             *    }
             *    //else
             *    i++;
             *
             *   // d.Update();
             * }*/

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Ejemplo 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)
        {
            if (isStarted)
            {
                // Allows the game to exit
                if (!IsPaused)
                {
                    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        this.Exit();
                    }


                    updateLabel(gameTime.TotalGameTime.Minutes - lastUpdateMinutes, gameTime.TotalGameTime.Seconds - lastUpdateSeconds);
                    game_map.Update(gameTime);
                    lastUpdateMinutes = gameTime.TotalGameTime.Minutes;
                    lastUpdateSeconds = gameTime.TotalGameTime.Seconds;

                    if (key_pressed == System.Windows.Forms.Keys.None)
                    {
                        if (move)
                        {
                            move = false;
                            game_map.MoveVandal(direction.none);
                        }
                    }


                    else if (key_pressed == player.KeyboardSettings.Up)
                    {
                        game_map.MoveVandal(direction.up);
                    }
                    else if (key_pressed == player.KeyboardSettings.Down)
                    {
                        game_map.MoveVandal(direction.down);
                    }
                    else if (key_pressed == player.KeyboardSettings.Left)
                    {
                        game_map.MoveVandal(direction.left);
                    }
                    else if (key_pressed == player.KeyboardSettings.Right)
                    {
                        game_map.MoveVandal(direction.right);
                    }
                    else if (key_pressed == player.KeyboardSettings.Block)
                    {
                        game_map.GetVandal().changeDirectionToNext(game_map);
                    }
                    else if (key_pressed == player.KeyboardSettings.Dynamite)
                    {
                        if (player.Dynamite > 0)
                        {
                            game_map.GetVandal().LeftDynamite(game_map, gameTime);
                            key_pressed = System.Windows.Forms.Keys.None;
                        }
                        else
                        {
                            SoundEffect null_sound = Content.Load <SoundEffect>("Audio\\null_sound");
                            if (!player.AudioSettings.IsMuted)
                            {
                                SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                                null_sound.Play();
                            }
                        }
                    }
                    else if (key_pressed == player.KeyboardSettings.Pause)
                    {
                        PauseGame();
                    }
                    else if (key_pressed == player.KeyboardSettings.Racket)
                    {
                        if (player.Rackets > 0)
                        {
                            game_map.GetVandal().AttackWithRacket(game_map);
                        }
                        else
                        {
                            SoundEffect null_sound = Content.Load <SoundEffect>("Audio\\null_sound");
                            if (!player.AudioSettings.IsMuted)
                            {
                                SoundEffect.MasterVolume = (float)player.AudioSettings.SoundVolume;
                                null_sound.Play();
                            }
                        }
                    }



                    if (game_map.GetVandal().level_up)
                    {
                        int current_level = game_map.gameLevel;
                        if (current_level < 5)
                        {
                            //aktualizacja maksymalnego dopuszczalnego pzoiomu gry
                            if (player.MaxEnabledLevel < current_level + 1)
                            {
                                player.MaxEnabledLevel = current_level + 1;
                                Form.choose_level_panel.EnableTillLevel(player.MaxEnabledLevel);
                            }

                            //ustawianie poziomu inteligencji - jest ta funkcjonalnosc jest wlaczona
                            if (player.CheckIntelligence)
                            {
                                if (player.Points < 500 * current_level)
                                {
                                    player.IntelligenceLevel = 0;
                                }
                                if (player.Points >= 500 * current_level && player.Points < 900 * current_level)
                                {
                                    player.IntelligenceLevel = 1;
                                }
                                else
                                {
                                    player.IntelligenceLevel = 2;
                                }
                            }


                            game_map = new Map.Map(tile_size, map_width, map_height, this.Content, player, current_level + 1);
                        }
                        else
                        {
                            SaveHighScore();
                            Win();
                        }
                    }
                }
                if (!game_map.GetVandal().is_alive)
                {
                    IsPaused = true;
                    SaveHighScore();
                    GameOver();
                    game_map.GetVandal().is_alive = true;
                }

                {
                    base.Update(gameTime);

                    lastUpdateMinutes = gameTime.TotalGameTime.Minutes;
                    lastUpdateSeconds = gameTime.TotalGameTime.Seconds;
                }
            }
        }