/// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            AudioEngineManager.GetInstance();

            base.LoadContent();
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            checkpointRasterization = raceTrack.GetCurveRasterization(checkpoints);

            List <AbstractTrigger> checkpointTriggers = new List <AbstractTrigger>();

            for (int i = 0; i < checkpoints; i++)
            {
                PositionTrigger trigger     = new PositionTrigger(checkpointRasterization, i, true, true);
                string          outputDebug = "Passing checkpoint " + i;
                trigger.Triggered += (sender, e) =>
                {
                    Console.WriteLine(outputDebug);

                    var now = DateTime.Now;
                    if (lastCheckpointPass != DateTime.MinValue)
                    {
                        gameInstance.GetService <HUDComponent>().ShowTextNotification(Color.BurlyWood, (now - lastCheckpointPass).ToString(@"m\:ss\:ff"));
                    }
                    lastCheckpointPass = now;

                    var current  = states[CurrentState];
                    var aTrigger = sender as AbstractTrigger;
                    if (e.Object == car && current.Triggers.ContainsKey(aTrigger))
                    {
                        current.Triggers[aTrigger] = e;
                    }
                    AudioEngineManager.PlaySound("passfinishline");
                };

                string checkpointID = "checkpoint" + i;
                gameInstance.GetService <TriggerManager>().Triggers.Add(checkpointID, trigger);
                checkpointTriggers.Add(trigger);
                addedTriggers.Add(checkpointID);
            }

            // Keep track of times when passing goal line
            var goalTrigger = checkpointTriggers[0];

            goalTrigger.Triggered += (sender, e) =>
            {
                goalLineTimes.Add(e.Time.TotalGameTime);
                var    player       = gameInstance.GetService <Player>();
                string notification = (++player.Lap) > laps ? "Race finished!" : "Lap " + (player.Lap);
                gameInstance.GetService <HUDComponent>().ShowTextNotification(Color.Teal, notification);
            };

            for (int i = 0; i < laps; i++)
            {
                List <AbstractTrigger> lapTriggers = new List <AbstractTrigger>();
                lapTriggers.AddRange(checkpointTriggers);

                states.Add(new GameModeState(lapTriggers));
            }

            // Add state for passing the finish line
            states.Add(new GameModeState(checkpointTriggers.GetRange(index: 0, count: 1)));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public void StartRenderer(int WindowWidth, int WindowHeight, string WindowTitle, Type executingType,
                                  LuminalFlags Flags = 0, IImGuiTheme theme = null)
        {
            Log.Info($"--- Luminal Engine ---\nStarting at {WindowWidth} x {WindowHeight} (\"{WindowTitle}\")\nExecuting application: {executingType.Name}\n");

            Width  = WindowWidth;
            Height = WindowHeight;

            EngineFlags = Flags;

            var config = LuminalConfigLoader.LoadConfig("Luminal.json");

            AudioEngineManager.LoadEngine(config.AudioPlugin);

            sceneManager = new SceneManager(executingType);
            //sceneManager.SwitchScene("Dummy");

            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MAJOR_VERSION, 2);
            SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_MINOR_VERSION, 1);

            Window = SDL.SDL_CreateWindow(WindowTitle, 200, 200, WindowWidth, WindowHeight,
                                          SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL);
            //Renderer = SDL.SDL_CreateRenderer(Window, 0, SDL.SDL_RendererFlags.SDL_RENDERER_ACCELERATED);

            var winid = SDL.SDL_GetWindowID(Window);

            SDL_GPU.GPU_SetInitWindow(winid);

            Context.SetColour(255, 255, 255, 255);

            Log.Info("Loading SDL2_ttf");
            SDL_ttf.TTF_Init();

            Log.Info("Loading SDL2_image");
            SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_JPG | SDL_image.IMG_InitFlags.IMG_INIT_PNG |
                               SDL_image.IMG_InitFlags.IMG_INIT_TIF | SDL_image.IMG_InitFlags.IMG_INIT_WEBP);

            SDL_GPU.GPU_SetPreInitFlags(GPU_InitFlagEnum.GPU_INIT_DISABLE_VSYNC);

            //Screen = SDL_GPU.GPU_Init((uint)Width, (uint)Height, (uint)(SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL));

            var winflags = SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL;

            Screen = SDL_GPU.GPU_InitRenderer(GPU_RendererEnum.GPU_RENDERER_OPENGL_3, (uint)Width, (uint)Height, (uint)winflags);
            SDL_GPU.GPU_SetDefaultAnchor(0, 0);

            //GlContext = SDL.SDL_GL_CreateContext(Window);

            if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
            {
                Log.Info("Enabling user-defined OpenGL and Dear IMGUI.");
                OpenGLManager.Initialise();
                theme ??= new LuminalTheme();
                theme.InitTheme(ImGui.GetStyle(), ImGui.GetIO());
                OpenGLManager.ImGuiCreateFontAtlas();
            }

            if (OnLoading != null)
            {
                OnLoading(this);
            }

            //var sdlResult = SDL.SDL_CreateWindowAndRenderer(WindowWidth, WindowHeight, 0, out Renderer, out Window);
            //Console.WriteLine($"{sdlResult}");
            //SDL.SDL_SetWindowTitle(Window, WindowTitle);

            //Window.SetFramerateLimit(500);

            if (OnFinishedLoad != null)
            {
                OnFinishedLoad(this);
            }
            WindowOpen = true;

            sfClock = new Clock();

            while (WindowOpen)
            {
                //SDL.SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255);
                //SDL.SDL_RenderClear(Renderer);
                //SDL.SDL_SetRenderDrawColor(Renderer, 255, 255, 255, 255);

                SDL_GPU.GPU_ClearColor(Screen, Context.MakeColourFromRGBA(0, 0, 0, 255));

                GUIManager.Begin();

                if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                {
                    OpenGLManager.BeforeFrame();
                }

                if (OnGUI != null)
                {
                    OnGUI(this);
                }

                if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                {
                    OpenGLManager.AfterGUI();
                }

                SDL.SDL_Event evt;
                while (SDL.SDL_PollEvent(out evt) == 1)
                {
                    if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                    {
                        OpenGLManager.ImGuiHandleEvent(evt);
                    }

                    switch (evt.type)
                    {
                    case SDL.SDL_EventType.SDL_QUIT:
                        WinClose();
                        break;

                    case SDL.SDL_EventType.SDL_KEYDOWN:
                        var e = evt.key.keysym.scancode;
                        WinKeyDown(e);
                        break;

                    case SDL.SDL_EventType.SDL_KEYUP:
                        var k = evt.key.keysym.scancode;
                        WinKeyUp(k);
                        break;

                    case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                        var m = evt.button.button;
                        MouseButtonDown(m, evt.button.x, evt.button.y);
                        break;

                    case SDL.SDL_EventType.SDL_MOUSEBUTTONUP:
                        var u = evt.button.button;
                        MouseButtonUp(u, evt.button.x, evt.button.y);
                        break;

                    case SDL.SDL_EventType.SDL_MOUSEMOTION:
                        var d = evt.motion;
                        MouseDrag(d.x, d.y, d.xrel, d.yrel);
                        break;
                    }
                }

                var t = sfClock.Restart();

                AudioEngineManager.Engine.Update(t.AsSeconds());

                if (sceneManager.ActiveScene != null)
                {
                    sceneManager.ActiveScene.Update(this, t.AsSeconds());
                }

                if (OnUpdate != null)
                {
                    OnUpdate(this, t.AsSeconds());
                }

                if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                {
                    OpenGLManager.Update(t.AsSeconds());
                }

                if (OnEarlyDraw != null)
                {
                    OnEarlyDraw(this);
                }

                if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                {
                    OpenGLManager.EarlyDraw();
                }

                if (OnDraw != null)
                {
                    OnDraw(this);
                }

                if (sceneManager.ActiveScene != null)
                {
                    sceneManager.ActiveScene.Draw(this);
                }

                if (OnLateDraw != null)
                {
                    OnLateDraw(this);
                }

                GUIManager.RenderAll();

                SDL_GPU.GPU_ResetRendererState();

                //SDL.SDL_RenderPresent(Renderer);

                if ((Flags | LuminalFlags.ENABLE_USER_OPENGL) > 0)
                {
                    OpenGLManager.Draw();
                }

                SDL_GPU.GPU_Flip(Screen);

                GUIManager.End();

                //SDL.SDL_Delay(1);
            }
        }