Пример #1
0
        public override void Draw()
        {
            GameHelper.GraphicsDevice.Clear(backColor);

            // WORLD
            GameHelper.SpriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, null, null, null, Camera.Instance.ViewMatrix);

            GameHelper.SpriteBatch.DrawString(GameHelper.Font, "TESTING", new Vector2(20, 20), Color.Black);
            GameHelper.SpriteBatch.DrawString(GameHelper.Font, Camera.Instance.Zoom.ToString(), new Vector2(20, 40), Color.Black);

            // Borders
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], Vector2.Zero, null, Color.DarkGray, 0f, Vector2.Zero, new Vector2(2000), SpriteEffects.None, 0.0001f);

            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], Vector2.Zero, null, Color.Black, 0f, Vector2.Zero, new Vector2(4, 2000), SpriteEffects.None, 0.001f);
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], Vector2.Zero, null, Color.Black, 0f, Vector2.Zero, new Vector2(2000, 4), SpriteEffects.None, 0.001f);
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Vector2(2000, 0), null, Color.Black, 0f, Vector2.Zero, new Vector2(4, 2000), SpriteEffects.None, 0.001f);
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Vector2(0, 2000), null, Color.Black, 0f, Vector2.Zero, new Vector2(2000, 4), SpriteEffects.None, 0.001f);

            // DRAW SHIT HERE

            GeneticAlgorithm.Draw();

            if (SELECTED_EVOLVI != null)
            {
                SELECTED_EVOLVI.DrawSelected(selectedAngle);
            }

            GameHelper.SpriteBatch.End();

            // GUI
            GameHelper.SpriteBatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, null, null, null, null);

            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Rectangle(0, 0, GameHelper.GraphicsDevice.Viewport.Width, 70), Color.DimGray * 0.7f);
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Rectangle(0, 70, GameHelper.GraphicsDevice.Viewport.Width, 2), Color.Black);

            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Rectangle(0, GameHelper.GraphicsDevice.Viewport.Height - 70, GameHelper.GraphicsDevice.Viewport.Width, 70), Color.DimGray * 0.7f);
            GameHelper.SpriteBatch.Draw(GameHelper.TextureManager["PIXEL"], new Rectangle(0, GameHelper.GraphicsDevice.Viewport.Height - 72, GameHelper.GraphicsDevice.Viewport.Width, 2), Color.Black);


            GameHelper.SpriteBatch.DrawString(GameHelper.Font, "Generation: " + GeneticAlgorithm.Generation, new Vector2(10, GameHelper.GraphicsDevice.Viewport.Height - 70 + 15), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            if (GeneticAlgorithm.GenerationTime != 0)
            {
                GameHelper.SpriteBatch.DrawString(GameHelper.Font, "Generation Lifetime: " + Math.Round(GeneticAlgorithm.ElapsedGenerationTime) + " / " + GeneticAlgorithm.GenerationTime, new Vector2(10, GameHelper.GraphicsDevice.Viewport.Height - 70 + 40), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }
            else
            {
                GameHelper.SpriteBatch.DrawString(GameHelper.Font, "Generation Lifetime: " + Math.Round(GeneticAlgorithm.ElapsedGenerationTime) + " / INF", new Vector2(10, GameHelper.GraphicsDevice.Viewport.Height - 70 + 40), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            }

            GameHelper.SpriteBatch.DrawString(GameHelper.Font, "(" + GeneticAlgorithm.EvolutionSpeed + "x)", new Vector2(215, GameHelper.GraphicsDevice.Viewport.Height - 70 + 40), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);

            btn_exit.Draw();
            btn_debug.Draw();
            btn_showNetwork.Draw();
            btn_evoSpeed_1.Draw();
            btn_evoSpeed_5.Draw();
            btn_evoSpeed_10.Draw();
            btn_pauseEvo.Draw();
            btn_autoSelectOnNewGeneration.Draw();
            btn_autoSelectBestPerformer.Draw();
            btn_openConsole.Draw();
            btn_openGrapher.Draw();
            btn_resumeEvolution.Draw();

            if (SHOW_NETWORK && SELECTED_EVOLVI != null)
            {
                DrawNetwork(SELECTED_EVOLVI.Network);
            }

            if (USING_CONSOLE)
            {
                MyConsole.Draw();
            }

            if (MyGrapher.IsActive)
            {
                MyGrapher.Draw();
            }

            if (MyIndividualViewer.IsActive)
            {
                MyIndividualViewer.Draw();
            }

            if (ScreenModal?.isActive == true)
            {
                ScreenModal.Draw();
            }

            GameHelper.SpriteBatch.End();

            base.Draw();
        }
Пример #2
0
        public override void Update()
        {
            if (ScreenModal?.isActive == false)
            {
                GameHelper.Window.Title = "Time: " + Math.Round(GeneticAlgorithm.ElapsedGenerationTime) + " / " + GeneticAlgorithm.GenerationTime + " Generation: " + GeneticAlgorithm.Generation;

                btn_exit.Update();
                btn_debug.Update();
                btn_showNetwork.Update();
                btn_evoSpeed_1.Update();
                btn_evoSpeed_5.Update();
                btn_evoSpeed_10.Update();
                btn_pauseEvo.Update();
                btn_autoSelectOnNewGeneration.Update();
                btn_autoSelectBestPerformer.Update();
                btn_openConsole.Update();
                btn_openGrapher.Update();
                btn_resumeEvolution.Update();

                if (!USING_CONSOLE)
                {
                    #region Camera Handling
                    Camera.Instance.SetFocalPoint(camPos, false);
                    Camera.Instance.Update();

                    if (InputManager.ScrolledUp())
                    {
                        Camera.Instance.Zoom *= 1.1f;
                    }
                    if (InputManager.ScrolledDown())
                    {
                        Camera.Instance.Zoom /= 1.1f;
                    }

                    if (InputManager.KeyPressing(Microsoft.Xna.Framework.Input.Keys.W))
                    {
                        FOLLOW_SELECTED = false;
                        camPos         += new Vector2(0, -cameraSpeed / Camera.Instance.Zoom);
                    }
                    if (InputManager.KeyPressing(Microsoft.Xna.Framework.Input.Keys.S))
                    {
                        FOLLOW_SELECTED = false;
                        camPos         += new Vector2(0, cameraSpeed / Camera.Instance.Zoom);
                    }
                    if (InputManager.KeyPressing(Microsoft.Xna.Framework.Input.Keys.A))
                    {
                        FOLLOW_SELECTED = false;
                        camPos         += new Vector2(-cameraSpeed / Camera.Instance.Zoom, 0);
                    }
                    if (InputManager.KeyPressing(Microsoft.Xna.Framework.Input.Keys.D))
                    {
                        FOLLOW_SELECTED = false;
                        camPos         += new Vector2(cameraSpeed / Camera.Instance.Zoom, 0);
                    }
                    #endregion

                    if (InputManager.PressedMouseLeft())
                    {
                        foreach (Evolvi e in GeneticAlgorithm.CurrentGeneration)
                        {
                            if (InputManager.MouseBoxWorld.Intersects(e.CollisionBox))
                            {
                                SELECTED_EVOLVI = e;
                                break;
                            }
                        }
                    }

                    if (InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                    {
                        FOLLOW_SELECTED = true;
                    }
                }

                if (USING_CONSOLE && InputManager.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape))
                {
                    USING_CONSOLE = false;
                }

                if (AUTOSELECT_BEST_PERFORMER && GeneticAlgorithm.CurrentGeneration.Count > 0)
                {
                    SELECTED_EVOLVI = GeneticAlgorithm.SortFittest().Last();
                }

                if (FOLLOW_SELECTED && SELECTED_EVOLVI != null)
                {
                    camPos = SELECTED_EVOLVI.Position;
                }

                if (USING_CONSOLE)
                {
                    MyConsole.Update();
                }

                if (MyGrapher.IsActive)
                {
                    MyGrapher.Update();
                }

                if (MyIndividualViewer.IsActive)
                {
                    MyIndividualViewer.Update();
                }

                GeneticAlgorithm.Update(GameHelper.GameTime);

                selectedAngle += 0.05f;


                base.Update();
            }
            else
            {
                ScreenModal.Update();
            }
        }