Exemple #1
0
        public static void GameUpdate()
        {
            // Update code here
            player.Update();
            if (!player.HasBeenKilled())
            {
                UpdateTouchData();
                obstacleManager.Update(moveSpeed);
                background.Update(moveSpeed);
                UpdateCamera();
                UpdateScore();
            }

            // Sets the volcano background to follow the sprite
            background.SetVolcanoPosition((player.GetPos().X + 400) - (Director.Instance.GL.Context.GetViewport().Width / 2), 0.0f);

            if (player.IsDead())
            {
                screenManager.ChangeScreenTo(Screens.GameOver);
                gameScene.AddChild(rSprite);
                DestroyGame();
                highscoresManager.SaveScore((int)score);
            }
        }
Exemple #2
0
        protected override void Update(GameTime gameTime)
        {
            //if (!gameRunning)
            //{
            //    if (!soundManager.introPlaying)
            //        soundManager.playIntro();
            //}
            //else
            //{
            //    if (!soundManager.backgroundPlaying)
            //        soundManager.playBackground();
            //}

            if (turnsTaken == 0 & !shotFired)
            {
                cameraFollow(currentTank.getTankPos());
            }

            player1Tank.checkAngle();
            player2Tank.checkAngle2();

            if (currentTank == player1Tank)
            {
                currentTank.turretPosition = new Vector2(currentTank.tankPosition.X + 45, currentTank.tankPosition.Y + 10);
                controller = GamePad.GetState(PlayerIndex.One);
                currentTank.recieveController(GamePad.GetState(PlayerIndex.One));
            }

            if (currentTank == player2Tank)
            {
                currentTank.turretPosition = new Vector2(currentTank.tankPosition.X + 30, currentTank.tankPosition.Y + 10);
                controller = GamePad.GetState(PlayerIndex.Two);
                currentTank.recieveController(GamePad.GetState(PlayerIndex.Two));
            }

            if ((currentTank.tankPosition.X > 180 && currentTank.tankPosition.X < 468) || (currentTank.tankPosition.X > 1160 && currentTank.tankPosition.X < 1260))
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 50;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 15;
            }
            else if ((currentTank.tankPosition.X > 705 && currentTank.tankPosition.X < 950) || (currentTank.tankPosition.X > 1540 && currentTank.tankPosition.X < 1795))
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 30;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 15;
            }
            else
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 40;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 10;
            }

            if (controller.Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            screenManager.Update(gameTime);

            player1Tank.tempSpeed = 1f;
            player2Tank.tempSpeed = 1f;

            if (player1Tank.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData))
            {
                player1Tank.tempSpeed = 0;
            }

            if (player2Tank.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData))
            {
                player2Tank.tempSpeed = 0;
            }

            if (gameRunning)
            {
                //if (soundManager.introPlaying)
                //    soundManager.stopIntro();

                uiManager.Update(gameTime);
                background.Update(gameTime);

                takeTurn(gameTime);

                tankCollision(player1Tank, player2Tank);
                powerUpManager.PowerUpCollision(player1Tank, player2Tank);

                if (isGameOver() || Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    gameRunning = false;
                    GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0.0f, 0.0f);
                    screenManager.ChangeGameState(ScreenManager.GameState.END);
                }

                if (currentTank.turnTime <= 5 && currentTank.turnTime > 0)
                {
                    if (countdownTimer >= 1)
                    {
                        soundManager.timeBeep.Play();
                        countdownTimer = 0;
                    }
                    else
                    {
                        countdownTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }
            }

            if (screenManager.currentState == ScreenManager.GameState.END)
            {
                resetSetting();
            }

            uiManager.moveFloatingText();

            base.Update(gameTime);
        }