コード例 #1
0
        public override GameState UpdateState(GameTime gameTime)
        {
            //rotation += (float)gameTime.ElapsedGameTime.TotalSeconds * .5f;
            //car.Speed = ((float)Math.Sin(gameTime.TotalGameTime.TotalSeconds) + 2f) * 1.5f;
            //car.Update();

            InputComponent input = Game.GetService <InputComponent>();
            int            i     = availableColors.FindIndex(0, c => c == diffuseColor);

            if (input.GetKey(Keys.Left))
            {
                i--;
                if (i < 0)
                {
                    i = availableColors.Count - 1;
                }
            }
            else if (input.GetKey(Keys.Right))
            {
                i = (++i % availableColors.Count);
            }

            diffuseColor = availableColors[i];
            GameSettings.Default.CarColor = diffuseColor;

            GameState state = base.UpdateState(gameTime);

            if (state != this.gameState)
            {
                GameSettings.Default.Save();
            }
            return(state);
        }
コード例 #2
0
        public override GameState UpdateState(GameTime gameTime)
        {
            InputComponent input         = gameInstance.GetService <InputComponent>();
            GameState      nextGameState = GameState.None;

            if (input.GetKey(Keys.Down))
            {
                var index = selectedIndex;
                do
                {
                    selectedIndex++;
                } while (selectedIndex < MenuItems.Count && !MenuItems[selectedIndex].Selectable);

                if (selectedIndex > MenuItems.Count - 1)
                {
                    selectedIndex = index;
                }
                AudioEngineManager.PlaySound("menutick");
            }
            else if (input.GetKey(Keys.Up))
            {
                var index = selectedIndex;
                do
                {
                    selectedIndex--;
                } while (selectedIndex >= 0 && !MenuItems[selectedIndex].Selectable);

                if (selectedIndex < 0)
                {
                    selectedIndex = index;
                }
                AudioEngineManager.PlaySound("menutick");
            }
            else if (input.GetKey(Keys.Right) && MenuItems[selectedIndex] is OptionMenuItem)
            {
                (MenuItems[selectedIndex] as OptionMenuItem).NextOption();
            }
            else if (input.GetKey(Keys.Left) && MenuItems[selectedIndex] is OptionMenuItem)
            {
                (MenuItems[selectedIndex] as OptionMenuItem).PreviousOption();
            }
            else if (input.GetKey(Keys.Enter) && MenuItems[selectedIndex] is StateActionMenuItem)
            {
                nextGameState = (MenuItems[selectedIndex] as StateActionMenuItem).NextState;
            }
            else if (input.GetKey(Keys.Enter) && MenuItems[selectedIndex] is ActionMenuItem)
            {
                (MenuItems[selectedIndex] as ActionMenuItem).PerformAction();
            }
            return(nextGameState != GameState.None ? nextGameState : this.gameState);
        }
コード例 #3
0
        public override GameState UpdateState(GameTime gameTime)
        {
            Vector2 direction = TargetPosition - CurrentOverlay.Position;

            if (direction.Length() > 5f)
            {
                //direction.Normalize();
                Vector2 d = direction * Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                CurrentOverlay.OffsetPosition(d);
            }

            for (int i = 0; i < Overlays.Count; i++)
            {
                OverlayView overlay     = Overlays[i];
                float       rotationDir = TargetRotation * (i + rotationOffset) - overlay.Rotation;
                if (Math.Abs(rotationDir) > 0.01f)
                {
                    overlay.Rotation += rotationDir * 10 * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }

            InputComponent input = gameInstance.GetService <InputComponent>();

            if (input.GetKey(Keys.PageUp))
            {
                rotationOffset += 1;
            }
            if (input.GetKey(Keys.PageDown))
            {
                rotationOffset -= 1;
            }

            GameState state = CurrentOverlay.UpdateState(gameTime);


            if (state != oldState)
            {
                // If the new game state is the previous one
                if (Overlays.Count > 1 && Overlays[1].gameState == state)
                {
                    Overlays.RemoveAt(0);
                    CurrentOverlay = Overlays.First <OverlayView>();
                    ChangeResolution();
                }
                else
                {
                    if (state == GameState.MainMenu)
                    {
                        Overlays.Insert(0, new MainMenu(Game));
                        CurrentOverlay = Overlays.First <OverlayView>();
                        ChangeResolution();
                        ResetMenu();
                    }
                    else if (state == GameState.MultiplayerMenu)
                    {
                        Overlays.Insert(0, new MultiplayerMenu(Game));
                        CurrentOverlay = Overlays.First <OverlayView>();
                        ChangeResolution();
                        ResetMenu();
                    }
                    else if (state == GameState.OptionsMenu)
                    {
                        Overlays.Insert(0, new OptionsMenu(Game));
                        CurrentOverlay = Overlays.First <OverlayView>();
                        ChangeResolution();
                        ResetMenu();
                    }
                    else if (state == GameState.CarChooser)
                    {
                        Overlays.Insert(0, new CarChooser(Game));
                        CurrentOverlay = Overlays.First <OverlayView>();
                        ChangeResolution();
                        ResetMenu();
                    }
                    else
                    {
                        if (state == GameState.Gameplay)
                        {
                            GameModeChoice choice;
                            int?           seed;
                            if (Overlays.Count - 2 >= 0 && Overlays[Overlays.Count - 2] is MultiplayerMenu)
                            {
                                choice = GameModeChoice.Multiplayer;
                                seed   = Game.GetService <ServerClient>().Seed;
                            }
                            else
                            {
                                choice = GameModeChoice.SimpleRace;
                                seed   = (int)DateTime.UtcNow.Ticks;
                            }

                            Game.Components.Add(new GamePlayView(Game, seed, choice));
                            return(GameState.Gameplay);
                        }
                        return(state);
                    }
                }
            }
            oldState = state;


            UpdateRenders();


            return(GameState.MainMenu);
        }
コード例 #4
0
        public override void Update()
        {
            if (_input == null)
            {
                return;
            }

            base.Update();
            if (IsGrounded)
            {
                if (_input.GetKey(SDL.SDL_Keycode.SDLK_UP) &&
                    _input.GetKey(SDL.SDL_Keycode.SDLK_DOWN))
                {
                    _v = 0;
                }
                else if (_input.GetKey(SDL.SDL_Keycode.SDLK_DOWN))
                {
                    _v = 1;
                }
                else if (_input.GetKey(SDL.SDL_Keycode.SDLK_UP))
                {
                    _v = -1;
                }
                else
                {
                    _v = 0;
                }

                if (_input.GetKey(SDL.SDL_Keycode.SDLK_LEFT) &&
                    _input.GetKey(SDL.SDL_Keycode.SDLK_RIGHT))
                {
                    _h = 0;
                }
                else if (_input.GetKey(SDL.SDL_Keycode.SDLK_LEFT))
                {
                    _h = -1;
                }
                else if (_input.GetKey(SDL.SDL_Keycode.SDLK_RIGHT))
                {
                    _h = 1;
                }
                else
                {
                    _h = 0;
                }

                /*if (_input.GetKey(SDL.SDL_Keycode.SDLK_SPACE))
                 * {
                 *  dateTime1 = DateTime.Now;
                 *  IsGrounded = false;
                 * }*/

                if (_h != 0 || _v != 0)
                {
                    if (_h < 0)
                    {
                        flip = 'v';
                    }
                    else if (_h > 0)
                    {
                        flip = 'n';
                    }
                    _animate.SetAnimation("running", flip);
                }
                else
                {
                    _animate.SetAnimation("idle", flip);
                }
                _transform.Position.x += _h;
                _transform.Position.y += _v;
            }
        }