Example #1
0
        public void HandleInput(GameTime gameTime, InputState input, Game game)
        {
            Vector2 releasePt;
            Vector2 touchPt = input.TouchState.GetTouchPt(out releasePt);

            selectedEntry = -1;

            if (touchPt != Menus.notTouched) {

                // Resume Game
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY - 10;

                if (Menus.MenuItemBoundingBox.Intersects(touchPt))
                    selectedEntry = 0;

                // Main Menu
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + Menus.ItemDeltaY - 10;

                if (Menus.MenuItemBoundingBox.Intersects(touchPt))
                    selectedEntry = 1;

                // Quit
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + Menus.ItemDeltaY*2 - 10;
                if (Menus.MenuItemBoundingBox.Intersects(touchPt))
                    selectedEntry = 2;

                return;
            }

            if (releasePt == Menus.notTouched)
                return;

            // Resume Game
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY - 10;
            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                Invasion.currentScreen = GameplayScreen;
                return;
            }

            // Main Menu
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + Menus.ItemDeltaY - 10;
            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                Invasion.currentScreen = MainMenuScreen;
                return;
            }

            // Quit
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + Menus.ItemDeltaY*2 - 10;
            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                game.Exit();
                return;
            }
        }
Example #2
0
 public void HandleInput(GameTime gameTime, InputState input, Game game)
 {
     Vector2 releasePt;
     Vector2 touchPt = input.TouchState.GetTouchPt(out releasePt);
     // go back to Main Menu when screen is tapped
     if (releasePt != Menus.notTouched)
     {
         Invasion.currentScreen = MainMenuScreen;
         Invasion.DelayStart = Environment.TickCount;
     }
 }
Example #3
0
        private static bool HandleBackButton(InputState inputState, Game game)
        {
            PlayerIndex player;
            bool backPressed = inputState.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out player);

            if (backPressed)
                currentScreen.HandleBackButton(game);

            return backPressed;
        }
Example #4
0
        public void HandleInput(GameTime gameTime, InputState input, Game game)
        {
            Vector2 releasePt;
            Vector2 touchPt = input.TouchState.GetTouchPt(out releasePt);
            timeSinceSpeedChangeSec += (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (releasePt != Menus.notTouched)
            {
                if (InvasionGame.Scoreboard.WeaponTapRect.Intersects(releasePt))
                {
                    Invasion.StarShip.SelectNextWeapon();
                    InvasionGame.Scoreboard.Weapon = Invasion.StarShip.Weapon;
                    input.Gestures.Clear();
                    //while (TouchPanel.IsGestureAvailable)
                    //    TouchPanel.ReadGesture();
                    return;
                }
                else if (InvasionGame.Scoreboard.AutoSelectTapRect.Intersects(releasePt))
                {
                    StarShip.AutoSelectWeapon = !StarShip.AutoSelectWeapon;
                    input.Gestures.Clear();
                    return;
                }
            }

            bool firePressed = false;
            int moveShipLeft = 0;
            int moveShipRight = 0;
            bool skidToAStop = false;
            bool skid = false;
            bool stopMovingShip = false;

            if (touchPt != Menus.notTouched && Invasion.StarShip.Intersects(touchPt)) {
                starshipSelected = true;
            }

            foreach (GestureSample gesture in input.Gestures)
            {

                // we can use the type of gesture to determine our behavior
                switch (gesture.GestureType) {

                        // on taps, we change the color of the selected sprite
                    case GestureType.Tap:
                        //case GestureType.DoubleTap:
                        if (starshipSelected) {
                            if (Math.Abs(Invasion.StarShip.SpeedX) > 2)
                                skidToAStop = true;
                            else
                                stopMovingShip = true;
                        }

                        firePressed = true;
                        break;

                        // on drags, we just want to move the selected sprite with the drag
                    case GestureType.HorizontalDrag:
                        if (starshipSelected) {
                            stopMovingShip = true;
                            Invasion.StarShip.Position += gesture.Delta;

                            // skid if switching directions
                            if (gesture.Delta.X > 0.0f) { // dragging right
                                if (Invasion.StarShip.SpeedX < 0 || lastDragDelta < 0.0f)
                                    skid = true;
                            }
                            else if (gesture.Delta.X < 0.0f) { //dragging left
                                if (Invasion.StarShip.SpeedX > 0 || lastDragDelta > 0.0f)
                                    skid = true;
                            }
                            lastDragDelta = gesture.Delta.X;
                        }
                        break;

                        // When the scoreboard is held, go to the Options menu
                    case GestureType.Hold:
                        if ((InvasionGame.Scoreboard.DisplaySide == DisplaySide.Left && touchPt.X < Scoreboard.Width) ||
                            (InvasionGame.Scoreboard.DisplaySide == DisplaySide.Right && touchPt.X >= Scoreboard.RightPos.X))
                        {
                            Invasion.currentScreen = OptionsScreen;
                        }
                        break;

                        // on flicks, we want to update the selected sprite's velocity with
                        // the flick velocity, which is in pixels per second.
                    case GestureType.Flick:
                        if (starshipSelected) {
                            if (gesture.Delta.X > 0.0f) {
                                if (Invasion.StarShip.SpeedX < 0)
                                    skid = true;
                                moveShipRight = 4;
                            }
                            else if (gesture.Delta.X < 0.0f) {
                                if (Invasion.StarShip.SpeedX > 0)
                                    skid = true;
                                moveShipLeft = 4;
                            }
                        }
                        break;
                }
            }

            // give priority to touch gesture input
            if (moveShipLeft == 0 && moveShipRight == 0 && !stopMovingShip && !skidToAStop) {

                // Handle Accelerometer Input
                var accelerometerState = Accelerometer.GetState();

                float accelX = accelerometerState.Acceleration.X;
                float accelY = accelerometerState.Acceleration.Y;

                if (accelY < -0.1f) {
                    moveShipRight = (accelY < -0.2f)? 4 : 2;

                    if (Invasion.StarShip.SpeedX < -2)
                        skid = true;
                }

                if (accelY > 0.1f) {
                    moveShipLeft = (accelY > 0.2f)? 4 : 2;

                    if (Invasion.StarShip.SpeedX > 2)
                        skid = true;
                }

                // Make very slow moving starship slow to a stop
                if (accelY >= -0.1f && accelY <= 0.1f) {
                    if (timeSinceSpeedChangeSec > minTimeBetweenSpeedChangesSec) {
                        timeSinceSpeedChangeSec = 0.0f;

                        int speed = Math.Abs(Invasion.StarShip.SpeedX);

                        if (Invasion.StarShip.SpeedX < 0) {
                            Invasion.StarShip.MoveLeft(speed-1);
                        }
                        else if (Invasion.StarShip.SpeedX > 0) {
                            Invasion.StarShip.MoveRight(speed-1);
                        }
                    }
                }
            }

            if (firePressed) {
                if (Invasion.StarShip.ShipState == ShipState.OK) {
                    Invasion.StarShip.FireWeapon();
                }
            }

            if (skidToAStop) {
                Invasion.StarShip.SkidToAStop();
            }
            else {
                if (skid)
                    Invasion.StarShip.Skid();

                if (stopMovingShip)
                    Invasion.StarShip.StopMoving();
            }

            // Move after skid/stop in case change in direction : skid, then move opposition direction
            if (moveShipLeft != 0) {
                Invasion.StarShip.MoveLeft(moveShipLeft);
            }
            else if (moveShipRight != 0) {
                Invasion.StarShip.MoveRight(moveShipRight);
            }

            if (touchPt == Menus.notTouched) {
                starshipSelected = false;
                lastDragDelta = 0.0f;
            }
        }
Example #5
0
        public void HandleInput(GameTime gameTime, InputState intouches, Game game)
        {
            Vector2 releasePt;
            Vector2 touchPt = intouches.TouchState.GetTouchPt(out releasePt);
            const int itemHeight  = 40;
            var itemRect = new Rectangle(0, 260, 800, itemHeight);

            int touchedEntry = -1;

            const int numMenuItems = 5;

            for (int menuItem = 0; menuItem < numMenuItems; menuItem++) {
                if (releasePt.X >= itemRect.Left && releasePt.X <= itemRect.Right &&
                    releasePt.Y >= (itemRect.Top + menuItem*itemHeight) && releasePt.Y <= (itemRect.Bottom + menuItem*itemHeight))
                {
                    touchedEntry = menuItem;
                    break;
                }
            }

            if (touchedEntry != -1) {
                Invasion.Option = touchedEntry;

                switch (Invasion.Option) {
                    case 0: // Play Game Menu Item
                        Invasion.currentScreen = GameplayScreen;
                        Invasion.SetupNewGame();

                        var menuSoundEffect = this.menuSoundEffect;
                        SoundManager.Instance.Play(menuSoundEffect);
                        break;

                    case 1: // Options Menu Item
                        Invasion.currentScreen = OptionsScreen;
                        Invasion.DelayStart = Environment.TickCount;
                        break;

                    case 2: // Credits Menu Item
                        Invasion.currentScreen = CreditsScreen;
                        Invasion.DelayStart = Environment.TickCount;
                        break;

                    case 3: // Help Menu Item
                        Invasion.currentScreen = HelpScreen;
                        ExtrasManager.Instance.Reset();

                        for (int iExtra = 0; iExtra < Extra.NumExtraTypes; iExtra++) {
                            Debug.WriteLine("Setting up iExtra = " + iExtra + ", Extra = " + (Extra.ExtraType)(iExtra));
                            Vector2 extraPos = new Vector2(240, HelpScreen.HelpScreenExtrasFirstRowY+HelpScreen.HelpScreenExtrasLineSpacing*iExtra);
                            Extra extra = new Extra(game, extraPos, (Extra.ExtraType)(iExtra));
                            ExtrasManager.Instance.Add(extra);
                        }

                        Invasion.DelayStart = Environment.TickCount;
                        //Debug.WriteLine("delayOffset = " + delayOffset + ", delayStart = " + delayStart);
                        break;

                    case 4: // Quit Menu Item Exits the Game
                        game.Exit();
                        break;
                }
            }
            else {
                for (int menuItem = 0; menuItem < numMenuItems; menuItem++) {

                    if (touchPt.X >= itemRect.Left && touchPt.X <= itemRect.Right &&
                        touchPt.Y >= (itemRect.Top + menuItem*itemHeight) && touchPt.Y <= (itemRect.Bottom + menuItem*itemHeight))
                    {
                        touchedEntry = menuItem;
                        break;
                    }
                }

                if (touchedEntry != -1) {
                    Invasion.Option = touchedEntry;
                }
            }
        }
Example #6
0
        public void HandleInput(GameTime gameTime, InputState intouches, Game game)
        {
            Vector2 releasePt;
            Vector2 touchPt = intouches.TouchState.GetTouchPt(out releasePt);
            _timeSinceButtonPressSec += (float)gameTime.ElapsedGameTime.TotalSeconds;

            selectedEntry = -1;
            int iEntry = -1;

            if (touchPt != Menus.notTouched) {

                if (!Invasion.GameInProgress) {
                    // Scoreboard Entry
                    Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

                    if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                        selectedEntry = iEntry;
                }

                // Game Music
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                    selectedEntry = iEntry;

                // Difficulty Level
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                    selectedEntry = iEntry;

                // Auto-Select Weapon
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                    selectedEntry = iEntry;

                // Rate & Review
                Menus.MenuItemBoundingBox.Y = Options2NdSubmenuY - 10;
                ++iEntry;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                    selectedEntry = iEntry;

                // Find our other Games
                Menus.MenuItemBoundingBox.Y = Options2NdSubmenuY + OptionsMenuItemDeltaY - 10;
                ++iEntry;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                    selectedEntry = iEntry;

                return;
            }

            if (releasePt == Menus.notTouched || _timeSinceButtonPressSec <= OptionsButtonDebounceSec)
                return;

            _timeSinceButtonPressSec = 0.0f;

            iEntry = -1;

            // Scoreboard Position
            if (!Invasion.GameInProgress) {
                Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

                if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
                {
                    InvasionGame.Scoreboard.DisplaySide = (InvasionGame.Scoreboard.DisplaySide == DisplaySide.Left)?
                                                                                                                       DisplaySide.Right : DisplaySide.Left;
                    return;
                }
            }

            // Game Music
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

            if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
            {
                InvasionGame.musicManager.Enabled = !InvasionGame.musicManager.Enabled;

                var musicManager = (MusicManager)game.Services.GetService(typeof(MusicManager));

                if (InvasionGame.musicManager.Enabled)
                    musicManager.Play(InvasionGame.gameMusic, true);

                else if (musicManager.IsGameMusicPlaying)
                    musicManager.Stop();

                return;
            }

            // Difficulty Level
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

            if (RectangleExtensions.Intersects((Rectangle) Menus.MenuItemBoundingBox, touchPt))
            {
                InvasionGame.Scoreboard.DifficultyLevel = (DifficultyLevel)(((int)InvasionGame.Scoreboard.DifficultyLevel+1)%3);
                return;
            }

            // Auto-Select Weapon
            Menus.MenuItemBoundingBox.Y = Menus.FirstOptionY + OptionsMenuItemDeltaY*(++iEntry) - 10;

            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                StarShip.AutoSelectWeapon = !StarShip.AutoSelectWeapon;
                return;
            }

            // Rate & Review
            Menus.MenuItemBoundingBox.Y = Options2NdSubmenuY - 10;

            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                try {
                    var mr = new MarketplaceReviewTask();
                    mr.Show();
                }
                catch (Exception ex) {
                    Debug.WriteLine("Exception while attempting to Show MarketplaceReviewTask:\n" + ex.Message);
                }

                return;
            }

            // Find our other Games
            Menus.MenuItemBoundingBox.Y = Options2NdSubmenuY + OptionsMenuItemDeltaY - 10;

            if (Menus.MenuItemBoundingBox.Intersects(touchPt))
            {
                try {
                    var task = new MarketplaceSearchTask
                                   {
                                       ContentType = MarketplaceContentType.Applications,
                                       SearchTerms = "ImproviSoft"
                                   };
                    task.Show();
                }
                catch (Exception ex) {
                    Debug.WriteLine("Exception while attempting to Show MarketplaceSearchTask:\n" + ex.Message);
                }

                return;
            }
        }
Example #7
0
 public void HandleInput(GameTime gameTime, InputState input, Game game)
 {
 }