Esempio n. 1
0
File: Game1.cs Progetto: Xe3d/Main
        /// <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();
            }

            // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses
            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            //Update the player
            UpdatePlayer(gameTime);

            // Update the parallaxing background
            if (currentKeyboardState.IsKeyDown(Keys.A))
            {
                bgLayer1.Update();
                bgLayer2.Update();
            }

            // Update the enemies
            UpdateEnemies(gameTime);



            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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses

            previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();

            //Update the player
            player.Update(gameTime);
            UpdatePlayer(gameTime);
            // Update the parallaxing background
            bgLayer1.Update();
            bgLayer2.Update();
            UpdateEnemies(gameTime);
            UpdateCollision();
            UpdateProjectiles();
            UpdateExplosions(gameTime);

            base.Update(gameTime);
        }
Esempio n. 3
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 == ButtonState.Pressed ||
                currentKeyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            // TODO: Add your update logic here
            UpdatePlayer(gameTime);
            bgLayer1.Update();
            bgLayer2.Update();
            UpdateEnemy(gameTime);
            UpdateProjectiles();
            UpdateCollision();
            UpdateExplosions(gameTime);
            ui.Update();
            base.Update(gameTime);
        }
Esempio n. 4
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 == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            //Updates the player
            player.Update(gameTime);
            //Save the previous state of keyboard
            previousKeyboardState = currentKeyboardState;

            //Read current keyboard state
            currentKeyboardState = Keyboard.GetState();

            //Update the player
            UpdatePlayer(gameTime);

            //Update the parallaxing background
            bgLayer1.Update();
            bgLayer2.Update();

            //Update the enemies
            UpdateEnemies(gameTime);


            base.Update(gameTime);
        }
Esempio n. 5
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 == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            // Save the previous state of the keyboard and game pad to determine single key presses
            previousKeyboardState = currentKeyboardState;
            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            //Update the player
            UpdatePlayer(gameTime);

            // Update the parallaxing background
            bgLayer1.Update();
            bgLayer2.Update();

            // Update the enemies
            UpdateEnemies(gameTime);

            UpdateCollisions();

            explosionAnim.Update(gameTime);

            base.Update(gameTime);
        }
Esempio n. 6
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 == ButtonState.Pressed || currentKeyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            //Any key closes the start menu
            if (startMenu == true)
            {
                if (currentGamePadState.Buttons.Start == ButtonState.Pressed || currentKeyboardState.IsKeyDown(Keys.Enter))
                {
                    startMenu = false;
                }
            }

            if (gameOver == true)
            {
                if (currentGamePadState.Buttons.Start == ButtonState.Pressed || currentKeyboardState.IsKeyDown(Keys.Enter))
                {
                    gameOver = false;
                }
            }

            // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses
            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            if (startMenu == false && gameOver == false)
            {
                UpdateBackgroundEnemies(gameTime);
                //Update the player
                UpdateExplosions(gameTime);
                UpdatePlayer(gameTime);
                UpdateEnemies(gameTime);

                UpdateBackgroundEnemies(gameTime);
                UpdateCollision();

                // Update the projectiles
                UpdateProjectiles();

                // Update the parallaxing background
                bgLayer1.Update();
                bgLayer2.Update();
            }

            base.Update(gameTime);
        }
Esempio n. 7
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)
        {
            // For Mobile devices, this logic will close the Game when the Back button is pressed
            // Exit() is obsolete on iOS
                        #if !__IOS__ && !__TVOS__
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
                        #endif

            // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses
            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);


            //Update the player
            UpdatePlayer(gameTime);

            // Update the parallaxing background
            bgLayer1.Update();
            bgLayer2.Update();

            // Update the enemies
            UpdateEnemies(gameTime);

            // Update the collision
            UpdateCollision();

            // Update the projectiles
            UpdateProjectiles();

            UpdateLazorBeam(gameTime);

            // Update the explosions
            UpdateExplosions(gameTime);

            base.Update(gameTime);
        }
Esempio n. 8
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 == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here

            base.Update(gameTime);

            // Save the previous state of the keyboard and game pad so we can determinesingle key/button presses
            previousGamePadState  = currentGamePadState;
            previousKeyboardState = currentKeyboardState;

            // Read the current state of the keyboard and gamepad and store it
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);


            //Update the player
            UpdatePlayer(gameTime);

            // Update the parallaxing background
            bgLayer1.Update();
            bgLayer2.Update();

            // Update the enemies
            UpdateEnemies(gameTime);

            // Update the explosions
            UpdateExplosions(gameTime);

#if MONOGAME
            var state = Accelerometer.GetState();

            player.Position.X += (float)state.Acceleration.Y * playerMoveSpeed;
            player.Position.Y += (float)state.Acceleration.X * playerMoveSpeed;
#endif
        }
Esempio n. 9
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 == ButtonState.Pressed)
            {
                this.Exit();
            }
            if (!gameOver)
            {
                prevKeyboardState    = currentKeyboardState;
                currentKeyboardState = Keyboard.GetState();
                updatePlayer(gameTime);
                updateEnemies(gameTime);
                bgLayer1.Update();
                bgLayer2.Update();
                updateCollision();
                updateProjectiles(gameTime);
                updateExplosions(gameTime);
                powerUp.Update(gameTime);
            }

            base.Update(gameTime);
        }
Esempio n. 10
0
        protected override void Update(GameTime gameTime)
        {
            previouseKeyboardState = currentKeyboardState;
            previouseGamePadState  = currentGamePadState;
            previouseMouseState    = currentMouseState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);
            currentMouseState    = Mouse.GetState();

            if ((currentGamePadState.Buttons.Back == ButtonState.Pressed && previouseGamePadState.Buttons.Back != ButtonState.Pressed) ||
                (currentKeyboardState.IsKeyDown(Keys.Escape) && !previouseKeyboardState.IsKeyDown(Keys.Escape)))
            {
                switch (gameState)
                {
                case GameState.Playing:
                    gameState = GameState.Paused;
                    MediaPlayer.Pause();
                    break;

                case GameState.Paused:
                    gameState = GameState.Playing;
                    MediaPlayer.Play(gameMusic.Song);
                    break;

                default:
                    break;
                }
            }

            if (gameState != GameState.Playing)
            {
                playButton.Update(currentMouseState.X, currentMouseState.Y);
                exitButton.Update(currentMouseState.X, currentMouseState.Y);

                ButtonSound(playButton, playButtonSound);
                ButtonSound(exitButton, exitButtonSound);

                if (currentMouseState.LeftButton == ButtonState.Pressed && previouseMouseState.LeftButton != ButtonState.Pressed)
                {
                    MouseClickedOnMenu(playButton.IsMouseOver, exitButton.IsMouseOver, gameTime);
                }
            }

            if (isGameEnded)
            {
                MediaPlayer.Stop();
            }

            if (isGameEnded && enemies.Count == 0 && !shootingEnemy.Active && !bomb.Active && !healer.Active &&
                laserBeams.Count == 0 && enemyLaserBeams.Count == 0 &&
                !asteroids[0].Active && !asteroids[1].Active && !asteroids[2].Active)
            {
                gameState = GameState.StartMenu;
            }

            if (gameState != GameState.Paused)
            {
                // Update the parallaxing background
                bgLayer1.Update(gameTime);
                bgLayer2.Update(gameTime);
            }

            UpdateHealer(gameTime);
            UpdateBomb(gameTime);
            UpdateAsteroids(gameTime);

            if (gameState == GameState.Playing)
            {
                UpdatePlayer(gameTime);

                UpdateEnemySpeed(gameTime);
                UpdateEnemies(gameTime);

                if (player.Active)
                {
                    UpdateCollision();
                }

                UpdateLaserBeams(gameTime, laserBeams);
                UpdateLaserBeams(gameTime, enemyLaserBeams);

                UpdateExplosions(gameTime);
            }

            healthBar.Update(player.Health);

            base.Update(gameTime);
        }