public void Update(GameTime gameTime, Game1 game1)
        {
            timePast += gameTime.ElapsedGameTime;
            totalTimePast += gameTime.ElapsedGameTime;

            if (totalTimePast.TotalMilliseconds >= loadingTime)
            {
                if (!isBeforeTitleScreen) game1.ChangeGameState(GameState.Playing);

                drawCircle = false;
            }
            if ((int)(timePast.TotalMilliseconds / 20) >= loadingTex.Length)
                timePast = TimeSpan.Zero;
        }
        public void Update(GameTime gameTime, Game1 game1, MouseState state, MouseState lState, KeyboardState keystate, KeyboardState lastKeyState)
        {
            game1.IsMouseVisible = true;
            time += gameTime.ElapsedGameTime;
            soundTime += gameTime.ElapsedGameTime;
            backGroundAlphaAnimation.Update(gameTime.ElapsedGameTime);

            int lastSelected = selected;

            #region input
            if (UsedKeys["down"].isPressed() && time.TotalMilliseconds >= 200)
            {
                selected++;
                if (selected > 5)
                {
                    if (time.TotalMilliseconds >= 300)
                    {
                        selected = 1;
                        time = TimeSpan.Zero;
                    }
                    else selected = 5;
                }
                else
                    time = TimeSpan.Zero;
            }
            else if (UsedKeys["up"].isPressed() && time.TotalMilliseconds >= 200)
            {
                selected--;
                if (selected < 1)
                {
                    if (time.TotalMilliseconds >= 300)
                    {
                        selected = 5;
                        time = TimeSpan.Zero;
                    }
                    else selected = 1;
                }
                else
                    time = TimeSpan.Zero;
            }

            for (int i = 0; i < TextPositions.Length; i++)
                if (Game1.isHover(state, TextPositions[i]))
                {
                    if (state.X != lState.X || state.Y != lState.Y)
                    {
                        selected = i + 1;
                        time = TimeSpan.Zero;
                    }
                    if (UsedKeys["mouse"].isPressed())
                    {
                        Game1.PlaySound("click");
                        switch (selected)
                        {
                            case 1:
                                if (!isMainMenu)
                                {
                                    Game1.PlaySound("back");
                                    game1.ChangeGameState(GameState.Playing);
                                }
                                else
                                {
                                    if (!isFirstTime) { game1.RestartGame(); isFirstTime = false; }
                                    game1.ChangeGameState(GameState.Loading);
                                }
                                //backGroundMusic.Stop();
                                break;
                            case 4: if (!isMainMenu) game1.ChangeGameState(GameState.Menu);
                                break;
                            case 5: game1.ExitGame();
                                break;
                        }
                    }
                }

            if (UsedKeys["enter"].isPressed())
            {
                if (!(selected == 1 && !isMainMenu)) Game1.PlaySound("click");
                switch (selected)
                {
                    case 1:
                        if (!isMainMenu)
                        {
                            Game1.PlaySound("back");
                            game1.ChangeGameState(GameState.Playing);
                        }
                        else
                        {
                            if (!isFirstTime) { game1.RestartGame(); isFirstTime = false; }
                            game1.ChangeGameState(GameState.Loading);
                        }
                        //backGroundMusic.Stop();
                        break;
                    case 4: if (!isMainMenu) game1.ChangeGameState(GameState.Menu);
                        break;
                    case 5: game1.ExitGame();
                        break;
                }
            }
            #endregion

            if (soundTime.TotalMilliseconds >= 20)
                if (lastSelected != selected)
                {
                    Game1.PlaySound("button");
                    soundTime = TimeSpan.Zero;
                }

            if (!isMainMenu)
                if (UsedKeys["escape"].isPressed())
                {
                    Game1.PlaySound("back");
                    game1.ChangeGameState(GameState.Playing);
                }
            foreach (KeyValuePair<string, Key> key in UsedKeys)
            {
                if (key.Key != "mouse") key.Value.Update(keystate, lastKeyState);
                else key.Value.Update(state, lState);
            }
        }
        public void Update(GameTime gameTime, Game1 game1, MouseState mouseState, KeyboardState keyboardState)
        {
            if (gameTime.TotalGameTime.TotalMilliseconds >= LoadingTime - 500)
            {
                if (counter < TimeSpan.FromMilliseconds(1000)) counter += gameTime.ElapsedGameTime;
                if (counter > TimeSpan.FromMilliseconds(1000))
                {
                    if (isAdding) PressAlpha += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;
                    else PressAlpha -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2;

                    if (PressAlpha > 255 | PressAlpha < 0)
                    {
                        if (!isAdding) counter = TimeSpan.Zero;
                        isAdding = !isAdding;
                    }
                }
            }
            if (gameTime.TotalGameTime.TotalMilliseconds < LoadingTime) loading.Update(gameTime, game1);

            if (!(timePressed.TotalMilliseconds < DummyTimeSpan.TotalMilliseconds) && gameTime.TotalGameTime.TotalMilliseconds >= LoadingTime + TimeBeforeUserCanContinue && (keyboardState.GetPressedKeys().Length > 0 || mouseState.LeftButton == ButtonState.Pressed))
            {
                timePressed = gameTime.TotalGameTime;
                Game1.PlaySound("back");
            }
            if (gameTime.TotalGameTime.TotalMilliseconds - timePressed.TotalMilliseconds >= TimeToWaitAfterPressed)
                isGoingToMenu = true;

            if (isGoingToMenu)
            {
                logoAnimation += gameTime.ElapsedGameTime;
                if (logoAnimation.TotalMilliseconds >= timeBeforeMoving + logoMoveTime + timeAfterAnimation) game1.ChangeGameState(GameState.Menu); // animation finished
            }
        }
示例#4
0
 static void Main(string[] args)
 {
     using (Game1 game = new Game1())//System.Windows.Forms.MessageBox.Show("Open In Full Screen ?", "", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes))
     {
         game.Run();
     }
 }
        private void HandleInput(GameTime gameTime, KeyboardState keyboardState, KeyboardState lastKeyboardState, MouseState mouseState, Game1 game1)
        {
            //Debugging Stop Point
            if (keyboardState.IsKeyDown(Keys.P))
            { }

            #region keyboard

            if (UsedKeys["o"].isPressed())
                showFPS = !showFPS;
            if (UsedKeys["i"].isPressed())
                showBoundingBox = !showBoundingBox;
            if (UsedKeys["u"].isPressed())
                camera.canJump = !camera.canJump;
            if (UsedKeys["y"].isPressed())
                camera.canCrouch = !camera.canCrouch;

            #region game
            Vector3 moveVector = new Vector3(0, 0, 0);

            if (UsedKeys["w"].isPressed())
                moveVector += new Vector3(0, 0, -1);
            if (UsedKeys["s"].isPressed())
                moveVector += new Vector3(0, 0, 1);
            if (UsedKeys["d"].isPressed())
                moveVector += new Vector3(1, 0, 0);
            if (UsedKeys["a"].isPressed())
                moveVector += new Vector3(-1, 0, 0);

            moveVector *= (float)gameTime.ElapsedGameTime.TotalMilliseconds / 100.0f;

            if (camera.canCrouch && !camera.isJumping)
            {
                if (keyboardState.IsKeyDown(Keys.LeftControl))
                    camera.isCrouched = true;
                else
                    camera.isCrouched = false;
            }

            if (camera.canJump && UsedKeys["space"].isPressed() && !camera.isJumping && !camera.isCrouched)
            {
                camera.isJumping = true;
                camera.jumpspeed = 4;
            }
            camera.UpdatePosition(moveVector, room.bBoxManager.boundingBoxes, gameTime, this);
            #endregion

            #endregion

            #region mouse
            float amount = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
            if (mouseState.X != screenCenter.X && !camera.isAnimating)
            {
                camera.yaw -= camera.YrotationSpeed * (mouseState.X - screenCenter.X) * amount;
            }
            if (mouseState.Y != screenCenter.Y && !camera.isAnimating)
            {
                camera.pitch -= camera.XrotatiobSpeed * (mouseState.Y - screenCenter.Y) * amount;
                if (camera.pitch > MathHelper.ToRadians(90))
                    camera.pitch = MathHelper.ToRadians(90);
                if (camera.pitch < MathHelper.ToRadians(-60))
                    camera.pitch = MathHelper.ToRadians(-60);
            }
            Mouse.SetPosition((int)screenCenter.X, (int)screenCenter.Y);

            if (UsedKeys["mouse"].isPressed())
            {
                if (teleporter.isOnPlayer) teleporter.Throw(camera.position, camera.yaw, camera.pitch);
                else teleporter.Teleport(ref camera.position);
            }
            if (UsedKeys["lmouse"].isPressed())
            {
                if (!teleporter.isOnPlayer) teleporter.ReturnToHand();
            }
            #endregion

            if (UsedKeys["escape"].isPressed())
                game1.ChangeGameState(GameState.EscMenu);
        }
        public void Update(GameTime gameTime, KeyboardState keyboardState, KeyboardState lastKeyboardState, MouseState mouseState, MouseState lastMouseState, Game1 game1)
        {
            HandleInput(gameTime, keyboardState, lastKeyboardState, mouseState, game1);
            camera.UpdateView();
            teleporter.Update(gameTime);
            game1.IsMouseVisible = false;

            foreach (KeyValuePair<string, Key> key in UsedKeys)
            {
                if (key.Key != "mouse" && key.Key != "lmouse") key.Value.Update(keyboardState, lastKeyboardState);
                else key.Value.Update(mouseState, lastMouseState);
            }

            #region blink
            if (timeBeforeStart.TotalMilliseconds >= MiSe_BeforeStart)
            {
                blink.Update(gameTime.ElapsedGameTime);
            }
            else
            {
            }
            #endregion

            game1.Window.Title = camera.position + "    " + camera.yaw + "," + camera.pitch;
        }
示例#7
0
        public void Update(GameTime gameTime, Game1 game1, MouseState state, MouseState lState, KeyboardState keystate, KeyboardState lastKeyState)
        {
            game1.IsMouseVisible = true;
            time      += gameTime.ElapsedGameTime;
            soundTime += gameTime.ElapsedGameTime;
            backGroundAlphaAnimation.Update(gameTime.ElapsedGameTime);


            int lastSelected = selected;

            #region input
            if (UsedKeys["down"].isPressed() && time.TotalMilliseconds >= 200)
            {
                selected++;
                if (selected > 5)
                {
                    if (time.TotalMilliseconds >= 300)
                    {
                        selected = 1;
                        time     = TimeSpan.Zero;
                    }
                    else
                    {
                        selected = 5;
                    }
                }
                else
                {
                    time = TimeSpan.Zero;
                }
            }
            else if (UsedKeys["up"].isPressed() && time.TotalMilliseconds >= 200)
            {
                selected--;
                if (selected < 1)
                {
                    if (time.TotalMilliseconds >= 300)
                    {
                        selected = 5;
                        time     = TimeSpan.Zero;
                    }
                    else
                    {
                        selected = 1;
                    }
                }
                else
                {
                    time = TimeSpan.Zero;
                }
            }

            for (int i = 0; i < TextPositions.Length; i++)
            {
                if (Game1.isHover(state, TextPositions[i]))
                {
                    if (state.X != lState.X || state.Y != lState.Y)
                    {
                        selected = i + 1;
                        time     = TimeSpan.Zero;
                    }
                    if (UsedKeys["mouse"].isPressed())
                    {
                        Game1.PlaySound("click");
                        switch (selected)
                        {
                        case 1:
                            if (!isMainMenu)
                            {
                                Game1.PlaySound("back");
                                game1.ChangeGameState(GameState.Playing);
                            }
                            else
                            {
                                if (!isFirstTime)
                                {
                                    game1.RestartGame(); isFirstTime = false;
                                }
                                game1.ChangeGameState(GameState.Loading);
                            }
                            //backGroundMusic.Stop();
                            break;

                        case 4: if (!isMainMenu)
                            {
                                game1.ChangeGameState(GameState.Menu);
                            }
                            break;

                        case 5: game1.ExitGame();
                            break;
                        }
                    }
                }
            }

            if (UsedKeys["enter"].isPressed())
            {
                if (!(selected == 1 && !isMainMenu))
                {
                    Game1.PlaySound("click");
                }
                switch (selected)
                {
                case 1:
                    if (!isMainMenu)
                    {
                        Game1.PlaySound("back");
                        game1.ChangeGameState(GameState.Playing);
                    }
                    else
                    {
                        if (!isFirstTime)
                        {
                            game1.RestartGame(); isFirstTime = false;
                        }
                        game1.ChangeGameState(GameState.Loading);
                    }
                    //backGroundMusic.Stop();
                    break;

                case 4: if (!isMainMenu)
                    {
                        game1.ChangeGameState(GameState.Menu);
                    }
                    break;

                case 5: game1.ExitGame();
                    break;
                }
            }
            #endregion

            if (soundTime.TotalMilliseconds >= 20)
            {
                if (lastSelected != selected)
                {
                    Game1.PlaySound("button");
                    soundTime = TimeSpan.Zero;
                }
            }

            if (!isMainMenu)
            {
                if (UsedKeys["escape"].isPressed())
                {
                    Game1.PlaySound("back");
                    game1.ChangeGameState(GameState.Playing);
                }
            }
            foreach (KeyValuePair <string, Key> key in UsedKeys)
            {
                if (key.Key != "mouse")
                {
                    key.Value.Update(keystate, lastKeyState);
                }
                else
                {
                    key.Value.Update(state, lState);
                }
            }
        }