Ejemplo n.º 1
0
        public Screen()
        {
            InitializeComponent();
            timer.Start();

            this.world = World.Instance;
            this.worldCanvas.Paint += this.world.Render;
            this.worldCanvas.Size = new Size(World.Width, World.Height);
            this.worldCanvas.Location = newLocation;
            BitmapEngine.LoadDataPool();

            this.graphCanvas.Paint += this.world.RenderGraph;
            this.graphCanvas.Size = new Size(World.Width - 2, World.Height - 2);
            this.graphCanvas.Location = new Point(0, 0);

            miDebugShowAll.Click += OnToolstripDebugClick;
            miDebugCurrentLocation.Click += OnToolstripDebugClick;
            miDebugCurrentVelocity.Click += OnToolstripDebugClick;
            miDebugDesiredVelocity.Click += OnToolstripDebugClick;
            miDebugWallAviodanceFeelers.Click += OnToolstripDebugClick;
            miDebugWander.Click += OnToolstripDebugClick;
            miDebugPanicDistance.Click += OnToolstripDebugClick;
            miDebugGraph.Click += OnToolstripDebugClick;
            miDebugBradius.Click += OnToolstripDebugClick;
            miDebugArrive.Click += OnToolstripDebugClick;
            miDebugViewDistance.Click += OnToolstripDebugClick;
            miDebugFlocking.Click += OnToolstripDebugClick;
            miDebugHealth.Click += OnToolstripDebugClick;
            miDebugGoals.Click += OnToolstripDebugClick;

            miDebugCurrentLocation.ShortcutKeys = Keys.F1;
            miDebugCurrentVelocity.ShortcutKeys = Keys.F2;
            miDebugDesiredVelocity.ShortcutKeys = Keys.F3;
            miDebugWallAviodanceFeelers.ShortcutKeys = Keys.F4;
            miDebugWander.ShortcutKeys = Keys.F5;
            miDebugPanicDistance.ShortcutKeys = Keys.F6;
            miDebugGraph.ShortcutKeys = Keys.F7;
            miDebugBradius.ShortcutKeys = Keys.F8;
            miDebugArrive.ShortcutKeys = Keys.F9;
            miDebugViewDistance.ShortcutKeys = Keys.F10;
            miDebugFlocking.ShortcutKeys = Keys.F11;
            miDebugHealth.ShortcutKeys = Keys.F12;
            miDebugGoals.ShortcutKeys = Keys.F13;

            btnRestart.Click += OnRestartClick;

            Application.Idle += HandleApplicationIdle;
        }
Ejemplo n.º 2
0
        public static Graph GenerateWorldGraph(World world)
        {
            Graph graph = new Graph();

            float maxWidth = World.Width;
            float maxHeight = World.Height;

            int edgeSize = 30;

            //Add a little padding on the edge of the world. We don't want our entities to fall off the world.
            int OffsetX = (World.Width % edgeSize) / 2;
            int OffsetY = (World.Height % edgeSize) / 2;

            for (int y = OffsetY; y < maxHeight; y += edgeSize)
            {
                for (int x = OffsetX; x < maxWidth; x += edgeSize)
                {
                    Vector2D currentPosition = new Vector2D(x, y);

                    var staticObjects = world.GetAllStaticObjects();

                    //Check if new node fits on the world
                    if (currentPosition.x + edgeSize < maxWidth)
                    {
                        Vector2D promissingPoint = new Vector2D(x + edgeSize, y);

                        bool doesIntersect = false;
                        foreach (BaseEntity entity in staticObjects)
                            if (Util.LineIntersectsWithCirlce(entity.Position, entity.Bradius / 2, currentPosition, promissingPoint))
                                doesIntersect = true;

                        if (!doesIntersect)
                        {
                            //Add edges in two directions
                            //  A --> B
                            //  A <-- B
                            graph.AddEdge(currentPosition, promissingPoint);
                            graph.AddEdge(promissingPoint, currentPosition);
                        }
                    }

                    if (currentPosition.y + edgeSize < maxHeight)
                    {
                        Vector2D promissingPoint = new Vector2D(x, y + edgeSize);
                        bool doesIntersect = false;

                        foreach (BaseEntity entity in staticObjects)
                            if (Util.LineIntersectsWithCirlce(entity.Position, entity.Bradius / 2, currentPosition, promissingPoint))
                                doesIntersect = true;

                        if (!doesIntersect)
                        {
                            //Add edges in two directions
                            //  A --> B
                            //  A <-- B
                            graph.AddEdge(currentPosition, promissingPoint);
                            graph.AddEdge(promissingPoint, currentPosition);
                        }
                    }
                }
            }
            return graph;
        }