示例#1
0
        public override void Build(City c)
        {
            double xChange = 40 * Math.Cos(dir);
            double yChange = 40 * Math.Sin(dir);

            enter = new CityNode(x + (int)xChange, y + (int)yChange);
            exit  = new CityNode(x - (int)xChange, y - (int)yChange);

            xChange = 60 * Math.Cos(dir);
            yChange = 60 * Math.Sin(dir);

            p1 = new CityNode(x - (int)xChange, y - (int)yChange);
            p2 = new CityNode(x + (int)xChange, y + (int)yChange);

            xChange = 60 * Math.Cos(dir - Math.PI / 2);
            yChange = 60 * Math.Sin(dir - Math.PI / 2);

            pMid = new CityNode(x + (int)xChange, y + (int)yChange);

            enter.Connect(exit, CityPathType.privates, 40);

            p1.Connect(pMid, CityPathType.pedestrians);
            p2.Connect(pMid, CityPathType.pedestrians);
            pMid.Connect(p1, CityPathType.pedestrians);
            pMid.Connect(p2, CityPathType.pedestrians);

            c.nodes.Add(enter);
            c.nodes.Add(exit);
            c.nodes.Add(p1);
            c.nodes.Add(p2);
            c.nodes.Add(pMid);
        }
        public override void Build(City c)
        {
            if (this.n1 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n1 = this.n1 as BuilderAllWayStopNode;
                n1.Connect(this, out s1, out e1, out p11, out p21);
            }
            if (this.n1 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n1 = this.n1 as BuilderDeadEndNode;
                n1.Connect(this, out s1, out e1, out p11, out p21);
            }


            if (this.n2 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n2 = this.n2 as BuilderAllWayStopNode;
                n2.Connect(this, out s2, out e2, out p12, out p22);
            }
            if (this.n2 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n2 = this.n2 as BuilderDeadEndNode;
                n2.Connect(this, out s2, out e2, out p12, out p22);
            }

            s1.Connect(e2, CityPathType.privates);
            s2.Connect(e1, CityPathType.privates);
        }
示例#3
0
        /// <summary>
        /// Initialize graphics settings (screen size etc'), and call SetupGame.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            graphics.PreferredBackBufferWidth  = GAME_WIDTH;
            graphics.PreferredBackBufferHeight = GAME_HEIGHT;
            graphics.ApplyChanges();

            IsFixedTimeStep   = true;
            TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / Util.ToTicks(1));

            IsMouseVisible = true;

            sideMenu = new StackPanel(GAME_WIDTH - 350, 0, 350, GAME_HEIGHT);

            CityBuilder builder = new CityBuilder();

            BuilderTrafficCircleNode i1 = new BuilderTrafficCircleNode(430, 415);
            BuilderAllWayStopNode    i2 = new BuilderAllWayStopNode(940, 415);

            BuilderDeadEndNode e1top    = new BuilderDeadEndNode(430, 50, 0);
            BuilderDeadEndNode e1left   = new BuilderDeadEndNode(65, 415, MathHelper.ToRadians(-90));
            BuilderDeadEndNode e1bottom = new BuilderDeadEndNode(430, 780, MathHelper.ToRadians(180));

            BuilderDeadEndNode e2top    = new BuilderDeadEndNode(940, 50, MathHelper.ToRadians(0));
            BuilderDeadEndNode e2right  = new BuilderDeadEndNode(1310, 415, MathHelper.ToRadians(90));
            BuilderDeadEndNode e2bottom = new BuilderDeadEndNode(940, 780, MathHelper.ToRadians(180));

            CityBuilderParkingTwoLanePath connection = new CityBuilderParkingTwoLanePath(i1, i2);

            i1.right = connection;
            i2.left  = connection;

            CityBuilderParkingTwoLanePath i1top = new CityBuilderParkingTwoLanePath(i1, e1top);

            i1.top = i1top;
            CityBuilderParkingTwoLanePath i1left = new CityBuilderParkingTwoLanePath(i1, e1left);

            i1.left = i1left;
            CityBuilderParkingTwoLanePath i1bottom = new CityBuilderParkingTwoLanePath(i1, e1bottom);

            i1.bottom = i1bottom;

            CityBuilderParkingTwoLanePath i2right = new CityBuilderParkingTwoLanePath(i2, e2right);

            i2.right = i2right;
            CityBuilderParkingTwoLanePath i2top = new CityBuilderParkingTwoLanePath(i2, e2top);

            i2.top = i2top;
            CityBuilderParkingTwoLanePath i2bottom = new CityBuilderParkingTwoLanePath(i2, e2bottom);

            i2.bottom = i2bottom;

            builder.nodes.Add(i1);
            builder.nodes.Add(i2);
            builder.nodes.Add(e1top);
            builder.nodes.Add(e1left);
            builder.nodes.Add(e1bottom);
            builder.nodes.Add(e2right);
            builder.nodes.Add(e2top);
            builder.nodes.Add(e2bottom);
            builder.paths.Add(connection);
            builder.paths.Add(i1top);
            builder.paths.Add(i1bottom);
            builder.paths.Add(i1left);
            builder.paths.Add(i2right);
            builder.paths.Add(i2top);
            builder.paths.Add(i2bottom);
            city = builder.Build();

            Random r = new Random();

            foreach (CityNode n in city.nodes)
            {
                if (n is ParkingNode)
                {
                    //vehicles.Add(new GasolineCar(n));
                }
            }

            CityNode work1 = new CityNode(1200, 300);
            CityNode work2 = new CityNode(1100, 600);

            city.nodes.Add(work1);
            city.nodes.Add(work2);

            CityNode n1 = city.NearestNode(1200, 300, CityPathType.pedestrians);

            work1.Connect(n1, CityPathType.pedestrians);
            n1.Connect(work1, CityPathType.pedestrians);
            CityNode n2 = city.NearestNode(1100, 600, CityPathType.pedestrians);

            work2.Connect(n2, CityPathType.pedestrians);
            n2.Connect(work2, CityPathType.pedestrians);


            CityNode[] homes = new CityNode[]
            {
                new CityNode(250, 200),
                new CityNode(270, 300),
                new CityNode(120, 300),
                new CityNode(570, 100),
                new CityNode(570, 210),
                new CityNode(220, 560),
                new CityNode(550, 560),
                new CityNode(580, 700),
                new CityNode(750, 560),
                new CityNode(780, 720),
                new CityNode(780, 310),
                new CityNode(1080, 720),
                new CityNode(1080, 100),
            };

            foreach (CityNode home in homes)
            {
                city.nodes.Add(home);
                CityNode n = city.NearestNode((int)home.x, (int)home.y, CityPathType.pedestrians);
                home.Connect(n, CityPathType.pedestrians);
                n.Connect(home, CityPathType.pedestrians);

                CityNode park = City.ClosestParking(n);

                GasolineCar c = new GasolineCar(park);
                vehicles.Add(c);

                Commuter guy = new Commuter(home, home, r.Next(2) == 0 ? work1 : work2, c);
                debugObjects.Add(guy);
            }
        }
        public override void Build(City c)
        {
            MergePoint m1  = new MergePoint();
            CityNode   nw1 = wTop = new MergeNode(x - 40, y - 80, m1, "nw1");
            CityNode   ne1 = eTop = new CityNode(x + 40, y - 80, "ne1");
            CityPath   p1  = ne1.Connect(nw1, CityPathType.privates);

            m1.priority = p1;

            MergePoint m2  = new MergePoint();
            CityNode   nw2 = wLeft = new MergeNode(x - 80, y + 40, m2, "nw2");
            CityNode   ne2 = eLeft = new CityNode(x - 80, y - 40, "ne2");
            CityPath   p2  = ne2.Connect(nw2, CityPathType.privates);

            m2.priority = p2;

            MergePoint m3  = new MergePoint();
            CityNode   nw3 = wBottom = new MergeNode(x + 40, y + 80, m3, "nw3");
            CityNode   ne3 = eBottom = new CityNode(x - 40, y + 80, "ne3");
            CityPath   p3  = ne3.Connect(nw3, CityPathType.privates);

            m3.priority = p3;

            MergePoint m4  = new MergePoint();
            CityNode   nw4 = wRight = new MergeNode(x + 80, y - 40, m4, "nw4");
            CityNode   ne4 = eRight = new CityNode(x + 80, y + 40, "ne4");
            CityPath   p4  = ne4.Connect(nw4, CityPathType.privates);

            m4.priority = p4;

            nw1.Connect(ne2, CityPathType.privates, 40);
            nw2.Connect(ne3, CityPathType.privates, 40);
            nw3.Connect(ne4, CityPathType.privates, 40);
            nw4.Connect(ne1, CityPathType.privates, 40);

            pTopLeft     = new CityNode(x - 100, y - 100);
            pTopRight    = new CityNode(x + 100, y - 100);
            pBottomLeft  = new CityNode(x - 100, y + 100);
            pBottomRight = new CityNode(x + 100, y + 100);

            pTopLeft.Connect(pTopRight, CityPathType.pedestrians);
            pTopLeft.Connect(pBottomLeft, CityPathType.pedestrians);

            pTopRight.Connect(pTopLeft, CityPathType.pedestrians);
            pTopRight.Connect(pBottomRight, CityPathType.pedestrians);

            pBottomLeft.Connect(pBottomRight, CityPathType.pedestrians);
            pBottomLeft.Connect(pTopLeft, CityPathType.pedestrians);

            pBottomRight.Connect(pBottomLeft, CityPathType.pedestrians);
            pBottomRight.Connect(pTopRight, CityPathType.pedestrians);

            c.nodes.Add(pTopLeft);
            c.nodes.Add(pTopRight);
            c.nodes.Add(pBottomLeft);
            c.nodes.Add(pBottomRight);

            c.nodes.Add(nw1);
            c.nodes.Add(ne1);

            c.nodes.Add(nw2);
            c.nodes.Add(ne2);

            c.nodes.Add(nw3);
            c.nodes.Add(ne3);

            c.nodes.Add(nw4);
            c.nodes.Add(ne4);
        }
示例#5
0
        public override void Build(City c)
        {
            if (this.n1 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n1 = this.n1 as BuilderAllWayStopNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n1 = this.n1 as BuilderTrafficCircleNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }
            if (this.n1 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n1 = this.n1 as BuilderDeadEndNode;
                n1.Connect(this, out s1, out e1, out p11, out p12);
            }


            if (this.n2 is BuilderAllWayStopNode)
            {
                BuilderAllWayStopNode n2 = this.n2 as BuilderAllWayStopNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderTrafficCircleNode)
            {
                BuilderTrafficCircleNode n2 = this.n2 as BuilderTrafficCircleNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }
            if (this.n2 is BuilderDeadEndNode)
            {
                BuilderDeadEndNode n2 = this.n2 as BuilderDeadEndNode;
                n2.Connect(this, out s2, out e2, out p21, out p22);
            }

            double dist      = Util.Distance(s1.x, s1.y, e2.x, e2.y);
            int    parkCount = (int)(dist / PARKING_LENGTH);
            double dir       = Util.GetLookatDir(s1.x, s1.y, e2.x, e2.y);

            CityNode last     = s1;
            CityNode lastPark = p11;

            for (int i = 1; i <= parkCount; i++)
            {
                int       x    = s1.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int       y    = s1.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                MergeNode exit = new MergeNode(x, y, new MergePoint());

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                CityPath priority = last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                (exit.intersection as MergePoint).priority = priority;

                last     = exit;
                lastPark = park;
            }
            last.Connect(e2, CityPathType.privates);
            lastPark.Connect(p22, CityPathType.pedestrians);
            p22.Connect(lastPark, CityPathType.pedestrians);


            dist      = Util.Distance(s2.x, s2.y, e1.x, e1.y);
            parkCount = (int)(dist / PARKING_LENGTH);
            dir       = Util.GetLookatDir(s2.x, s2.y, e1.x, e1.y);

            last     = s2;
            lastPark = p21;
            for (int i = 1; i <= parkCount; i++)
            {
                int      x    = s2.x + (int)(i * PARKING_LENGTH * Math.Cos(dir));
                int      y    = s2.y + (int)(i * PARKING_LENGTH * Math.Sin(dir));
                CityNode exit = new CityNode(x, y);

                x -= (int)(PARKING_LENGTH / 2 * Math.Cos(dir));
                x += (int)(20 * Math.Cos(dir + Math.PI / 2));
                y -= (int)(PARKING_LENGTH / 2 * Math.Sin(dir));
                y += (int)(20 * Math.Sin(dir + Math.PI / 2));
                ParkingNode park = new ParkingNode(x, y);

                last.Connect(exit, CityPathType.privates);
                last.Connect(park, CityPathType.privates);
                park.Connect(exit, CityPathType.privates);

                lastPark.Connect(park, CityPathType.pedestrians);
                park.Connect(lastPark, CityPathType.pedestrians);

                c.nodes.Add(exit);
                c.nodes.Add(park);

                last     = exit;
                lastPark = park;
            }
            last.Connect(e1, CityPathType.privates);
            lastPark.Connect(p12, CityPathType.pedestrians);
            p12.Connect(lastPark, CityPathType.pedestrians);
        }
        public override void Build(City c)
        {
            StopSignIntersection i = new StopSignIntersection();

            CityNode nw1 = wTop = new StopSignNode(x - 40, y - 80, i, "nw1");
            CityNode nl1 = new CityNode(x - 40, y, "nl1");
            CityNode ne1 = eTop = new IntersectionExitNode(x + 40, y - 80, i, "ne1");

            nw1.Connect(nl1, CityPathType.privates);

            CityNode nw2 = wLeft = new StopSignNode(x - 80, y + 40, i, "nw2");
            CityNode nl2 = new CityNode(x, y + 40, "nl2");
            CityNode ne2 = eLeft = new IntersectionExitNode(x - 80, y - 40, i, "ne2");

            nw2.Connect(nl2, CityPathType.privates);

            CityNode nw3 = wBottom = new StopSignNode(x + 40, y + 80, i, "nw3");
            CityNode nl3 = new CityNode(x + 40, y, "nl3");
            CityNode ne3 = eBottom = new IntersectionExitNode(x - 40, y + 80, i, "ne3");

            nw3.Connect(nl3, CityPathType.privates);

            CityNode nw4 = wRight = new StopSignNode(x + 80, y - 40, i, "nw4");
            CityNode nl4 = new CityNode(x, y - 40, "nl4");
            CityNode ne4 = eRight = new IntersectionExitNode(x + 80, y + 40, i, "ne4");

            nw4.Connect(nl4, CityPathType.privates);

            nl1.Connect(ne3, CityPathType.privates);
            nl2.Connect(ne4, CityPathType.privates);
            nl3.Connect(ne1, CityPathType.privates);
            nl4.Connect(ne2, CityPathType.privates);

            nl1.Connect(nl2, CityPathType.privates, 40);
            nl2.Connect(nl3, CityPathType.privates, 40);
            nl3.Connect(nl4, CityPathType.privates, 40);
            nl4.Connect(nl1, CityPathType.privates, 40);

            nw1.Connect(ne2, CityPathType.privates, 40);
            nw2.Connect(ne3, CityPathType.privates, 40);
            nw3.Connect(ne4, CityPathType.privates, 40);
            nw4.Connect(ne1, CityPathType.privates, 40);

            pTopLeft     = new CityNode(x - 100, y - 100);
            pTopRight    = new CityNode(x + 100, y - 100);
            pBottomLeft  = new CityNode(x - 100, y + 100);
            pBottomRight = new CityNode(x + 100, y + 100);

            pTopLeft.Connect(pTopRight, CityPathType.pedestrians);
            pTopLeft.Connect(pBottomLeft, CityPathType.pedestrians);

            pTopRight.Connect(pTopLeft, CityPathType.pedestrians);
            pTopRight.Connect(pBottomRight, CityPathType.pedestrians);

            pBottomLeft.Connect(pBottomRight, CityPathType.pedestrians);
            pBottomLeft.Connect(pTopLeft, CityPathType.pedestrians);

            pBottomRight.Connect(pBottomLeft, CityPathType.pedestrians);
            pBottomRight.Connect(pTopRight, CityPathType.pedestrians);

            c.nodes.Add(pTopLeft);
            c.nodes.Add(pTopRight);
            c.nodes.Add(pBottomLeft);
            c.nodes.Add(pBottomRight);

            c.nodes.Add(nw1);
            c.nodes.Add(nl1);
            c.nodes.Add(ne1);

            c.nodes.Add(nw2);
            c.nodes.Add(nl2);
            c.nodes.Add(ne2);

            c.nodes.Add(nw3);
            c.nodes.Add(nl3);
            c.nodes.Add(ne3);

            c.nodes.Add(nw4);
            c.nodes.Add(nl4);
            c.nodes.Add(ne4);
        }