Example #1
0
 public void DrawFrame()
 {
     emutex.Update(gfxdata);
     emusprite.Texture = emutex;
     window.Draw(emusprite);
     window.Display();
 }
Example #2
0
        public void EvaluateAgents(IEnumerable <ICarAI> agents, List <Parameters> maps)
        {
            this.Initalise(agents);

            foreach (var map in maps)
            {
                // Copy the map
                lineSegments = map.Map;
                carSimScreen.SetLineSegments(lineSegments);

                // Set our starting position (initial heading is always straight down)
                this.startPosition = map.StartPosition.Value;

                carSimScreen.InitaliseCars(map.Checkpoints, this.startPosition, 0);

                this.EvaluateAgents();

                window.Clear();
                window.Display();

                Thread.Sleep(100);
            }


            window.Clear();

            var text = new FontText(new Font("SimData\\Fonts\\Calibri.ttf"), $"Training Generation {gen++}...", Color.White)
            {
                Scale = 2
            };
            var cameraPosition = carSimScreen.Camera.GetView().Center;

            window.DrawString(text, cameraPosition);
            window.Display();
        }
Example #3
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     _renderWindow.DispatchEvents();
     _renderWindow.Clear(new SFML.Graphics.Color(255, 255, 255));
     Calendar.DrawCalendar(_renderWindow, _nodesModel, _sunModel, _moonModel, _metonicYearModel, _monthModel, _dayModel, _sunCountModel);
     _renderWindow.Display();
 }
Example #4
0
        public void Render(DoomApplication app)
        {
            if (app.State == ApplicationState.Opening)
            {
                openingSequence.Render(app.Opening);
            }
            else if (app.State == ApplicationState.Game)
            {
                RenderGame(app.Game);
            }

            if (app.Menu.Active)
            {
                menu.Render(app.Menu);
            }

            var screenData = screen.Data;
            var p          = MemoryMarshal.Cast <byte, uint>(sfmlTextureData);

            for (var i = 0; i < p.Length; i++)
            {
                p[i] = colors[screenData[i]];
            }

            sfmlTexture.Update(sfmlTextureData, (uint)screen.Height, (uint)screen.Width, 0, 0);

            sfmlWindow.Draw(sfmlSprite, sfmlStates);

            sfmlWindow.Display();
        }
Example #5
0
        void Render()
        {
            Window.Clear(LetterBoxColor.SFMLColor);
            Surface.FillColor = Color;
            Surface.Fill(Color);

            Draw.GameTarget = Surface;

            Draw.SpriteBatch.Begin(); // Spritebatch test?

            if (DrawInactiveScenes)
            {
                foreach (Scene scene in Scenes.Reverse())
                {
                    if (Scene != scene)
                    {
                        scenesToRender.Add(scene);
                    }
                    if (!scene.DrawScenesBelow)
                    {
                        scenesToRender = new List <Scene>();
                        if (Scene != scene)
                        {
                            scenesToRender.Add(scene);
                        }
                    }
                }
                for (int i = 0; i < scenesToRender.Count; i++)
                {
                    scenesToRender[i].RenderInternal();
                }
                scenesToRender = new List <Scene>();
            }

            if (Scene != null)
            {
                Scene.RenderInternal();
            }

            Draw.SpriteBatch.End(); // Spritebatch test?

            Draw.ResetTarget();
            foreach (var surface in Surfaces)
            {
                Draw.Graphic(surface);
            }

            Surface.DrawToWindow(this);

            if (Debugger != null)
            {
                Debugger.Render();
            }

            Window.Display();
        }
Example #6
0
        public void Print(Text a)
        {
            window.DispatchEvents();

            window.Clear(Color.Black);

            window.Draw(a);

            window.Display();
        }
Example #7
0
        private void DrawPause()
        {
            Window.Clear(Color.Blue);
            Font f = new Font("./Resources/font.ttf");
            Text t = new Text("PAUSED", f, 44);

            t.Color = Color.White;
            //t.Origin = new Vector2f(0.5f, 0.5f);
            t.Position = new Vector2f(0, 0);
            Window.Draw(t);
            Window.Display();
        }
Example #8
0
        public void StartAnimation()
        {
            RectangleShape rs = new RectangleShape(new Vector2f(800, 500));

            for (int i = 255; i > 0; i -= 8)
            {
                window.Clear();
                DrawFrame();
                rs.FillColor = new Color(0, 0, 0, (byte)i);
                window.Draw(rs);
                window.Display();
            }
        }
Example #9
0
 public void Loop()
 {
     isAlive = true;
     while (isAlive && window.IsOpen)
     {
         window.Clear();
         window.DispatchEvents();
         Draw(window);
         window.Display();
     }
     window.SetVisible(false);
     window.Close();
 }
Example #10
0
        void initialRender()
        {
            window.Clear();

            states.Transform = player.transform;
            window.Draw(player.Circle, states);
            foreach (KeyValuePair <byte, NonPlayer> np in nonPlayers)
            {
                states.Transform = np.Value.transform;
                window.Draw(np.Value.Circle, states);
            }
            window.Display();
        }
Example #11
0
        public void OpenGame(RenderWindow window)
        {
            window.Clear();
            this.Draw(window);
            window.Display();
            this.PlaySoundMenu();

            bool end        = true;
            bool KeyPressed = true;

            while (end == true)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    this.StopSoundMenu();
                    end = false;
                    window.Close();
                }

                if (Keyboard.IsKeyPressed(Keyboard.Key.D))
                {
                    this.Move(Keyboard.Key.D);
                    KeyPressed = false;
                }
                else if (Keyboard.IsKeyPressed(Keyboard.Key.Q))
                {
                    this.Move(Keyboard.Key.Q);
                    KeyPressed = false;
                }

                else if (Keyboard.IsKeyPressed(Keyboard.Key.Return) && KeyPressed == false)
                {
                    if (this.SelectedItemIndex == 0)
                    {
                        this.StopSoundMenu();
                        end = false;
                        window.Clear();
                    }
                    else if (this.SelectedItemIndex == 1)
                    {
                        this.StopSoundMenu();
                        end = false;
                        window.Close();
                    }
                }

                this.Draw(window);
                window.Display();
                Thread.Sleep(85);
            }
        }
Example #12
0
        public void Run()
        {
            // vbouchard et ppoulin

            // Fait jouer le son de début de jeu
            beginningSound.Play();
            if (true == game.LoadGrid("Levels/level1.txt"))
            {
                window.SetActive();
                while ((lastKeyPressed != Keyboard.Key.Escape) && window.IsOpen && (game.Update(lastKeyPressed) == EndGameResult.NotFinished))
                {
                    window.Clear(Color.Black);
                    window.DispatchEvents();
                    game.Draw(window);
                    window.Display();

                    // Tant que le son de début de jeu n'est pas arrêter on affiche l'écran titre
                    while (beginningSound.Status != SoundStatus.Stopped && window.IsOpen)
                    {
                        // Si l'écran titre n'a pas déjà été dessiner (pour ne pas l'afficher à chaque fois dans la boucle)
                        if (isTitleDrawn == false)
                        {
                            // On affiche l'écran de jeu (sans ceci le labyrinthe et les pacmans ne s'affichent pas)
                            window.Display();

                            // On dessine l'écran titre sur le jeu
                            window.Draw(titleSprite);

                            // On affiche l'écran titre sur le jeu
                            window.Display();

                            // L'écran titre à été afficher
                            isTitleDrawn = true;
                        }
                    }
                    // Le jeu à terminer d'avoir son écran de début et sa musique de début
                    game.isBeginning = false;
                }

                // Si le jeu est terminer, onse débarasse du son de début (sans ceci nous avons une execption de mémoire de son perdue)
                if (game.Update(lastKeyPressed) != EndGameResult.NotFinished)
                {
                    beginningSound.Dispose();
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Format de fichier invalide.\n\nL'application va se terminer", "Erreur lors du chargement");
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            window.Closed              += Window_Closed;
            window.MouseButtonPressed  += Window_MouseButtonPressed;
            window.MouseButtonReleased += Window_MouseButtonReleased;

            window.SetVerticalSyncEnabled(true);
            window.SetFramerateLimit(60);

            SetScene(new BlankScene());

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

                foreach (Drawable drawable in currentScene.GetDrawables().GetAll())
                {
                    window.Draw(drawable);
                }

                currentScene.Update();
                window.Display();
            }
        }
Example #14
0
        public void Run()
        {
            Init();
            // Start of game loop
            while (window.IsOpen)
            {
                // Process events - keypress, mouse movement & clicks
                window.DispatchEvents();

                // Clear screen - to pre-determined color
                window.Clear(clearColor);

                // Update the game if player hasn't paused
                if (isPaused)
                {
                    window.Draw(menuText);
                }
                else
                {
                    Update(window, dt);
                }
                // Update the window
                window.Display();
            }
            // End of game loop
        }
Example #15
0
        private void Redraw()
        {
            _window.Clear();
            _window.DispatchEvents();

            foreach (RectangleShape checkBox in _checkBoxes)
            {
                _window.Draw(checkBox);
            }

            _window.Draw(_pong);
            _window.Draw(_left);
            _window.Draw(_right);
            _window.Draw(_human);
            _window.Draw(_targetMode);
            _window.Draw(_easy);
            _window.Draw(_normal);
            _window.Draw(_hard);
            _window.Draw(_pressToContinue);
            _window.Draw(_xLeft);
            _window.Draw(_xRight);


            _window.Display();
        }
Example #16
0
        public static void Main(string[] args)
        {
            var windowColor = new Color(0, 0, 0);
            var mode        = new VideoMode(800, 600);
            var app         = new RenderWindow(mode, "Ant Simulator");
            var startUp     = new StartUp(app)
            {
                Active = true
            };

            app.Closed += OnClose;


            while (app.IsOpen)
            {
                // Process events
                app.DispatchEvents();


                // Clear screen
                app.Clear(windowColor);
                app.Draw(startUp);

                // Update the window
                app.Display();
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            //create the window object
            win = new RenderWindow(new SFML.Window.VideoMode(800, 600), "Meu Terraria");
            //need for vertical synchronization
            win.SetVerticalSyncEnabled(true);

            //you need to bind a method to the window event handler that will be called when you click the close window button on the upper right of the window
            win.Closed  += Win_Closed;
            win.Resized += Win_Resized;

            //loading content
            Content.Load();

            Game = new Game();

            //a loop that will work as long as the window is open
            while (win.IsOpen)
            {
                //inside the loop we ask one team that revises all its incoming message box about events such as moving higher, closing when keystrokes and so on
                win.DispatchEvents(); //call the event handlers for each pading events

                Game.Update();

                //next, we clear the drawing area of the window
                win.Clear(Color.Black);

                Game.Draw();

                win.Display();
            }
        }
Example #18
0
        private void Render()
        {
            while (_window.IsOpen)
            {
                _window.DispatchEvents();

                if (!_shouldRender)
                {
                    continue;
                }

                _window.Clear();

                var lines = GetLines();
                for (var i = 0; i < lines.Length; i++)
                {
                    _text.Position        = new Vector2f(0f, i * (FontSize + 4));
                    _text.DisplayedString = lines[i];

                    _window.Draw(_text);
                    DrawCallback?.Invoke(_window);
                }
                _window.Display();
                _shouldRender = false;
            }
        }
Example #19
0
        private void Run()
        {
            // Start call
            Start();

            double updateTime = 0d;
            float  totalTime  = 0f;
            float  oldTime    = 0f;
            float  deltaTime  = 0f;

            Clock clock = new Clock();

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

                totalTime = clock.ElapsedTime.AsSeconds();
                deltaTime = totalTime - oldTime;
                oldTime   = totalTime;

                updateTime += deltaTime;

                if (updateTime >= frameDelay)
                {
                    updateTime = 0;

                    Update();

                    Window.Clear(Color.Black);
                    Render();
                    Window.Display();
                }
            }
        }
Example #20
0
        public void Run()
        {
            while (window.IsOpen)
            {
                window.DispatchEvents();
                window.Clear(Color.Black);

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        window.Draw(grass[x, y]);
                    }
                }

                // Map the flipped vertical axis and the 1,1 pixel grid to the 16,16 pixel grid taking into account the origin.
                robot.Position = new Vector2f((toyRobot.Position.x * size) + halfSize, ((size * (height - 1)) - (toyRobot.Position.y * size)) + halfSize);
                robot.Rotation = DirectionUtility.DirectionToRotation[toyRobot.Direction];

                window.Draw(robot);

                window.Display();
            }

            robot.Texture.Dispose();
            grass[0, 0].Texture.Dispose();
        }
Example #21
0
 public void Render()
 {
     _sfmlWindow.DispatchEvents();
     _sfmlWindow.Clear();
     _sfmlWindow.Draw(sprite);
     _sfmlWindow.Display();
 }
Example #22
0
        private void renderLoop()
        {
            window = new RenderWindow(
                new VideoMode(Settings.ScreenSize.X, Settings.ScreenSize.Y),
                Settings.Title,
                Styles.Fullscreen | Styles.Close
                );
            window.Closed      += (object sender, EventArgs e) => (sender as RenderWindow).Close();
            window.KeyPressed  += (object sender, KeyEventArgs e) => keyPressed(e);
            window.KeyReleased += (object sender, KeyEventArgs e) => keyReleased(e);

            init();
            updateThread.Start();

            while (window.IsOpen)
            {
                stateLock.WaitOne();
                window.DispatchEvents();
                window.Clear(Settings.DefaultBgColor);

                draw();

                window.Display();
                stateLock.ReleaseMutex();
            }
        }
Example #23
0
        public void Run()
        {
            window.SetActive();

            bool gameIsOver = false;

            // Game.GetInstance( ).InitializeGame( paths[currentLevel] );
            while (window.IsOpen && !gameIsOver)
            {
                EndGameResult result = Game.GetInstance().Update();
                if (result == EndGameResult.Win)
                {
                    // Signaler la victoire
                    Game.GetInstance().HandleEndOfGame(result);
                }
                else if (result == EndGameResult.Lost)
                {
                    // Signaler la défaite
                    Game.GetInstance().HandleEndOfGame(result);
                }
                else
                {
                    // Effectuer le rendu
                    window.Clear(backgroundColor);
                    window.DispatchEvents();
                    Game.GetInstance().Draw(window);
                    window.Display();
                }
            }
        }
        static void Main(string[] args)
        {
            GradientRect g = new GradientRect(0, 0, 800, 600, Color.Red, Color.Black, 2);
            RenderWindow win = new RenderWindow(new VideoMode(800, 600), "");
            Color gradientPrimary = new Color(255, 0, 0);
            Color gradientSecondary = new Color(0, 0, 0);

            win.Closed += (sender, e) => win.Close();
            win.MouseMoved += (sender, e) =>
            {
                if (e.X < 400)
                {
                    gradientPrimary.R = PercentColor(e.Y, 0.0);
                    gradientPrimary.G = PercentColor(e.Y, 0.0);
                    gradientPrimary.B = PercentColor(e.Y, 600.0);
                }
                else
                {
                    gradientSecondary.R = (byte)(Math.Abs(255 - PercentColor(e.Y, 600.0)));
                    gradientSecondary.G = (byte)(Math.Abs(255 - PercentColor(e.Y, 600.0)));
                    gradientSecondary.B = (byte)(Math.Abs(255 - PercentColor(e.Y, 60S0.0)));
                }
            };
            
            while (win.IsOpen())
            {
                win.DispatchEvents();
                win.Clear();
                g.Draw(win);
                win.Display();                
                g.ChangePrimaryColor(gradientPrimary);
                g.ChangeSecondaryColor(gradientSecondary);
            }
        }
Example #25
0
        static void Main(string[] args)
        {
            Window = new RenderWindow(new SFML.Window.VideoMode(800, 600), "Моя Terraria!");
            Window.SetVerticalSyncEnabled(true);

            Window.Closed  += Win_Closed;
            Window.Resized += Win_Resized;

            // Загрузка контента
            Content.Load();

            Game = new Game();      // Создаём новый объект класса игры
            Clock clock = new Clock();

            while (Window.IsOpen)
            {
                Delta = clock.Restart().AsSeconds();

                Window.DispatchEvents();

                Game.Update();

                Window.Clear(Color.Black);

                Game.Draw();

                Window.Display();
            }
        }
Example #26
0
File: Game.cs Project: Malpp/TP3
        /// <summary>
        /// Draw code of the program
        /// </summary>
        private void Draw()
        {
            //totalTime += drawClock.Restart().AsSeconds();
            //if (totalTime > 0.016f)
            //{
            //    totalTime = 0;

            window.Clear();
            currentRenderTexture.Clear();
            currentRenderTexture.Draw(borderSprite);
            EntityManager.Draw(currentRenderTexture);
            currentRenderTexture.Display();
            drawSprite.Texture = currentRenderTexture.Texture;
            window.Draw(drawSprite);
            horizontal.Update(currentRenderTexture.Texture, sigma, glow);

            secondPass.Clear();
            secondPass.Draw(horizontal);
            secondPass.Display();

            vertical.Update(secondPass.Texture, sigma, glow);

            window.Draw(vertical);

            EntityManager.DrawText(window);

            window.Display();

            //}
        }
Example #27
0
        static void Main(string[] args)
        {
            window         = new RenderWindow(new VideoMode((uint)window_width, (uint)window_height), "SortingVisuals");
            window.Closed += new EventHandler(OnClose);

            BaseSort sort = new ShakeSort();

            sort.SetEntries(window_width, window_height);



            while (window.IsOpen)
            {
                window.DispatchEvents();
                window.Clear(Color.White);

                sort.DoSort();

                for (int i = 0; i < sort.GetCurrentSort().Count; i++)
                {
                    RectangleShape lineEntry = new RectangleShape(new SFML.System.Vector2f(1, sort.GetCurrentSort()[i]));
                    lineEntry.FillColor = Color.Black;
                    lineEntry.Position  = new SFML.System.Vector2f(i, 0);
                    window.Draw(lineEntry);
                }



                window.Display();
            }
        }
Example #28
0
        public void Run()
        {
            Initialize();

            var      window        = new RenderWindow(new VideoMode(800, 600), "Pong", Styles.Default);
            DateTime previous_time = DateTime.Now;
            DateTime current_time;
            double   delta;

            while (running)
            {
                current_time  = DateTime.Now;
                delta         = current_time.Subtract(previous_time).TotalMilliseconds;
                previous_time = current_time;

                window.DispatchEvents();
                window.Closed += (sender, evtArgs) => running = false;

                Update(delta);

                window.Clear(Color.Black);
                Render(window);
                window.Display();
            }
        }
Example #29
0
        private void MainLoop()
        {
            Stopwatch frameTime = new Stopwatch();

            while (m_window.Visible)
            {
                float lastFrameTime = (float)frameTime.Elapsed.TotalSeconds;
                frameTime.Restart();

                m_renderWindow.SetView(Globals.ViewManager.View);
                if (Globals.RenderManager.Update(lastFrameTime, m_renderWindow))
                {
                    m_renderWindow.Display();
                }

                Application.DoEvents();
                Globals.InputManager.Update(lastFrameTime);
                Globals.EntityManager.Update(lastFrameTime);
                Globals.PhysicsManager.Update(lastFrameTime);
                Globals.ProcessManager.Update(lastFrameTime);

                var maxEventTime = MaxFrameTime - (float)frameTime.Elapsed.TotalSeconds;
                Globals.EventManager.Update(maxEventTime);

                if (frameTime.Elapsed.TotalSeconds < MaxFrameTime)
                {
                    Thread.Sleep(1);
                }
            }
        }
        public virtual void RenderLoop()
        {
            lastFrame = DateTime.Now;
            while (renderWindow.IsOpen)
            {
                //Assuming 60 fps
                float deltaTime = (float)DateTime.Now.Subtract(lastFrame).Milliseconds / 17;
                lastFrame = DateTime.Now;

                //Perform Network Methods
                NetworkUpdate();

                //Perform Updates on Dynamic Actors
                UpdateGame(deltaTime);

                //Dispatch Events and Clear the screen
                renderWindow.DispatchEvents();
                renderWindow.Clear(Color.Black);

                //Adjust and Set the view
                //Adjust view to player location
                renderWindow.SetView(view);

                //Render Each Drawable Actor
                DrawActors();

                //Draw frame on screen
                renderWindow.Display();
            }
        }