示例#1
0
        public void setNextPursuitTarget()
        {
            MovingEntity objSharkie = getVehicleByID(m_intSharkieID);

            objSharkie.Steering().ArriveOff();
            objSharkie.Steering().FollowPathOff();

            if (m_Vehicles.Count > 1)
            {
                bool blnSearch = true;

                while (blnSearch)
                {
                    int tempNum = Utils.RandInt(0, (m_Vehicles.Count - 1));

                    if (m_Vehicles[tempNum].ID() != m_intSharkieID)
                    {
                        m_intVictimID = m_Vehicles[tempNum].ID();
                        blnSearch     = false;
                    }
                }

                MovingEntity objVictim = getVehicleByID(m_intVictimID);
                objSharkie.Steering().PursuitOn(objVictim);
            }
        }
示例#2
0
        public void setTarget(int x, int y)
        {
            GameWorld.Instance.TargetPos = new Vector2D(x, y);

            MovingEntity objSharkie = getVehicleByID(m_intSharkieID);

            objSharkie.Steering().PursuitOff();
            objSharkie.Steering().FollowPathOff();

            objSharkie.Steering().ArriveOn();
        }
示例#3
0
        public void setFollowPathOn()
        {
            MovingEntity objSharkie = getVehicleByID(m_intSharkieID);

            objSharkie.Steering().PursuitOff();
            objSharkie.Steering().ArriveOff();

            objSharkie.Steering().FollowPathOn();

            if (objSharkie.Steering().GetPath().Finished())
            {
                ReCreatePath();
            }
        }
示例#4
0
        private void renderDetectionBox(MovingEntity objVehicle, Graphics objGraphics, Pen objPen)
        {
            List <Vector2D> points = new List <Vector2D>();

            points.Add(new Vector2D(0, objVehicle.BRadius));
            points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), objVehicle.BRadius));
            points.Add(new Vector2D(objVehicle.Steering().DBoxLength(), -objVehicle.BRadius));
            points.Add(new Vector2D(0, -objVehicle.BRadius));

            if (UseSmoothing)
            {
                points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.SmoothedHeading(), objVehicle.SmoothedHeading().Perp());
            }
            else
            {
                points = Utils.WorldTransform(points, objVehicle.Pos, objVehicle.Heading(), objVehicle.Side());
            }

            objGraphics.DrawLine(objPen, (PointF)points[0], (PointF)points[1]);
            objGraphics.DrawLine(objPen, (PointF)points[1], (PointF)points[2]);
            objGraphics.DrawLine(objPen, (PointF)points[2], (PointF)points[3]);
        }
示例#5
0
        public SteeringScenario(int cx, int cy)
        {
            m_cxClient = cx;
            m_cyClient = cy;

            m_Vehicles.Clear();
            m_Obstacles.Clear();
            m_Walls.Clear();

            GameWorld.Instance.cxClient = m_cxClient;
            GameWorld.Instance.cyClient = m_cyClient;

            GameWorld.Instance.Wrap = true;
            GameWorld.Instance.SpacePartitioningOn = true;

            objVehiclePen  = new Pen(Color.Black);
            objDarkPen     = new Pen(Color.SeaGreen, 2);
            objWallPen     = new Pen(Color.DarkOrange);
            objObstaclePen = new Pen(Color.Orange);
            objTargetPen   = new Pen(Color.Blue, 1);
            objRedPen      = new Pen(Color.Red, 2);
            objCellPen     = new Pen(Color.LightSkyBlue, 1);
            objGrayPen     = new Pen(Color.LightSlateGray, 2);
            objPathPen     = new Pen(Color.Blue, 2);

            objPathPen.EndCap    = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            objPathPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

            m_pCellSpace = new CellSpacePartition(m_cxClient, m_cyClient, SteerParams.Instance.NumCellsX, SteerParams.Instance.NumCellsY, SteerParams.Instance.NumAgents);

            CreateObstacles();
            CreateWalls();
            CreateRandomPath();

            //setup the agents
            for (int a = 0; a < SteerParams.Instance.NumAgents; ++a)
            {
                //determine a random starting position
                Vector2D SpawnPos = new Vector2D(cx / 2.0 + Utils.RandomClamped() * cx / 2.0, cy / 2.0 + Utils.RandomClamped() * cy / 2.0);

                double rotation = Utils.RandFloat() * Utils.TwoPi;

                MovingEntity pVehicle = new MovingEntity(SpawnPos,  //initial position
                                                         SteerParams.Instance.VehicleScale,
                                                         new Vector2D(0, 0),
                                                         SteerParams.Instance.MaxSpeed,
                                                         new Vector2D(Math.Sin(rotation), -Math.Cos(rotation)),
                                                         SteerParams.Instance.VehicleMass,
                                                         new Vector2D(SteerParams.Instance.VehicleScale, SteerParams.Instance.VehicleScale),
                                                         SteerParams.Instance.MaxTurnRatePerSecond,
                                                         SteerParams.Instance.AppliedMaxSteeringForce());

                pVehicle.Steering().FlockingOn();
                pVehicle.Steering().WallAvoidanceOn();
                pVehicle.Steering().ObstacleAvoidanceOn();

                m_Vehicles.Add(pVehicle);

                //add it to the cell subdivision
                m_pCellSpace.AddEntity(pVehicle);
            }

            // Turn the last one into a shark!
            int sharkie = SteerParams.Instance.NumAgents - 1;

            m_Vehicles[sharkie].Steering().FlockingOff();
            m_Vehicles[sharkie].SetScale(new Vector2D(6, 6));
            m_Vehicles[sharkie].MaxSpeed = 80;

            m_intSharkieID = m_Vehicles[sharkie].ID();

            setNextPursuitTarget();

            for (int a = 0; a < SteerParams.Instance.NumAgents - 1; ++a)
            {
                m_Vehicles[a].Steering().EvadeOn(m_Vehicles[sharkie]);
            }

            GameWorld.Instance.Agents     = m_Vehicles;
            GameWorld.Instance.Walls      = m_Walls;
            GameWorld.Instance.Obstacles  = m_Obstacles;
            GameWorld.Instance.CellSpaces = m_pCellSpace;
        }
示例#6
0
        public bool isFollowPathOn()
        {
            MovingEntity objSharkie = getVehicleByID(m_intSharkieID);

            return(objSharkie.Steering().isFollowPathOn());
        }
示例#7
0
        public void ReCreatePath()
        {
            MovingEntity objSharkie = getVehicleByID(m_intSharkieID);

            objSharkie.Steering().GetPath().Set(CreateRandomPath());
        }
示例#8
0
        public void Render(Graphics objGraphics)
        {
            if (isFollowPathOn())
            {
                MovingEntity objSharkie = getVehicleByID(m_intSharkieID);
                RenderPath2D(objSharkie.Steering().GetPath(), objGraphics, objPathPen);
            }

            foreach (MovingEntity objVehicle in m_Vehicles)
            {
                Pen objDrawPen = objVehiclePen;

                if (isPursuitOn() && (objVehicle.ID() == m_intVictimID))
                {
                    objDrawPen = objTargetPen;
                }

                if (m_blnNonePenetrationOn)
                {
                    List <MovingEntity> ListTouched = MovingEntity.EnforceNonPenetrationConstraint(objVehicle, m_Vehicles);

                    if (ListTouched.Count > 0)
                    {
                        if (objVehicle.ID() == m_intSharkieID)
                        {
                            objDrawPen = objRedPen;
                        }
                        else
                        {
                            objDrawPen = objDarkPen;
                        }
                    }
                }

                RenderVehicle(objVehicle, objGraphics, objDrawPen);

                if (m_blnRenderAids)
                {
                    if ((objVehicle.ID() == m_intSharkieID))
                    {
                        Vector2D vecForce = (Vector2D)(objVehicle.Steering().Force() / SteerParams.Instance.SteeringForceTweaker);
                        vecForce.X = (vecForce.X * 2) * objVehicle.Scale().X;
                        vecForce.Y = (vecForce.Y * 2) * objVehicle.Scale().Y;

                        objGraphics.DrawLine(objRedPen, (PointF)objVehicle.Pos, (PointF)(objVehicle.Pos + vecForce));


                        objGraphics.DrawEllipse(objVehiclePen, (int)(objVehicle.Pos.X - SteerParams.Instance.ViewDistance), (int)(objVehicle.Pos.Y - SteerParams.Instance.ViewDistance),
                                                (int)SteerParams.Instance.ViewDistance * 2, (int)SteerParams.Instance.ViewDistance * 2);

                        renderDetectionBox(objVehicle, objGraphics, objVehiclePen);
                    }
                    else if ((objVehicle.ID() == m_intVictimID) && GameWorld.Instance.SpacePartitioningOn && isPursuitOn())
                    {
                        InvertedAABBox2D box = new InvertedAABBox2D(objVehicle.Pos - new Vector2D(SteerParams.Instance.ViewDistance, SteerParams.Instance.ViewDistance),
                                                                    objVehicle.Pos + new Vector2D(SteerParams.Instance.ViewDistance, SteerParams.Instance.ViewDistance));

                        renderBox(box, objGraphics, objTargetPen);

                        GameWorld.Instance.CellSpaces.CalculateNeighbors(objVehicle.Pos, SteerParams.Instance.ViewDistance);

                        foreach (MovingEntity objNeighbour in GameWorld.Instance.CellSpaces.ListOfNeighbours())
                        {
                            if (objNeighbour.ID() != m_intSharkieID)
                            {
                                RenderObstacle(objNeighbour, objGraphics, objGrayPen);
                            }
                        }

                        objGraphics.DrawEllipse(objGrayPen, (int)(objVehicle.Pos.X - SteerParams.Instance.ViewDistance), (int)(objVehicle.Pos.Y - SteerParams.Instance.ViewDistance),
                                                (int)SteerParams.Instance.ViewDistance * 2, (int)SteerParams.Instance.ViewDistance * 2);
                    }
                }
            }

            if (GameWorld.Instance.SpacePartitioningOn)
            {
                foreach (Cell objCell in m_pCellSpace.ListOfCells())
                {
                    renderCell(objCell, objGraphics, objCellPen, true);
                }
            }

            foreach (Wall2D objWall in m_Walls)
            {
                RenderWall2D(objWall, objGraphics, objWallPen, true);
            }

            foreach (BaseGameEntity objObs in m_Obstacles)
            {
                RenderObstacle(objObs, objGraphics, objObstaclePen);
            }

            if (!isPursuitOn() && !isFollowPathOn())
            {
                RenderTarget(GameWorld.Instance.TargetPos, objGraphics, objTargetPen);
            }
        }