コード例 #1
0
        protected override void doUpdate(GameTime currentTime)
        {
            stateTimer += currentTime.ElapsedGameTime.Milliseconds;

            if (stateTimer > 1500f)
            {
                if ((InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad) && !player1ConfirmPressed)
                {
                    player1ConfirmPressed = true;
                }
                else if (!(InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad) && player1ConfirmPressed)
                {
                    player1ConfirmPressed = false;

                    isComplete = true;
                }
            }

            CampaignLobbyState.lineOffset += (currentTime.ElapsedGameTime.Milliseconds * CampaignLobbyState.lineMoveSpeed);
            if (CampaignLobbyState.lineOffset > 16.0f)
            {
                CampaignLobbyState.lineOffset -= 16.0f;
            }
        }
コード例 #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
#if PROFILE
            elapsedTime += gameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromMilliseconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate    = frameCounter;
                frameCounter = 0;
            }

            if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
            {
                Thread.Sleep(5);
            }

            if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
            {
                return;
            }
#endif

#if WINDOWS
#if DEBUG
            // Allows the game to exit; win32 only
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
#endif
#endif

            if (exitGame)
            {
                this.Exit();
            }

            if (!(preloadedAssets && preloadedJSon))
            {
                InputDevice2.Update(gameTime);

                if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.RightDirection) != InputDevice2.PlayerPad.NoPad)
                {
                    shipRotation += 0.02f;
                }
                else if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.LeftDirection) != InputDevice2.PlayerPad.NoPad)
                {
                    shipRotation -= 0.02f;
                }

                if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad)
                {
                    shipVelocity += new Vector2((float)(Math.Cos(shipRotation)), (float)(Math.Sin(shipRotation))) * shipThrust;
                    shipVelocity  = Vector2.Clamp(shipVelocity, new Vector2(-0.91f), new Vector2(0.91f));
                }

                shipPosition += shipVelocity * gameTime.ElapsedGameTime.Milliseconds;
                shipVelocity *= 0.99f;

                if (shipPosition.X < -1850)
                {
                    shipPosition.X = 1850;
                }
                if (shipPosition.X > 1850)
                {
                    shipPosition.X = -1850;
                }
                if (shipPosition.Y < -1300)
                {
                    shipPosition.Y = 1300;
                }
                if (shipPosition.Y > 1300)
                {
                    shipPosition.Y = -1300;
                }

                return;
            }

            gameIsRunningSlowly = gameTime.IsRunningSlowly;

            if (currentGameScreen.IsComplete)
            {
                currentGameScreen = ScreenState.SwitchToNewScreen(currentGameScreen.nextLevelState());
            }

            InputDevice2.Update(gameTime);

            currentGameScreen.update(gameTime);

            base.Update(gameTime);
        }
コード例 #3
0
        private void gameLogicUpdate(Microsoft.Xna.Framework.GameTime currentTime)
        {
            if (InputDevice2.IsPlayerButtonDown(InputDevice2.PPG_Player.Player_1, InputDevice2.PlayerButton.PauseButton) && !player1Dead)
            {
                state = LoadingState.LevelPaused;
                pauseDialogMinimumTime = 0;
                pauseMenuItem          = 0;
                AudioLib.playSoundEffect("monitorOpening");
            }

            if (GameCampaign.Player_Ammunition < 0)
            {
                GameCampaign.Player_Ammunition = 0;
            }
            if (GameCampaign.Player2_Ammunition < 0)
            {
                GameCampaign.Player2_Ammunition = 0;
            }

            if (GameCampaign.Player_Ammunition > 100)
            {
                GameCampaign.Player_Ammunition = 100;
            }
            if (GameCampaign.Player2_Ammunition > 100)
            {
                GameCampaign.Player2_Ammunition = 100;
            }

            if (messageQueueState == PushMessageQueueState.Wait)
            {
                if (pushMessageQueue.Count > 0)
                {
                    messageQueueState = PushMessageQueueState.FadeIn;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.ShowMessage)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 1000f + (25 * pushMessageQueue.Peek().Length))
                {
                    messageQueueState = PushMessageQueueState.FadeOut;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.FadeIn)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 200f)
                {
                    messageQueueState = PushMessageQueueState.ShowMessage;
                    queueTimer        = 0;
                }
            }
            else if (messageQueueState == PushMessageQueueState.FadeOut)
            {
                queueTimer += currentTime.ElapsedGameTime.Milliseconds;

                if (queueTimer > 200f)
                {
                    messageQueueState = PushMessageQueueState.Wait;
                    queueTimer        = 0;
                    pushMessageQueue.Dequeue();
                }
            }

            for (int i = 0; i < entityList.Count; i++)
            {
                if (Vector2.Distance(cameraFocus.CenterPoint, entityList[i].CenterPoint) < 800 || entityList[i] is Player)
                {
                    entityList[i].update(currentTime);
                }
            }

            elapsedLevelTime += currentTime.ElapsedGameTime.Milliseconds;

            particleSet.update(currentTime);

#if WINDOWS
            entityList.RemoveAll(en => en.Remove_From_List == true);
#elif XBOX
            XboxTools.RemoveAll(entityList, XboxTools.IsEntityToBeRemoved);
            XboxTools.RemoveAll(acidSpitters, XboxTools.IsEntityToBeRemoved);
#endif

            if (cameraFocus != null)
            {
                int pointX = (int)cameraFocus.CenterPoint.X;
                int pointY = (int)cameraFocus.CenterPoint.Y;

                camera = Matrix.CreateTranslation(new Vector3((pointX * -1) + (GlobalGameConstants.GameResolutionWidth / 2), (pointY * -1) + (GlobalGameConstants.GameResolutionHeight / 2), 0.0f));
                //camera = Matrix.CreateScale(0.1f);
            }

            gui.update(currentTime);

            if (player1Dead)
            {
                fadeOutTime += currentTime.ElapsedGameTime.Milliseconds;

                gui.BlackFadeOverlay = fadeOutTime / fadeOutDuration;

                if (fadeOutTime >= fadeOutDuration)
                {
                    BackGroundAudio.stopAllSongs();
                    isComplete = true;
                }
            }

            if (endFlagReached)
            {
                BackGroundAudio.stopAllSongs();
                isComplete = true;
            }

#if DEBUG
            if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.SwitchItem2) != InputDevice2.PlayerPad.NoPad)
            {
                showStats = true;
            }
            else
            {
                showStats = false;
            }
#endif
        }
コード例 #4
0
        protected override void doUpdate(GameTime currentTime)
        {
            button_pressed_timer += currentTime.ElapsedGameTime.Milliseconds;
            fade += currentTime.ElapsedGameTime.Milliseconds;

            if (screen == titleScreens.menuScreen || screen == titleScreens.playScreen)
            {
                fade_duration = max_fade_menu_timer;
            }
            else
            {
                fade_duration = max_fade_timer;
            }

            switch (screen)
            {
            case titleScreens.introScreen:
                if (fade > max_fade_timer)
                {
                    fade       = 0.0f;
                    fade_state = (FadeState)(((int)fade_state + 1) % 3);
                    if (fade_state == FadeState.stay)
                    {
                        fade   = 0.0f;
                        screen = titleScreens.menuScreen;
                    }
                }
                break;

            /**************************************************************************************************************************/
            case titleScreens.logoScreen:
                if (fade > fade_duration)
                {
                    fade       = 0.0f;
                    fade_state = (FadeState)(((int)fade_state + 1) % 3);

                    if (fade_state == FadeState.fadeIn)
                    {
                        fade   = 0.0f;
                        screen = titleScreens.menuScreen;
                    }
                    else if (fade_state == FadeState.stay)
                    {
                        fade          = 0.0f;
                        fade_duration = logo_stay_timer;
                    }
                    else if (fade_state == FadeState.fadeOut)
                    {
                        fade          = 0.0f;
                        fade_duration = max_fade_timer;
                    }
                }
                break;

            /**************************************************************************************************************************/
            case titleScreens.menuScreen:
                if (!music_playing)
                {
                    BackGroundAudio.playSong("Menu", true);
                    music_playing = true;
                }

                if (Game1.videoPlayer.State == Microsoft.Xna.Framework.Media.MediaState.Stopped)
                {
                    Game1.videoPlayer.IsLooped = true;
                    Game1.videoPlayer.Play(Game1.titleScreenVideo);
                }


                if (fade > max_fade_menu_timer)
                {
                    fade       = 0.0f;
                    fade_state = FadeState.stay;
                    if (fade_state == FadeState.fadeIn)
                    {
                        fade   = 0.0f;
                        screen = titleScreens.menuScreen;
                    }
                }

                if (storageDevicePrompted)
                {
                    if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.DownDirection) != InputDevice2.PlayerPad.NoPad)
                    {
                        if (!down_pressed)
                        {
                            button_pressed_timer = 0.0f;
                        }

                        down_pressed = true;
                    }

                    if ((down_pressed && !(InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.DownDirection) != InputDevice2.PlayerPad.NoPad)) || (down_pressed && (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.DownDirection) != InputDevice2.PlayerPad.NoPad) && button_pressed_timer > max_button_pressed_timer))
                    {
                        down_pressed         = false;
                        button_pressed_timer = 0.0f;

                        menu_item_selected++;
                        AudioLib.playSoundEffect(menuBlipSound);
                        if (menu_item_selected >= menu_list.Count())
                        {
                            menu_item_selected = menu_item_selected % menu_list.Count();
                        }
                        else if (menu_item_selected < 0)
                        {
                            menu_item_selected += menu_list.Count();
                        }
                    }

                    if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.UpDirection) != InputDevice2.PlayerPad.NoPad)
                    {
                        if (!up_pressed)
                        {
                            button_pressed_timer = 0.0f;
                        }
                        up_pressed = true;
                    }

                    if ((up_pressed && !(InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.UpDirection) != InputDevice2.PlayerPad.NoPad)) || (up_pressed && (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.UpDirection) != InputDevice2.PlayerPad.NoPad) && button_pressed_timer > max_button_pressed_timer))
                    {
                        up_pressed           = false;
                        button_pressed_timer = 0.0f;

                        menu_item_selected--;
                        AudioLib.playSoundEffect(menuBlipSound);
                        if (menu_item_selected >= menu_list.Count())
                        {
                            menu_item_selected = menu_item_selected % menu_list.Count();
                        }
                        else if (menu_item_selected < 0)
                        {
                            menu_item_selected += menu_list.Count();
                        }
                    }

                    if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad)
                    {
                        confirm_pressed = true;

                        whoPressedConfirm = InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm);
                    }
                    else if (confirm_pressed)
                    {
                        confirm_pressed = false;

                        switch (menu_list[menu_item_selected].text)
                        {
                        case "START":
                            screen     = titleScreens.playScreen;
                            fade_state = FadeState.fadeOut;
                            fade       = 0.0f;
                            break;

                        case "OPTIONS":
                            InputDevice2.LockController(InputDevice2.PPG_Player.Player_1, whoPressedConfirm);
                            screen     = titleScreens.optionScreen;
                            fade_state = FadeState.fadeOut;
                            fade       = 0.0f;
                            break;

                        case "QUIT":
                            Game1.exitGame = true;
                            break;
                        }
                    }

                    for (int i = 0; i < menu_list.Count(); i++)
                    {
                        if (i == menu_item_selected)
                        {
                            menu_list[menu_item_selected].selected = true;
                        }
                        else
                        {
                            menu_list[i].selected = false;
                        }
                        menu_list[i].update(currentTime);
                    }
                }
                else
                {
                    if (InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm) != InputDevice2.PlayerPad.NoPad)
                    {
                        confirm_pressed = true;

                        whoPressedConfirm = InputDevice2.IsAnyControllerButtonDown(InputDevice2.PlayerButton.Confirm);
                    }
                    else if (confirm_pressed)
                    {
                        confirm_pressed = false;

                        SaveGameModule.selectStorageDevice((PlayerIndex)whoPressedConfirm);
                        SaveGameModule.loadGame();

                        storageDevicePrompted = true;
                    }
                }
                break;

            /*****************************************************************************************************/
            default:
                if (fade > max_fade_menu_timer)
                {
                    isComplete = true;
                    BackGroundAudio.stopAllSongs();
                    Game1.videoPlayer.Stop();
                }
                break;
            }
        }