Exemple #1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(59, 100, 147));

            background.Draw(spriteBatch);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, camera.getViewMatrix(Vector2.One));

            uiManager.Draw(spriteBatch);
            powerUpManager.Draw();

            player1Tank.Draw(spriteBatch);
            player2Tank.Draw(spriteBatch);
            screenManager.Draw();

            base.Draw(gameTime);

            spriteBatch.End();
        }
Exemple #2
0
        public void Run()
        {
            while (window.IsOpen)
            {
                float deltaT = Configuration.IsDebugFrameTime
                    ? Configuration.DebugFrameTime
                    : clock.Restart().AsMicroseconds() / 1000000f;

                // Clear the previous frame
                window.Clear(Configuration.Background);

                // Process events
                window.DispatchEvents();

                // Update all the screens
                screenManager.Update(deltaT);

                // Draw all the screens
                screenManager.Draw(deltaT);

                // Update the window
                window.Display();
            }
        }
Exemple #3
0
        public void Run()
        {
            // Spawn our initial populaiton of individuals
            world.Spawn();

            Thread.Sleep(3000);

            // Set our generation count to zero and restart our timer
            int generation = 0;

            generationClock.Restart();

            while (window.IsOpen)
            {
                // Get the amount of time that has passed since we drew the last frame.
                float deltaT = clock.Restart().AsMicroseconds() / 1000000f;

                // Clear the previous frame
                window.Clear(Configuration.Background);

                // Process events
                window.DispatchEvents();

                // Camera movement is now separate from our other screen update code to minimise overhead.
                screenManager.UpdateCamera(deltaT);

                screenManager.Draw(deltaT);

                // Update the window
                window.Display();

                // If one second has passed, breed the next generation
                if (generationClock.ElapsedTime.AsSeconds() > generationTime &&
                    (doGeneration?.IsCompleted ?? true) &&
                    !world.HasConverged)
                {
                    doGeneration = Task.Run(() =>
                    {
                        // Do one generation of breeding & culling.
                        world.DoGeneration();

                        // Restart our generation timer
                        generationClock.Restart();

                        // Update the screen to show the new generation
                        pathScreen.GenerationString.StringText = $"Generation: {++generation}";

                        // Draw the paths of the current best individual
                        pathScreen.UpdateSequence(world.GetBestIndividual());

                        // Update all the screen components that are unrelated to our sequence.
                        screenManager.Update(deltaT);
                    });
                }

                // Our GA has either hit the max generations or has stopped improving, set the GA as complete
                // and copy the history of fitness values to the clipboard
                if (world.GenerationCount == GAConfig.MaxGenerations ||
                    world.NoImprovementCount == GAConfig.MaxNoImprovementCount)
                {
                    pathScreen.SetGACompleted();

                    // Copy the fitness to clipboard
                    Clipboard.SetText(string.Join(",", world.FitnessOverTime));
                }

                // Process any key presses that the user has made.
                this.ProcessUserInput();

                // Check to see if the user wants to stop the simulation.
                if (Keyboard.IsKeyPressed(Configuration.QuitKey) ||
                    Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    return;
                }
            }
        }