コード例 #1
0
        //Update and Draw Methods --------------------------------------------------------------
        //Main Update Method for Keyboard
        public void MissleManagerUpdateFriendlyKeyboard(KeyboardState currentKeyState, KeyboardState previousKeyState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            this.z_EnemyShipList = this.z_enemyManager.getEnemiesList();
            //The Alogrithm:
            //Determine if the player shot a missle
            //If so then add it the List
            //If the list is not empty, update each missle
            //While checking each missle, make sure it hasn't left the screen or collided with something
            //If so, remove it from the list

            if (currentKeyState.IsKeyDown(Keys.Space) && previousKeyState.IsKeyUp(Keys.Space) && playerShip.getIsAlive())
            {
                //Play a fire sound
                this.z_fireSound1.Play(.2f, 0, 0);

                //Create and add a new Missle Object
                this.z_FriendlyMissles.Add(this.z_bulletPool.getNextAvailableEnemy());
                /*
                this.z_FriendlyMissles.Add(new PlayerMissle1(this.z_friendlyMissleSprite1,
                                                             new Vector2(playerShip.getPosition().X
                                                                         + playerShip.getSprite().Width / 2
                                                                         - this.z_friendlyMissleSprite1.Width / 2,
                                                                 playerShip.getPosition().Y), spriteBatch));
                 * */
            }

            this.MissleManagerUpdateEnemy();

            //If List is empty, nothing to update, exit this update function
            if (this.z_FriendlyMissles.Count <= 0)
                return;

            this.UpdateFriendlyList();
        }
コード例 #2
0
        //Main Update Method for GamePad
        public void MissleManagerUpdateFriendlyGamepad(GamePadState currentPadState, GamePadState previousPadState,
                                                        PlayerShip playerShip, SpriteBatch spriteBatch)
        {
            //For the simple collision checking
            //this.z_EnemyShipList = enemyList;
            //Same Algorithm as before, but with a gamePad controller [Fire = right Trigger]
            if (currentPadState.Triggers.Right >= .5f && previousPadState.Triggers.Right == 0 && playerShip.getIsAlive())
            {
                this.z_FriendlyMissles.Add(new PlayerMissle1(this.z_friendlyMissleSprite1,
                                                             new Vector2(playerShip.getPosition().X
                                                                         + playerShip.getSprite().Width / 2
                                                                         - this.z_friendlyMissleSprite1.Width / 2,
                                                                 playerShip.getPosition().Y), spriteBatch));

                //Play a fire sound
                this.z_fireSound1.Play(.2f, 0, 0);
            }

            this.MissleManagerUpdateEnemy();
            //If List is empty, nothing to update, exit this update function
            if (this.z_FriendlyMissles.Count <= 0)
                return;

            this.UpdateFriendlyList();
        }