Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        BuildingGrid = new GameObject[GridWidth, GridHeight];
        PosGrid      = new bool[GridWidth, GridHeight];
        obs_timer    = new Timer(5000);
        //loading map

        Vector2 map_pos = Vector2.zero;

        for (int m = 0; m < 4; m++)
        {
            map_pos = new Vector2((m % 2) * 5, (m / 2) * 5);

            int angle = Subs.GetRandom(new int[] { 0, 90, 180, 270 });

            var     map  = Subs.GetRandom(Maps);
            int     w    = map.map_data.GetLength(1);
            int     h    = map.map_data.GetLength(0);
            Vector2 size = new Vector2(w, h);
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    Vector2 pos = new Vector2(x, y);

                    pos = RotateArrayVector2(pos, size, angle);

                    pos.y = h - 1 - pos.y;

                    pos += map_pos;

                    if (map.map_data[y, x] == 1)
                    {
                        AddBuilding((int)pos.x, (int)pos.y);
                    }
                    if (map.map_data[y, x] == 2)
                    {
                        AddCheckPoint((int)pos.x, (int)pos.y);
                    }
                }
            }
        }

        var goal = raceController.CheckPoints[Subs.GetRandom(raceController.CheckPoints.Count)];

        goal.IsGoal             = true;
        raceController.StartPos = goal;

        raceController.CreateCars();

        CameraGo.transform.position =
            new Vector3(raceController.StartPos.transform.position.x,
                        CameraGo.transform.position.x,
                        raceController.StartPos.transform.position.z
                        );

        AStar.Scan();
    }