Exemple #1
0
        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            Vector2 position = new Vector2(0.5f, 0.15f);

            spriteBatch.Begin();
            spriteBatch.Draw(Background, Bounds, Color.White);
            spriteBatch.Draw(Logo, GetScreenPosition(position) - new Vector2(Logo.Bounds.Width, Logo.Bounds.Height) / 2, Color.White);
            spriteBatch.End();

            foreach (var overlayTexture in OverlayTextures)
            {
                OverlayView overlay = overlayTexture.Key;
                basicEffect.World =
                    Matrix.CreateTranslation(overlay.Position.X * 0.01f, -overlay.Position.Y * 0.01f, 1.8f) *
                    Matrix.CreateRotationY(MathHelper.ToRadians(overlay.Rotation)) *
                    Matrix.CreateScale(overlay.RenderBounds.Width * 0.01f, overlay.RenderBounds.Height * 0.01f, 1f);

                basicEffect.Texture        = overlayTexture.Value;
                basicEffect.TextureEnabled = true;
                EffectPass pass = basicEffect.CurrentTechnique.Passes[0];
                pass.Apply();

                GraphicsDevice.SetVertexBuffer(vertexBuffer);
                GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }

            base.Draw(gameTime);
        }
Exemple #2
0
        public MenuView(Game game, GameState gameState) : base(game, gameState)
        {
            Overlays.Add(new MainMenu(game));
            CurrentOverlay = Overlays.First <OverlayView>();
            oldState       = GameState.MainMenu;

            ChangeResolution();

            Speed          = 10f;
            TargetRotation = -65;
        }
Exemple #3
0
        public MenuView(Game game, GameState gameState)
            : base(game, gameState)
        {
            Overlays.Add(new MainMenu(game));
            CurrentOverlay = Overlays.First<OverlayView>();
            oldState = GameState.MainMenu;

            ChangeResolution();

            Speed = 10f;
            TargetRotation = -65;
        }
Exemple #4
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);
        }
Exemple #5
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;
        }