コード例 #1
0
        public void Update()
        {
            mouseState = Mouse.GetState();

            ButtonState currState = mouseState.LeftButton;

            if (currState == ButtonState.Pressed && currState != prevState)
            {
                mousePosition = new Point(mouseState.X, mouseState.Y);
                if (homeButtonRectangle.Contains(mousePosition))
                {
                    game.quitGame();
                }

                prevState = currState;
            }
            if (currState == ButtonState.Released)
            {
                prevState = currState;
            }
        }
コード例 #2
0
        public void Update(GameTime gameTime)
        {
            if (runTimer)
            {
                timer += (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            playerShip.Update(gameTime);

            UpdateInput();

            if (playerShip.Lives == 0) // game over
            {
                runTimer = false;
                Score playerScore = new Score(timer);
                game.gameOver(playerScore);
                saveScore(playerScore);
            }

            for (int i = 0; i < playerAttackBallList.Count; i++)
            {
                playerAttackBallList[i].Update(gameTime);
                if (playerAttackBallList[i].Position.Y < -100.0f)
                {
                    playerAttackBallList.RemoveAt(i);
                }
            }

            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            buttonFireDelay -= elapsed;
            enemyDelay      -= elapsed;


            for (int i = 0; i < enemyShipList.Count; i++)
            {
                enemyShipList[i].Update(gameTime);

                if (enemyShipList[i].Firing)
                {
                    AttackBall attackBall = new AttackBall(enemyAttackBallTexture, new Vector2(enemyShipList[i].Position.X + 10.0f, enemyShipList[i].Position.Y + 30.0f), -300.0f);
                    enemyAttackBallList.Add(attackBall);
                    enemyShipList[i].Firing = false;
                }


                int collide = enemyShipList[i].CollisionBall(playerAttackBallList);

                if (collide != -1)
                {
                    enemyShipList.RemoveAt(i);

                    playerAttackBallList.RemoveAt(collide);
                }
                else
                if (playerShip.CollisionTest(enemyShipList[i].Position, enemyShipList[i].Radius))
                {
                    enemyShipList.RemoveAt(i);
                }
                else if (enemyShipList[i].Position.Y > 2000.0f)
                {
                    enemyShipList.RemoveAt(i);
                }
            }

            for (int i = 0; i < enemyAttackBallList.Count; i++)
            {
                enemyAttackBallList[i].Update(gameTime);

                if (enemyAttackBallList[i].Position.Y > 900)
                {
                    enemyAttackBallList.RemoveAt(i);
                }
                else if (playerShip.CollisionTest(enemyAttackBallList[i].Position, 20.0f))
                {
                    enemyAttackBallList.RemoveAt(i);
                }
            }


            if (enemyDelay <= 0.0f)
            {
                CreateEnemy();
                enemyDelay      = enemySpawnRate;
                buttonFireDelay = 0.25f;
            }


            mouseState = Mouse.GetState();

            ButtonState currState = mouseState.LeftButton;

            if (currState == ButtonState.Pressed && currState != prevState)
            {
                mousePosition = new Point(mouseState.X, mouseState.Y);
                if (quitButtonRectangle.Contains(mousePosition))
                {
                    game.quitGame();
                }

                prevState = currState;
            }
            if (currState == ButtonState.Released)
            {
                prevState = currState;
            }
        }