示例#1
0
        // process input
        public override void ProcessInput(float elapsedTime, InputManager input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            gameManager.ProcessInput(elapsedTime, input);

            int i, j = (int)gameManager.GameMode;
            for (i = 0; i < j; i++)
                if (input.IsKeyPressed(i,Keys.Escape) || input.IsButtonPressedBack(i))
                {
                    gameManager.GetPlayer(i).Score = -1;
                    screenManager.SetNextScreen(ScreenType.ScreenEnd);
                    gameManager.PlaySound("menu_cancel");
                }
        }
示例#2
0
        float backgroundTime = 0.0f;  // time for background animation used on menus

        // constructor
        public ScreenManager(ShipGameGame shipGame, FontManager font, GameManager game)
        {
            this.shipGame = shipGame;
            gameManager = game;
            fontManager = font;

            screens = new List<Screen>();
            inputManager = new InputManager();

            // add all screens
            screens.Add(new ScreenIntro(this, game));
            screens.Add(new ScreenHelp(this, game));
            screens.Add(new ScreenPlayer(this, game));
            screens.Add(new ScreenLevel(this, game));
            screens.Add(new ScreenGame(this, game));
            screens.Add(new ScreenEnd(this, game));

            // fade in to intro screen
            SetNextScreen(ScreenType.ScreenIntro,
                GameOptions.FadeColor, GameOptions.FadeTime);
            fade = fadeTime * 0.5f;
        }
示例#3
0
        public override void ProcessInput(float elapsedTime, InputManager input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            int i, j = (int)gameManager.GameMode;
            for (i = 0; i < j; i++)
            {
                // select
                if (input.IsKeyPressed(i, Keys.Enter) || input.IsButtonPressedA(i))
                {
                    gameManager.SetLevel(levels[selection]);
                    screenManager.SetNextScreen(ScreenType.ScreenGame);
                    gameManager.PlaySound("menu_select");
                }

                // cancel
                if (input.IsKeyPressed(i, Keys.Escape) || input.IsButtonPressedB(i))
                {
                    gameManager.SetLevel(null);
                    screenManager.SetNextScreen(ScreenType.ScreenPlayer);
                    gameManager.PlaySound("menu_cancel");
                }

                // change selection (previous)
                if (input.IsKeyPressed(i, Keys.Left) ||
                    input.IsButtonPressedDPadLeft(i) ||
                    input.IsButtonPressedLeftStickLeft(i))
                {
                    if (selection == 0)
                        selection = levels.GetLength(0) - 1;
                    else
                        selection = selection - 1;
                    gameManager.PlaySound("menu_change");
                }

                // change selection (next)
                if (input.IsKeyPressed(i, Keys.Right) ||
                    input.IsButtonPressedDPadRight(i) ||
                    input.IsButtonPressedLeftStickRight(i))
                {
                    selection = (selection + 1) % levels.GetLength(0);
                    gameManager.PlaySound("menu_change");
                }
            }
        }
示例#4
0
        public override void ProcessInput(float elapsedTime, InputManager input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            const float rotationVelocity = 3.0f;

            int i, j = (int)gameManager.GameMode;

            for (i = 0; i < j; i++)
                if (confirmed[i] == false)
                {
                    // change invert Y selection
                    if (input.IsKeyPressed(i, Keys.Y) || input.IsButtonPressedY(i))
                    {
                        invertY ^= ((uint)1 << i);
                        gameManager.PlaySound("menu_change");
                    }

                    // confirm selection
                    if (input.IsKeyPressed(i, Keys.Enter) || input.IsButtonPressedA(i))
                    {
                        confirmed[i] = true;
                        gameManager.PlaySound("menu_select");
                    }

                    // cancel and return to intro menu
                    if (input.IsKeyPressed(i, Keys.Escape) || input.IsButtonPressedB(i))
                    {
                        gameManager.SetShips(null, null, 0);
                        screenManager.SetNextScreen(ScreenType.ScreenIntro);
                        gameManager.PlaySound("menu_cancel");
                    }

                    // rotate ship
                    float RotX = rotationVelocity * input.LeftStick(i).X * elapsedTime;
                    if (input.IsKeyDown(i, Keys.Left))
                        RotX -= rotationVelocity * elapsedTime;
                    if (input.IsKeyDown(i, Keys.Right))
                        RotX += rotationVelocity * elapsedTime;
                    if (Math.Abs(RotX) < 0.001f)
                        RotX = -0.5f * elapsedTime;
                    rotation[i] = rotation[i] * Matrix.CreateRotationY(RotX);

                    // change ship (next)
                    if (input.IsKeyPressed(i, Keys.Up) ||
                        input.IsButtonPressedDPadUp(i) ||
                        input.IsButtonPressedLeftStickUp(i))
                    {
                        selection[i] = (selection[i] + 1) % NumberShips;
                        gameManager.PlaySound("menu_change");
                    }

                    // change ship (previous)
                    if (input.IsKeyPressed(i, Keys.Down) ||
                        input.IsButtonPressedDPadDown(i) ||
                        input.IsButtonPressedLeftStickDown(i))
                    {
                        if (selection[i] == 0)
                            selection[i] = NumberShips - 1;
                        else
                            selection[i] = selection[i] - 1;
                        gameManager.PlaySound("menu_change");
                    }
                }
                else
                {
                    // cancel selection
                    if (input.IsKeyPressed(i, Keys.Escape) || input.IsButtonPressedB(i))
                    {
                        confirmed[i] = false;
                        gameManager.PlaySound("menu_cancel");
                    }
                }

            // if both ships confirmed, go to game screen
            if (confirmed[0] && confirmed[1])
            {
                if (gameManager.GameMode == GameMode.SinglePlayer)
                    gameManager.SetShips(ships[selection[0]], null, invertY);
                else
                    gameManager.SetShips(ships[selection[0]],
                                ships[selection[1]], invertY);
                screenManager.SetNextScreen(ScreenType.ScreenLevel);
            }
        }
示例#5
0
        // process input
        public override void ProcessInput(float elapsedTime, InputManager input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            int i, j = (int)gameManager.GameMode;
            for (i = 0; i < j; i++)
            {
                // Any key/button to go back
                if (input.IsButtonPressedA(i) ||
                    input.IsButtonPressedB(i) ||
                    input.IsButtonPressedX(i) ||
                    input.IsButtonPressedY(i) ||
                    input.IsButtonPressedLeftShoulder(i) ||
                    input.IsButtonPressedRightShoulder(i) ||
                    input.IsButtonPressedLeftStick(i) ||
                    input.IsButtonPressedRightStick(i) ||
                    input.IsButtonPressedBack(i) ||
                    input.IsButtonPressedStart(i) ||
                    input.IsKeyPressed(i, Keys.Enter) ||
                    input.IsKeyPressed(i, Keys.Escape) ||
                    input.IsKeyPressed(i, Keys.Space))
                {
                    screenManager.SetNextScreen(ScreenType.ScreenIntro);
                    gameManager.PlaySound("menu_cancel");
                }
            }
        }
示例#6
0
        // process input
        public override void ProcessInput(float elapsedTime, InputManager input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            for (int i = 0; i < 2; i++)
            {
                // A button or enter to select menu option
                if (input.IsButtonPressedA(i) ||
                    input.IsButtonPressedStart(i) ||
                    input.IsKeyPressed(i, Keys.Enter) ||
                    input.IsKeyPressed(i, Keys.Space))
                {
                    switch (menuSelection)
                    {
                        case 0:
                            // single player
                            gameManager.GameMode = GameMode.SinglePlayer;
                            screenManager.SetNextScreen(ScreenType.ScreenPlayer);
                            break;
                        case 1:
                            // multi player
                            gameManager.GameMode = GameMode.MultiPlayer;
                            screenManager.SetNextScreen(ScreenType.ScreenPlayer);
                            break;
                        case 2:
                            // help
                            screenManager.SetNextScreen(ScreenType.ScreenHelp);
                            break;
                        case 3:
                            // exit game
                            screenManager.Exit();
                            break;
                    }
                    gameManager.PlaySound("menu_select");
                }

                // up/down keys change menu sel
                if (input.IsKeyPressed(i,Keys.Up) ||
                    input.IsButtonPressedDPadUp(i) ||
                    input.IsButtonPressedLeftStickUp(i))
                {
                    menuSelection =
                        (menuSelection == 0 ? NumberMenuItems - 1 : menuSelection - 1);
                    gameManager.PlaySound("menu_change");
                }
                if (input.IsKeyPressed(i, Keys.Down) ||
                    input.IsButtonPressedDPadDown(i) ||
                    input.IsButtonPressedLeftStickDown(i))
                {
                    menuSelection = (menuSelection + 1) % NumberMenuItems;
                    gameManager.PlaySound("menu_change");
                }
            }
        }
示例#7
0
 // called to update input
 public abstract void ProcessInput(float elapsedTime, InputManager input);
示例#8
0
        /// <summary>
        /// Process game input
        /// </summary>
        public void ProcessInput(float elapsedTime, InputManager input)
        {
            // process input for player 1
            players[0].ProcessInput(elapsedTime, input, 0);

            // if in multiplayer mode, process input for player 2
            if (gameMode == GameMode.MultiPlayer)
                players[1].ProcessInput(elapsedTime, input, 1);
        }
示例#9
0
        /// <summary>
        /// Process input for player ship (movement and weapons)
        /// </summary>
        public void ProcessInput(float elapsedTime, InputManager input, int player)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            // if dead, don't process input for player
            if (IsAlive == false)
            {
                return;
            }

            // process movement related inputs
            movement.ProcessInput(elapsedTime, input.CurrentState, player);

            // if player invert Y is enabled, invert X rotation force
            if (gameManager.GetInvertY(player))
                movement.rotationForce.X = -movement.rotationForce.X;

            // if blaster ready and input activated
            if (blaster == 1)
                if (input.IsKeyPressed(player, Keys.Space) ||
                    input.CurrentState.padState[player].Triggers.Right > 0)
                {
                    // fire blaster
                    FireProjectile(ProjectileType.Blaster, GameOptions.BlasterVelocity);
                    // reset charge time
                    blaster = 0;
                }

            // if missile is ready and input activated
            if (missile == 1 && missileCount > 0)
                if (input.IsKeyPressed(player, Keys.Enter) ||
                    input.IsTriggerPressedLeft(player))
                {
                    // fire missile
                    FireProjectile(ProjectileType.Missile, GameOptions.MissileVelocity);
                    // subtract missile count
                    AddMissile(-1);
                    // reset charge time
                    missile = 0;
                }

            // if shield is ready and input
            if (shield == 1)
                if (input.IsKeyPressed(player,Keys.R) || input.IsButtonPressedA(player))
                {
                    // activate shield
                    shieldUse = true;
                    // create animated sprite
                    animatedSpriteShield =
                        gameManager.AddAnimSprite(AnimSpriteType.Shield,
                        transform.Translation + transform.Forward * 10,
                        160, 80, 15, DrawMode.Additive, player);
                    // play shield sound
                    gameManager.PlaySound("shield_activate");
                }

            // if boost ready and input activated
            if (boost == 1)
                if (input.IsKeyPressed(player, Keys.LeftShift) ||
                    input.IsKeyPressed(player, Keys.RightShift) ||
                    input.IsButtonPressedY(player) ||
                    input.IsButtonPressedLeftStick(player))
                {
                    // activate boost
                    boostUse = true;
                    // play boost sound
                    gameManager.PlaySound("ship_boost");
                }

            // if camara switch input activated
            if (input.IsKeyPressed(player, Keys.Back) || input.IsButtonPressedB(player))
            {
                // switch 3rd person mode
                camera3rdPerson = !camera3rdPerson;
                // reset camera
                chaseCamera.Reset();
            }
        }