Ejemplo n.º 1
0
        /// <summary>
        /// *** Noob implementation of a factory
        /// </summary>
        /// <param name="enemyType"></param>
        /// <returns></returns>
        public List<Enemy> CreateEnemy(InputState ins)
        {
            List<Enemy> enemyList = new List<Enemy>();
            PlayerIndex useless; // reports which player decided to spawn an enemy, currently unused, but require for InputState.IsNewKeyPress
            if (ins.IsNewKeyPress(Keys.D1, null, out useless)) enemyList.Add(_spawnFrames[0].Spawn());
            if (ins.IsNewKeyPress(Keys.D2, null, out useless)) enemyList.Add(_spawnFrames[1].Spawn());
            if (ins.IsNewKeyPress(Keys.D3, null, out useless)) enemyList.Add(_spawnFrames[2].Spawn());
            if (ins.IsNewKeyPress(Keys.D4, null, out useless)) enemyList.Add(_spawnFrames[3].Spawn());
            if (ins.IsNewKeyPress(Keys.D5, null, out useless)) enemyList.Add(_spawnFrames[4].Spawn());
            if (ins.IsNewKeyPress(Keys.D6, null, out useless)) enemyList.Add(_spawnFrames[5].Spawn());
            if (ins.IsNewKeyPress(Keys.D7, null, out useless)) enemyList.Add(_spawnFrames[6].Spawn());
            if (ins.IsNewKeyPress(Keys.D8, null, out useless)) enemyList.Add(_spawnFrames[7].Spawn());
            if (ins.IsNewKeyPress(Keys.D9, null, out useless)) enemyList.Add(_spawnFrames[8].Spawn());

            foreach (Enemy enemy in enemyList)
            {
                if (enemy != null)
                {
                    _unitAmmount++;
                    enemy.Position = new Vector2(300, 125);
                    enemy.Tag = "Enemy";
                }
            }

            return enemyList;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            _level.HandleInput(input);

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(_audioManager), ControllingPlayer);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// *** Should the spawner trigger it's own functions or the level trigger the spawner's function in case the player trigger
 ///     a spawning event with a key (1 to 9) ?
 /// </summary>
 public override void HandleInput(InputState input)
 {
     // Maybe it would be better to pass the key pressed to the spawner
     // and create an enemy accordingly
     /*
     if (key1.IsKeyDown(Keys.D1) && !oldState.IsKeyDown(Keys.D1)) // oldState value assigned later
     {
         Enemy sprite = _spawner.CreateEnemy(1);
         if (sprite != null)
             _midSpriteManager.CreateSprite(sprite);
     }
     */
     foreach (Enemy sprite in _spawner.CreateEnemy(input)) {
         if (sprite != null)
             _midSpriteManager.CreateSprite(sprite);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
     if (input == null)
         throw new ArgumentNullException("input");
 }