コード例 #1
0
        private GameWorld()
        {
            m_bPaused      = false;
            m_bWrap        = false;
            m_blnSmoothing = true;
            m_bCellSpaceOn = false;

            m_dTimeElapsed = 0.0;

            m_Walls      = null;
            m_pCellSpace = null;
            m_Obstacles  = null;
            m_Agents     = null;

            m_cxClient = 0;
            m_cyClient = 0;

            m_vTargetPos = new Vector2D();
        }
コード例 #2
0
ファイル: GameWorld.cs プロジェクト: Cloverseer/thinksharp
        private GameWorld()
        {
            m_bPaused = false;
            m_bWrap = false;
            m_blnSmoothing = true;
            m_bCellSpaceOn = false;

            m_dTimeElapsed = 0.0;

            m_Walls = null;
            m_pCellSpace = null;
            m_Obstacles = null;
            m_Agents = null;

            m_cxClient = 0;
            m_cyClient = 0;

            m_vTargetPos = new Vector2D();
        }
コード例 #3
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;
        }