Ejemplo n.º 1
0
        private static void InitializeStateManager()
        {
            //Construct
            stateManager = new StateManager();

            //Bind events
            stateManager.OutOfStates += (sender, i) => window?.Close();

            //Define starting state
            stateManager.EnterState(new SplashScreenState());
        }
Ejemplo n.º 2
0
        private void ClearInterface()
        {
            // Очищаем алгоритм
            algorithmController.ClearAlgorithm();

            // Закрываем окна
            algorithmForms.ForEach(form => form?.Close());
            renderWindow?.Close();
            sfmlForm?.Close();
            planForm?.Close();

            // Очищаем пункты меню алгоритмов
            algorithmsToolStripMenuItem.DropDownItems.Clear();
        }
Ejemplo n.º 3
0
        public void Run()
        {
            if (Running)
            {
                throw new InvalidOperationException("Run() was already called before.");
            }

            Running = true;

            while (Running)
            {
                if (RenderWindow == null)
                {
                    continue;
                }

                Tick();
            }

            RenderWindow?.Close();
            Exiting();
        }
Ejemplo n.º 4
0
 private void Window_Closed(object sender, EventArgs e)
 {
     tokenSource.Cancel();
     window.Close();
 }
Ejemplo n.º 5
0
 public void Close()
 {
     renderWindow.Close();
 }
Ejemplo n.º 6
0
 private void RenderWindow_Closed(object sender, EventArgs e)
 {
     _win?.Close();
 }
Ejemplo n.º 7
0
 public void Quit()
 {
     Window.Close();
 }
Ejemplo n.º 8
0
        public DoomApplication(CommandLineArgs args)
        {
            config = new Config(ConfigUtilities.GetConfigPath());

            try
            {
                config.video_screenwidth  = Math.Clamp(config.video_screenwidth, 320, 3200);
                config.video_screenheight = Math.Clamp(config.video_screenheight, 200, 2000);
                var videoMode = new VideoMode((uint)config.video_screenwidth, (uint)config.video_screenheight);
                var style     = Styles.Close | Styles.Titlebar;
                if (config.video_fullscreen)
                {
                    style = Styles.Fullscreen;
                }
                window = new RenderWindow(videoMode, ApplicationInfo.Title, style);
                window.Clear(new Color(64, 64, 64));
                window.Display();

                if (args.deh.Present)
                {
                    DeHackEd.ReadFiles(args.deh.Value);
                }

                resource = new CommonResource(GetWadPaths(args));

                DeHackEd.ReadDeHackEdLump(resource.Wad);

                renderer = new SfmlRenderer(config, window, resource);

                if (!args.nosound.Present && !args.nosfx.Present)
                {
                    sound = new SfmlSound(config, resource.Wad);
                }

                if (!args.nosound.Present && !args.nomusic.Present)
                {
                    music = ConfigUtilities.GetSfmlMusicInstance(config, resource.Wad);
                }

                userInput = new SfmlUserInput(config, window, !args.nomouse.Present);

                events = new List <DoomEvent>();

                options             = new GameOptions();
                options.GameVersion = resource.Wad.GameVersion;
                options.GameMode    = resource.Wad.GameMode;
                options.MissionPack = resource.Wad.MissionPack;
                options.Renderer    = renderer;
                options.Sound       = sound;
                options.Music       = music;
                options.UserInput   = userInput;

                menu = new DoomMenu(this);

                opening = new OpeningSequence(resource, options);

                cmds = new TicCmd[Player.MaxPlayerCount];
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    cmds[i] = new TicCmd();
                }
                game = new DoomGame(resource, options);

                wipe   = new WipeEffect(renderer.WipeBandCount, renderer.WipeHeight);
                wiping = false;

                currentState = ApplicationState.None;
                nextState    = ApplicationState.Opening;
                needWipe     = false;

                sendPause = false;

                quit        = false;
                quitMessage = null;

                CheckGameArgs(args);

                window.Closed      += (sender, e) => window.Close();
                window.KeyPressed  += KeyPressed;
                window.KeyReleased += KeyReleased;

                if (!args.timedemo.Present)
                {
                    window.SetFramerateLimit(35);
                }

                mouseGrabbed = false;
            }
            catch (Exception e)
            {
                Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
Ejemplo n.º 9
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Function called when the red cross of the application is hit.
        /// </summary>
        public static void OnClosed(object sender, EventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;

            window.Close();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Function called when the window is closed
 /// </summary>
 static void OnClosed(object sender, EventArgs e)
 {
     m_Window.Close();
 }
Ejemplo n.º 11
0
 private static void WindowCloser(object sender, EventArgs e)
 {
     window.Close();
 }
Ejemplo n.º 12
0
        /*
         * -1 - exit game
         * 0 - main menu
         * 1 - options
         * 2 - level select
         * 3 - arena
         * 4 - result
         */


        public static void Main()
        {
            CurrentState = 3;
            ScreenWidth  = VideoMode.DesktopMode.Width;
            ScreenHeight = VideoMode.DesktopMode.Height;
            Window       = new RenderWindow(new VideoMode(ScreenWidth, ScreenHeight), Title, Styles.Fullscreen);
            Window.SetMouseCursorVisible(true);
            Window.Closed += Window_Closed;

            var sound = new Sound
            {
                SoundBuffer = new SoundBuffer("res/music/mainTrack.flac"),
                Loop        = true
            };

            sound.Play();

            var model = new SceneModel(40, 40);
            var view  = new View();

            SceneModel.PlayerUnits.Add(new Base(new Vector2f(1, 1), true));
            SceneModel.PlayerUnits.Add(new Tank(new Vector2f(6, 1), true));
            SceneModel.PlayerUnits.Add(new Tank(new Vector2f(1, 4), true));
            SceneModel.PlayerUnits.Add(new Scout(new Vector2f(12, 12), true));
            SceneModel.PlayerUnits.Add(new Scout(new Vector2f(1, 8), true));

            SceneModel.EnemyUnits.Add(new Base(new Vector2f(39, 39), false));
            SceneModel.EnemyUnits.Add(new Tank(new Vector2f(32, 39), false));
            SceneModel.EnemyUnits.Add(new Tank(new Vector2f(39, 32), false));
            SceneModel.EnemyUnits.Add(new Tank(new Vector2f(34, 34), false));
            SceneModel.EnemyUnits.Add(new Tank(new Vector2f(35, 37), false));
            SceneModel.EnemyUnits.Add(new Tank(new Vector2f(37, 35), false));

            var menu = new MenuPage();

            while (Window.IsOpen)
            {
                Window.DispatchEvents();
                Window.Clear(Color.Black);

                switch (CurrentState)
                {
                case -1:
                    Window.Close();
                    break;

                case 0:
                    menu.Update();
                    menu.Display(Window);
                    break;

                case 1:
                    CurrentState = 0;
                    break;

                case 2:
                    CurrentState = 0;
                    break;

                case 3:
                    model.Update(0.1f);
                    view.Display(Window);
                    break;

                case 4:
                    CurrentState = 0;
                    break;
                }

                Window.Display();
            }
        }
Ejemplo n.º 13
0
 static void Window_Closed(object sender, EventArgs e)
 {
     Window.Close();
 }
Ejemplo n.º 14
0
        private static void Main(string[] args)
        {
            //Window set up.
            Window = new RenderWindow(new VideoMode(550, 104), "Smus", Styles.None);
            Window.SetFramerateLimit(61);
            Window.GainedFocus        += (o, e) => { WindowFocused = true; };
            Window.LostFocus          += (o, e) => { WindowFocused = false; };
            Window.MouseButtonPressed += (o, e) =>
            {
                //Hack to fix window focus.
                if (!WindowFocused)
                {
                    Window.Position += new Vector2i(0, 0);
                }
            };

            //Make sure the window can close properly.
            Window.Closed += (o, e) => Window.Close();
            Window.Closed += (o, e) => { if (Audio.Engine != null)
                                         {
                                             Audio.Engine.Dispose();
                                         }
            };
            Window.Closed += (o, e) => IsRunning = false;

            //Get bin directory.
            var ass = Assembly.GetExecutingAssembly();

            AssPath = Path.GetDirectoryName(ass.Location);

            //Initialize Audio
            Audio.StartEngine();

            //Config
            Config.PopulateConfig(AssPath + "/Resources/Config/config.xml");

            //SpriteBatch/Atlas
            AtlasData   = new AtlasData(AssPath + "/Resources/Textures/Atlas");
            SpriteBatch = new SpriteBatch(AtlasData.AtlasTexture);

            //Container
            var moduleContainer = new ModuleContainer();

            //Modules
            LoadModules(moduleContainer);

            //Update SpriteBatch
            SpriteBatch.SortZ();
            SpriteBatch.CalculateVertices();

            //Main loop
            while (IsRunning)
            {
                Window.DispatchEvents();
                if (!WindowFocused)
                {
                    Thread.Sleep(200); //Doesn't need to run as smooth.
                }
                Window.Clear(Config.Colors["background"]);

                if ((Keyboard.IsKeyPressed(Keyboard.Key.LAlt) || Keyboard.IsKeyPressed(Keyboard.Key.RAlt)) &&
                    Keyboard.IsKeyPressed(Keyboard.Key.F4))
                {
                    IsRunning = false;
                }

                moduleContainer.Update();

                Window.Display();
            }

            Audio.Engine.Dispose();
            Window.Close();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Settings.Load();

            Init();

            float FPS    = 0;
            int   fcount = 0;

            map    = new Map();
            player = new Player(map);

            Text fps = new Text(FPS.ToString(), new Font(Resources.FPS_Font));

            fps.FillColor = Color.Red;
            fps.Position  = new Vector2f(Settings.sWidth - 50, 10);


            ingame   = new Music(Resources.ingame_music);
            inmenu   = new Music(Resources.menu_music);
            stepsbuf = new SoundBuffer(Resources.steps);
            steps    = new Sound(stepsbuf);

            buttonbuf = new SoundBuffer(Resources.button);
            button    = new Sound(buttonbuf);

            steps.Loop  = true;
            ingame.Loop = true;
            inmenu.Loop = true;

            menu = new Menu();
            menu.OnOpen();

            Text debug = new Text($"Время расчета: {player.CalcTime.TotalMilliseconds}\nВремя отрисовки: {player.DrawTime.TotalMilliseconds}", new Font(Resources.FPS_Font));

            debug.Position  = new Vector2f(50, Settings.sHeight - 400);
            debug.FillColor = Color.Magenta;

            Settings.Update(true);

            while (window.IsOpen)
            {
                window.SetVerticalSyncEnabled(Settings.VSync);
                window.SetFramerateLimit(Settings.FPS_Limit);
                fps.Position = new Vector2f(Settings.sWidth - 50, 10);

                if (Exit)
                {
                    window.Close();
                }
                fcount++;
                DateTime start = DateTime.Now;
                fps.DisplayedString = ((int)FPS).ToString();
                window.DispatchEvents();

                if (player.Stamina > 1)
                {
                    player.Stamina = 1;
                }
                if (player.Stamina < 0)
                {
                    player.Stamina = 0;
                }
                Joystick.Update();
                if (!Joystick.IsConnected(0))
                {
                    if (Keyboard.IsKeyPressed(Keyboard.Key.RShift) || Keyboard.IsKeyPressed(Keyboard.Key.LShift))
                    {
                        player.Run();
                    }
                    else
                    {
                        player.Stamina += player.Stamina < 1 ? 0.0025F : 0;
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.W))
                    {
                        if (steps.Status != SoundStatus.Playing && Keyboard.IsKeyPressed(Keyboard.Key.W))
                        {
                            steps.Play();
                        }
                        player.Walk(Keyboard.Key.W, frametime);
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.A))
                    {
                        if (steps.Status != SoundStatus.Playing && Keyboard.IsKeyPressed(Keyboard.Key.A))
                        {
                            steps.Play();
                        }
                        player.Walk(Keyboard.Key.A, frametime);
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.S))
                    {
                        if (steps.Status != SoundStatus.Playing && Keyboard.IsKeyPressed(Keyboard.Key.S))
                        {
                            steps.Play();
                        }
                        player.Walk(Keyboard.Key.S, frametime);
                    }
                    if (Keyboard.IsKeyPressed(Keyboard.Key.D))
                    {
                        if (steps.Status != SoundStatus.Playing && Keyboard.IsKeyPressed(Keyboard.Key.D))
                        {
                            steps.Play();
                        }
                        player.Walk(Keyboard.Key.D, frametime);
                    }
                }
                else
                {
                    player.JoystickTurn();
                    player.JoystickWalk(frametime);

                    if (Joystick.IsButtonPressed(0, 5))
                    {
                        player.Run();
                    }
                    else
                    {
                        player.Stamina += player.Stamina < 1 ? 0.0025F : 0;
                    }
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.F1))
                {
                    Help();
                }


                window.Clear(Color.White);
                window.SetMouseCursorVisible(isMenu);
                //Drawing
                if (menu.isWin)
                {
                    EndScene();
                }
                if (isMenu)
                {
                    menu.Draw(window);
                }
                else
                {
                    inmenu.Stop();
                    player.Draw(window);
                    map.Draw(window);
                    player.DrawOnMap(window);
                }
                //====================



                if (fcount == 20)
                {
                    debug.DisplayedString = $"" +
                                            $"Joystick.Axis.Y = {MathF.Round(Joystick.GetAxisPosition(0, Joystick.Axis.Z) / 100F, 4)}\n" +
                                            $"Joystick.Axis.X = {Joystick.IsButtonPressed(0, 6)}\n" +
                                            $"Test = {TEST}\n";
                }

                window.Draw(debug);
                window.Draw(fps);
                window.Display();


                frametime = (DateTime.Now - start).TotalSeconds;
                if (fcount == 20)
                {
                    FPS    = (float)(1 / frametime);
                    fcount = 0;
                    window.Draw(debug);
                }
            }
        }
Ejemplo n.º 16
0
 private void OnClosed(object sender, EventArgs e)
 {
     window.Close();
 }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Box    box    = new Box();
            Player player = new Player();

            box.allObjects.Add(player.chain);
            box.allObjects.Add(player.player);
            box.levelList.Add(new Level(1));


            var window = new RenderWindow(new VideoMode(Convert.ToUInt32(MyGlobals.width), Convert.ToUInt32(MyGlobals.heigth)), "Bubble Trouble", Styles.Default);

            window.SetFramerateLimit(Convert.ToUInt32(MyGlobals.frameRate));
            window.Closed      += (s, a) => window.Close();
            window.KeyPressed  += (s, a) => player.move(a.Code);
            window.KeyReleased += (s, a) => player.idle();

            void update()
            {
                MyGlobals.playerHitbox.TextureRect = player.player.TextureRect;
                MyGlobals.playerHitbox.Position    = player.player.Position;
                MyGlobals.playerHitbox.Scale       = player.player.Scale;

                MyGlobals.chainPosition = player.chain.Position;

                foreach (var obj in box.levelList[MyGlobals.currentLevel - 1].ballList)
                {
                    obj.positionX = (int)obj.ball.Position.X;
                }
            }

            while (window.IsOpen)
            {
                window.DispatchEvents();

                update();


                for (int i = 0; i < box.levelList[MyGlobals.currentLevel - 1].ballQuantity; i++)
                {
                    update();
                    if (box.levelList[MyGlobals.currentLevel - 1].ballList[i].checkChainCollision())
                    {
                        player.isShot         = false;
                        player.chain.Position = new Vector2f(50, MyGlobals.heigth - 50);
                        update();
                        Ball b1 = new Ball(box.levelList[MyGlobals.currentLevel - 1].ballList[i].size - 1,
                                           box.levelList[MyGlobals.currentLevel - 1].ballList[i].positionX,
                                           box.levelList[MyGlobals.currentLevel - 1].ballList[i].color,
                                           1);
                        Ball b2 = new Ball(box.levelList[MyGlobals.currentLevel - 1].ballList[i].size - 1,
                                           box.levelList[MyGlobals.currentLevel - 1].ballList[i].positionX,
                                           box.levelList[MyGlobals.currentLevel - 1].ballList[i].color,
                                           -1);
                        b1.ballVelocity.Y = b1.bounceHeigth;
                        b2.ballVelocity.Y = b2.bounceHeigth;
                        b1.ball.Position  = new Vector2f(box.levelList[MyGlobals.currentLevel - 1].ballList[i].positionX, box.levelList[MyGlobals.currentLevel - 1].ballList[i].ball.Position.Y);
                        b2.ball.Position  = new Vector2f(box.levelList[MyGlobals.currentLevel - 1].ballList[i].positionX, box.levelList[MyGlobals.currentLevel - 1].ballList[i].ball.Position.Y);

                        box.levelList[MyGlobals.currentLevel - 1].ballList.Add(b1);
                        box.levelList[MyGlobals.currentLevel - 1].ballList.Add(b2);

                        box.levelList[MyGlobals.currentLevel - 1].ballQuantity += 2;

                        box.levelList[MyGlobals.currentLevel - 1].ballList.Remove(box.levelList[MyGlobals.currentLevel - 1].ballList[i]);
                        box.levelList[MyGlobals.currentLevel - 1].ballQuantity--;

                        update();
                    }
                }


                #region game time
                MyGlobals.frame++;
                if (MyGlobals.frame == MyGlobals.frameRate)
                {
                    MyGlobals.gameTime++;
                    MyGlobals.frame = 0;
                    //Console.WriteLine(MyGlobals.gameTime);
                }
                #endregion
                //freeze
                if (MyGlobals.gameTime >= 1)
                {
                    if (MyGlobals.frame % 2 == 0)
                    {
                        player.changeTexture();
                    }
                    if (player.player.Position.X + MyGlobals.playerVelocity.X + MyGlobals.playerSpeed > 36 && player.player.Position.X + MyGlobals.playerVelocity.X + MyGlobals.playerSpeed < MyGlobals.width - 94)
                    {
                        player.player.Position += MyGlobals.playerVelocity * MyGlobals.playerSpeed;
                    }

                    player.moveChain();
                    foreach (var obj in box.levelList[MyGlobals.currentLevel - 1].ballList)
                    {
                        obj.move();
                    }
                }


                window.Clear();

                foreach (var obj in box.allObjects)
                {
                    window.Draw(obj);
                }
                foreach (var obj in box.levelList[MyGlobals.currentLevel - 1].ballList)
                {
                    window.Draw(obj.ball);
                }


                window.Display();
            }
        }
Ejemplo n.º 18
0
 private void HandleWindowClose(object sender, EventArgs e)
 {
     m_mainWindow.Close();
 }
Ejemplo n.º 19
0
    private void Fermer(object sender, EventArgs e)
    {
        RenderWindow ecran = (RenderWindow)sender;

        ecran.Close();
    }
Ejemplo n.º 20
0
 private void HandleWindowClosing(object sender, EventArgs e)
 {
     window.Close();
 }
        static void win_Closed(object sender, EventArgs e)
        {
            RenderWindow win = (RenderWindow)sender;

            win.Close();
        }
Ejemplo n.º 22
0
 static void CloseWindow(object sender, EventArgs e)
 {
     window.Close();
 }
Ejemplo n.º 23
0
        /// <summary>
        ///     Entry point of programm
        /// </summary>
        /// <param name="args">System arguments</param>
        public static void Main(string[] args)
        {
            // Init main render window
            _window = new RenderWindow(new VideoMode(600, 600), "Circle");

            // Set basic settings fo window
            _window.SetMouseCursorVisible(true);
            _window.SetVerticalSyncEnabled(true);

            // Helps to close window
            _window.Closed += (sender, eventArgs) => { _window.Close(); };

            _window.Resized += (sender, eventArgs) =>
            {
                _window.SetView(new View(new FloatRect(0, 0, eventArgs.Width, eventArgs.Height)));
            };

            // Main app loop
            while (_window.IsOpen)
            {
                // Looking for events
                _window.DispatchEvents();

                // Clear screen
                _window.Clear();

                // Drawing some shape
                Draw();

                // Display shape to user
                _window.Display();

                // Change coofs
                if (Keyboard.IsKeyPressed(Keyboard.Key.Up))
                {
                    _coof1++;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Down) && _coof1 > 0)
                {
                    _coof1--;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Right))
                {
                    _coof2++;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Left) && _coof2 > 0)
                {
                    _coof2--;
                }

                // Change mods
                if (Keyboard.IsKeyPressed(Keyboard.Key.Q))
                {
                    _mode = Mode.AnglesShape;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.W))
                {
                    _mode = Mode.TwoPoints;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.E))
                {
                    _mode = Mode.Sphere;
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.R))
                {
                    _mode = Mode.Mandelbrot;
                }
            }
        }
Ejemplo n.º 24
0
 private static void Window_Closed(object sender, EventArgs e)
 {
     window.Close();
 }       // обработчик события закрытия окна
Ejemplo n.º 25
0
        void ResetWindow(string title, int width, int height, bool fullscreen, bool vsync)
        {
            if (width < 0)
            {
                throw new ArgumentException("Width must be greater than 0.");
            }
            if (height < 0)
            {
                throw new ArgumentException("Height must be greater than 0.");
            }

            if (Window != null)
            {
                if (Window.IsOpen())
                {
                    Window.Close();
                }
            }

            var windowStyle = Styles.Default;

            if (!WindowResize && WindowClose)
            {
                windowStyle = Styles.Close;
            }
            if (WindowResize && !WindowClose)
            {
                windowStyle = Styles.Resize;
            }
            if (!WindowResize && !WindowClose)
            {
                windowStyle = Styles.Titlebar;
            }
            if (!WindowBorder)
            {
                windowStyle = Styles.None;
            }

            Window              = new RenderWindow(new VideoMode((uint)width, (uint)height), title, fullscreen ? Styles.Fullscreen : windowStyle);
            Window.Closed      += new EventHandler(OnWindowClose);
            Window.GainedFocus += new EventHandler(Focused);
            Window.LostFocus   += new EventHandler(Unfocused);
            Window.Resized     += new EventHandler <SizeEventArgs>(OnResize);

            if (iconImage != null)
            {
                Window.SetIcon(iconWidth, iconHeight, iconImage.Pixels);
            }

            Window.SetVerticalSyncEnabled(vsync);

            UpdateView();
            if (Input != null)
            {
                Input.WindowInit();
            }
            if (Debugger != null)
            {
                Debugger.WindowInit();
            }
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            var size       = (uint)(VideoMode.DesktopMode.Height * 0.8f);
            var gameWindow = new OpenTK.GameWindow();             // required before RenderWindow construction for OpenGL use
            var window     = new RenderWindow(new VideoMode(size, size), "Collision Grid");

            window.Closed += (_, __) => window.Close();
            window.SetKeyRepeatEnabled(false);
            window.SetVerticalSyncEnabled(true);

            var scene              = new SceneAdapter(2000, 0.01f, 0.002f);
            var parameters         = new Parameters();
            var collisionDetection = new CollisionDetection(scene);

            scene.OnChange += (_, __) => collisionDetection.Update();

            var ui = new Ui(window);

            void RecreateUi()
            {
                ui.Clear();
                ui.AddPropertyGrid(parameters);
                ui.AddPropertyGrid(scene);
                ui.AddPropertyGrid(collisionDetection);
                if (collisionDetection.Algorithm is ICollisionGrid <ICollider> collGrid)
                {
                    foreach (var grid in collGrid.Grids.Reverse())
                    {
                        ui.AddCountGrid(grid);
                    }
                }
            }

            RecreateUi();
            collisionDetection.OnUpdate += (_, __) => RecreateUi();

            var view = new View();

            window.Resized += (_, a) => view.Resize((int)a.Width, (int)a.Height);
            //window.Resized += (_, a) => ui.Resize((int)a.Width, (int)a.Height);

            window.KeyPressed += (_, a) =>
            {
                if (Keyboard.Key.Escape == a.Code)
                {
                    window.Close();
                }
            };

            CollisionAlgoDebug algoDebug = new CollisionAlgoDebug();

            var clock = new Clock();

            while (window.IsOpen)
            {
                window.DispatchEvents();
                var deltaTime = clock.Restart().AsSeconds();
                scene.Update(deltaTime);

                if (parameters.CollisionDetection)
                {
                    var collidingSet = collisionDetection.FindCollisions();
                    if (parameters.DebugAlgo)
                    {
                        algoDebug.Check(scene, collidingSet);
                    }
                }

                view.Draw(scene.Collider, algoDebug.Errors);

                window.PushGLStates();
                ui.Draw();
                window.PopGLStates();
                window.Display();                 //buffer swap for double buffering and wait for next frame
            }
        }
Ejemplo n.º 27
0
 public void Exit()
 {
     isPlaying = false;
     window.Close();
 }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            var window = new RenderWindow(new VideoMode(ScreenWidth, ScreenHeight), "Flocking");
            var game   = new FlockingBehaviour(window, DefaultNumberOfAgents);
            var currentSelectedIndex = 0f;

            if (args.Contains("debug"))
            {
                StartDebugScreen(game);
            }

            window.KeyPressed += (source, args) =>
            {
                if (args.Code == Keyboard.Key.C)
                {
                    game.ShowCollider = !game.ShowCollider;
                }
                if (args.Code == Keyboard.Key.F)
                {
                    game.ShowFps = !game.ShowFps;
                }
                if (args.Code == Keyboard.Key.N)
                {
                    game.ShowNeighborhood = !game.ShowNeighborhood;
                }
                if (args.Code == Keyboard.Key.Num1)
                {
                    game.SelectAgent(0);
                }
                if (args.Code == Keyboard.Key.Tab)
                {
                    game.SelectAgent((int)(++currentSelectedIndex) % DefaultNumberOfAgents);
                }
                if (args.Code == Keyboard.Key.Up)
                {
                    game.AgentSpeed = Math.Min(game.AgentSpeed + 4f, 150f);
                }
                if (args.Code == Keyboard.Key.Down)
                {
                    game.AgentSpeed = Math.Max(game.AgentSpeed - 4f, 0f);
                }
                if (args.Code == Keyboard.Key.R)
                {
                    game.Reset();
                }
                if (args.Code == Keyboard.Key.Q)
                {
                    window.Close();
                }
                if (args.Code == Keyboard.Key.T)
                {
                    game.RenderQuadTree = !game.RenderQuadTree;
                }
                if (args.Code == Keyboard.Key.Y)
                {
                    game.UseQuadTree = !game.UseQuadTree;
                }
                if (args.Code == Keyboard.Key.Left)
                {
                    game.QuadTreeCapacity = Math.Max(1, game.QuadTreeCapacity - 1);
                }
                if (args.Code == Keyboard.Key.Right)
                {
                    game.QuadTreeCapacity += 1;
                }
                if (args.Code == Keyboard.Key.S)
                {
                    game.SpawnAgent();
                }
                if (args.Code == Keyboard.Key.D)
                {
                    game.RemoveLastAgent();
                }
            };

            game.Initialize();
            game.Start();
        }
Ejemplo n.º 29
0
        private void OnClose(object sender, EventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;

            window.Close();
        }
Ejemplo n.º 30
0
 private void OnClosed(object sender, EventArgs e)
 {
     ReturnState = false;
     Window.Close();
 }