Exemplo n.º 1
0
        public override void Render(GameTime GameTime)
        {
            var CameraMatrix = Game.Camera.GetViewMatrix();

            Game.SpriteBatch.Begin(transformMatrix: CameraMatrix, samplerState: SamplerState.PointClamp);

            // Draw Obstacle and RayCast test line
            // NOTE: In PhysicsWorld the rectangle position is at its center, when drawing is in top left | Draw obstacles
            RectangleF R = new RectangleF(-100f, -100f, 200f, 200f);

            Game.SpriteBatch.DrawRectangle(R, Color.Green);

            // Draw RayCast line
            Game.SpriteBatch.DrawLine(StartRay, EndRay, Color.Coral);

            // Draw Start and End of the Ray
            Game.SpriteBatch.DrawPoint(StartRay, Color.Blue, 3f);
            Game.SpriteBatch.DrawPoint(EndRay, Color.Red, 3f);

            // Draw Unit RayCast
            ObstacleAvoidance O = (ObstacleAvoidance)Unit.Behaviours[SteeringType.ObstacleAvoidance];

            Game.SpriteBatch.DrawLine(Unit.Transform.Position, O.Ray, Color.Black);
            if (O.CollisionPosition != Vector2.Zero)
            {
                LastCollisionPosition = O.CollisionPosition;
            }

            Game.SpriteBatch.DrawPoint(LastCollisionPosition, Color.Pink, 3f);

            /* Draw collision normal
             * if (O.CollisionPosition != Vector2.Zero)
             *  Game.SpriteBatch.DrawLine(O.CollisionPosition, O.CollisionNormal * 50f + O.CollisionPosition, Color.Gold); */

            // Draw Units
            foreach (Unit U in Units)
            {
                U.Draw(Game.SpriteBatch);
            }

            Game.SpriteBatch.End();
        }
Exemplo n.º 2
0
        public override void Render(GameTime GameTime)
        {
            var CameraMatrix = Game.Camera.GetViewMatrix();

            Game.SpriteBatch.Begin(transformMatrix: CameraMatrix, samplerState: SamplerState.PointClamp);

            // Draw Map
            MapRenderer.Draw(Map, CameraMatrix);

            if (DrawDebugGrid)
            {
                // Draw Debug Grid
                for (int x = 0; x <= Map.Width; x++)
                {
                    Rectangle Rect = new Rectangle(0 + x * Map.TileWidth, 0, 1, Map.WidthInPixels);
                    Game.SpriteBatch.Draw(DebugGridTexture, Rect, Color.Black);
                }

                for (int y = 0; y <= Map.Height; y++)
                {
                    Rectangle Rect = new Rectangle(0, 0 + y * Map.TileWidth, Map.HeightInPixels, 1);
                    Game.SpriteBatch.Draw(DebugGridTexture, Rect, Color.Black);
                }

                // Draw Nodes
                for (int x = 0; x < Map.Width; x++)
                {
                    for (int y = 0; y < Map.Height; y++)
                    {
                        if (PathfindingGrid.Nodes[x, y].Walkable)
                        {
                            Game.SpriteBatch.DrawPoint(PathfindingGrid.Nodes[x, y].WorldPosition, Color.Blue, 3);
                        }
                        else
                        {
                            Game.SpriteBatch.DrawPoint(PathfindingGrid.Nodes[x, y].WorldPosition, Color.Red, 3);
                        }
                    }
                }

                // Draw calculated Path
                Vector2 Current = Vector2.Zero;
                foreach (Vector2 P in Path.Positions)
                {
                    if (Current != Vector2.Zero)
                    {
                        Game.SpriteBatch.DrawLine(P, Current, Color.Coral, 2f);
                        Current = P;
                    }

                    Current = P;
                }

                // Draw Unit RayCast
                ObstacleAvoidance O = (ObstacleAvoidance)Unit2.Behaviours[SteeringType.ObstacleAvoidance];
                Game.SpriteBatch.DrawLine(Unit2.Transform.Position, O.Ray, Color.Black);
                if (O.CollisionPosition != Vector2.Zero)
                {
                    Game.SpriteBatch.DrawPoint(O.CollisionPosition, Color.Pink, 3f);
                }

                if (O.CollisionPosition != Vector2.Zero)
                {
                    Game.SpriteBatch.DrawLine(O.CollisionPosition, O.CollisionNormal * 50f + O.CollisionPosition, Color.Gold);
                }
            }

            foreach (Unit U in Units)
            {
                U.Draw(Game.SpriteBatch);
            }

            Game.SpriteBatch.End();

            DisplayEditor();
        }
Exemplo n.º 3
0
        // Adds a specific Steering if it's not already contained
        public void AddSteering(SteeringType Type)
        {
            if (!Behaviours.ContainsKey(Type))
            {
                switch (Type)
                {
                case SteeringType.Align:
                    Behaviours.Add(Type, new Align());
                    break;

                case SteeringType.AntiAlign:
                    Behaviours.Add(Type, new AntiAlign());
                    break;

                case SteeringType.Arrive:
                    Behaviours.Add(Type, new Arrive());
                    break;

                case SteeringType.Flee:
                    Behaviours.Add(Type, new Flee());
                    break;

                case SteeringType.Seek:
                    Behaviours.Add(Type, new Seek());
                    break;

                case SteeringType.VelocityMatching:
                    Behaviours.Add(Type, new VelocityMatching());
                    break;

                case SteeringType.Evade:
                    Behaviours.Add(Type, new Evade());
                    break;

                case SteeringType.Face:
                    Behaviours.Add(Type, new Face());
                    break;

                case SteeringType.LookWhereYouGoing:
                    Behaviours.Add(Type, new LookWhereYouGoing());
                    break;

                case SteeringType.ObstacleAvoidance:
                    ObstacleAvoidance O = new ObstacleAvoidance();
                    O.World = Collider.World;
                    Behaviours.Add(Type, O);
                    break;

                case SteeringType.PathFollowing:
                    Behaviours.Add(Type, new PathFollowing());
                    break;

                case SteeringType.Pursue:
                    Behaviours.Add(Type, new Pursue());
                    break;

                case SteeringType.Wander:
                    Behaviours.Add(Type, new Wander());
                    break;

                case SteeringType.Alignment:
                    Behaviours.Add(Type, new Alignment());
                    break;

                case SteeringType.Cohesion:
                    Behaviours.Add(Type, new Cohesion());
                    break;

                case SteeringType.Separation:
                    Behaviours.Add(Type, new Separation());
                    break;

                default:
                    break;
                }
            }
        }