コード例 #1
0
 public void SpawnFloormakerCopy(Vector3 coordinates)
 {
     FloorMakerInstance                  = Instantiate(FloorMakerPrefab, coordinates, Quaternion.identity) as FloorMaker;
     FloorMakerInstance.Level            = this;
     FloorMakerInstance.transform.parent = this.transform;
     StartCoroutine(FloorMakerInstance.GenerateSideRooms());
     CurrentFloorMakers++;
 }
コード例 #2
0
    public void SpawnFloorMaker()
    {
        Vector3 coordinates = new Vector3(1, 0, 1);

        FloorMakerInstance                  = Instantiate(FloorMakerPrefab, coordinates, Quaternion.identity) as FloorMaker;
        FloorMakerInstance.Level            = this;
        FloorMakerInstance.transform.parent = this.transform;
        StartCoroutine(FloorMakerInstance.GenerateLevel());
        CurrentFloorMakers++;
    }
コード例 #3
0
    void Update()
    {
//		If counter is less than 50, then:
        if ((myCounter < counterLife || !clone))          //&& globalFloorCount < 500) || !clone ) {
//			Generate a random number from 0.0f to 1.0f;
        {
            float randomNumber = Random.Range(0.0f, 1.0f);
//			If random number is less than 0.25f, then rotate myself 90 degrees on Z axis;
            if (randomNumber < 0.08f)
            {
                transform.eulerAngles += new Vector3(0f, 0f, 90f);
            }
//				... Else if number is 0.25f-0.5f, then rotate myself -90 degrees on Z axis;
            else if (randomNumber < 0.16f)
            {
                transform.eulerAngles += new Vector3(0f, 0f, -90f);
            }
//				... Else if number is 0.99f-1.0f, then instantiate a floorMakerPrefab clone at my current position;
            else if (randomNumber >= 0.99f)
            {
                FloorMaker myClone = Instantiate(floorMakerPrefab, transform.position, transform.rotation);
                //The clone will also be rotated and pushed forward
                float randomNumber2 = Random.Range(0.0f, 100f);
                if (randomNumber2 < 50f)
                {
                    myClone.transform.eulerAngles += new Vector3(0f, 0f, 90f);
                }
                else
                {
                    myClone.transform.eulerAngles += new Vector3(0f, 0f, -90f);
                }
                myClone.transform.position += myClone.transform.up;
                myClone.clone = true;
                //Debug.Log("H");
            }
//			// end elseIf
//			Instantiate a floorPrefab clone at current position;
            Instantiate(floorPrefab, transform.position, transform.rotation);
//			Move 1 unit "upwards" based on this object's local rotation (e.g. with rotation 0,0,0 "upwards" is (0,1,0)... but with rotation 0,0,180 then "upwards" is (0,-1, 0)... )
            transform.position += transform.up;
//			Increment counter;
            myCounter++;
            globalFloorCount++;
        }
//		Else:
        else
        {
            //At the end of the life of each clone, it creates a room
//			Destroy my game object;         // self destruct if I've made enough tiles already
            Instantiate(floorPrefab, transform.position, transform.rotation);
            //Moves along creating a room
            if (x == 0 && y == 0)
            {
                transform.position -= transform.right * roomOffset;
                x++;
                Instantiate(floorPrefab, transform.position, transform.rotation);
            }
            else if (x == roomWidth)
            {
                if (y == roomHeight)
                {
                    Destroy(this.gameObject);
                }
                else
                {
                    x = 0;
                    y++;
                    transform.position += transform.up;
                    transform.position -= transform.right * roomWidth;
                }
            }
            else
            {
                x++;
                transform.position += transform.right;
            }
        }
        //TO DO (possibly): allows more hallways to be created out from the sides
    }
コード例 #4
0
ファイル: MapMaker.cs プロジェクト: Krosantos/Time-Bubble
    void MakeFloors()
    {
        floorMakers.Add(new FloorMaker(Vector2.one*500f, Vector2.right, turnchance, turnaroundchance));

        // make start tile
        GameObject startTile = (GameObject)Instantiate(start,Vector2.one*500f,Quaternion.identity);
        startTile.transform.parent = transform;

        // mark start tile in array and check adjacent tiles
        tilemap[(int)startTile.transform.position.x,(int)startTile.transform.position.y].SetTile(startTile);
        tilemap[(int)startTile.transform.position.x,(int)startTile.transform.position.y].isStart = true;
        MarkAdjacentTiles(startTile);
        spawnpoint = startTile.transform.position;

        while (iterations >= 0){
            List<FloorMaker> floorMakersToAdd = new List<FloorMaker>();
            foreach (FloorMaker f in floorMakers){
                Vector2 v = f.Move();
                if (tilemap[(int)v.x,(int)v.y].isEmpty){
                    // make a new tile
                    GameObject newTile = (GameObject)Instantiate(floor, v, Quaternion.identity);
                    newTile.transform.parent = transform;
                    // mark tile in array and check adjacent tiles
                    tilemap[(int)newTile.transform.position.x,(int)newTile.transform.position.y].SetTile(newTile);
                    MarkAdjacentTiles(newTile);
                    iterations--;
                }

                // spawn new floormakers to create branches?
                if (Random.Range(0f,1f) < splitchance){
                    FloorMaker newf = new FloorMaker(f.position, f.direction, turnchance, turnaroundchance);
                    newf.Turn();
                    floorMakersToAdd.Add(newf);
                }

                // make a room?
                if (Random.Range(0f,1f) < roomchance){
                    for (int i = 0; i < roomsizeX; i++){
                        for (int j = 0; j < roomsizeY; j++){
                            if (tilemap[(int)v.x+i,(int)v.y+j].isEmpty){
                                GameObject newTile = (GameObject)Instantiate(floor, v + new Vector2(i,j), Quaternion.identity);
                                newTile.transform.parent = transform;
                                tilemap[(int)newTile.transform.position.x,(int)newTile.transform.position.y].SetTile(newTile);
                                MarkAdjacentTiles(newTile);
                            }
                        }
                    }
                }
            }

            // add any new floormakers
            foreach (FloorMaker f in floorMakersToAdd){
                floorMakers.Add(f);
            }

            // destroy excess floormakers
            while (floorMakers.Count > maxFloorMakers){
                floorMakers.RemoveAt(0);
            }

        }

        // find farthest active floormaker at end of generation
        float farthestDoorDistance = 0f;
        Vector2 farthestDoorPosition = new Vector2();
        foreach (FloorMaker f in floorMakers){
            float distance = ((Vector2)f.position - (Vector2)startTile.transform.position).magnitude;
            if (distance > farthestDoorDistance){
                farthestDoorDistance = ((Vector2)f.position - (Vector2)startTile.transform.position).magnitude;
                farthestDoorPosition = f.position;
            }
        }

        // make a door at farthest floormaker location
        Tile t = tilemap[(int)farthestDoorPosition.x,(int)farthestDoorPosition.y];
        Destroy(t.tile);
        GameObject newDoor = (GameObject)Instantiate(door, farthestDoorPosition, Quaternion.identity);
        newDoor.transform.parent = transform;
        tilemap[(int)newDoor.transform.position.x,(int)newDoor.transform.position.y].SetTile(newDoor);
        tilemap[(int)newDoor.transform.position.x,(int)newDoor.transform.position.y].isDoor = true;

        // find key location & place enemies
        float distanceFromSpawn = 10f; // these two variables also function as the minimum key distance from either location
        float distanceFromDoor = 10f;
        Vector2 keyPosition = new Vector2();
        for (int i = 0; i < 1000; i++){
            for (int j = 0; j < 1000; j++){
                if (!tilemap[i,j].isEmpty && !tilemap[i,j].isStart && !tilemap[i,j].isDoor){
                    Vector2 tileposition = tilemap[i,j].tile.transform.position;
                    float tileDistanceFromSpawn = ((Vector2)tileposition - (Vector2)startTile.transform.position).magnitude;
                    float tileDistanceFromDoor = ((Vector2)tileposition - (Vector2)newDoor.transform.position).magnitude;

                    if ((tileDistanceFromSpawn > distanceFromSpawn) && (tileDistanceFromDoor > distanceFromDoor)){
                        distanceFromSpawn = tileDistanceFromSpawn;
                        distanceFromDoor = tileDistanceFromDoor;
                        keyPosition = tileposition;
                    }

                    if (tileDistanceFromSpawn > minEnemyDistance){
                        float r = Random.Range(0f,1f);
                        if (r < enemySpawnRate){
                            int randint = Random.Range(0, enemy.Count);
                            Instantiate(enemy[randint], tileposition, Quaternion.identity);
                        }
                    }
                }
            }
        }

        // make a key
        t = tilemap[(int)keyPosition.x,(int)keyPosition.y];
        Destroy(t.tile);
        GameObject newKey = (GameObject)Instantiate(key, keyPosition, Quaternion.identity);
        newKey.transform.parent = transform;
        tilemap[(int)newKey.transform.position.x,(int)newKey.transform.position.y].SetTile(newKey);

        MakeWalls();
    }