Esempio n. 1
0
    void Start()
    {
        if (level == null || level.startRoom == null)
        {
            return;
        }

        hash = new XXHash(level.seed);

        generatedRooms = new List <Room>();
        generatedRooms.Add(Instantiate(level.startRoom));

        StartCoroutine(SpawnNextRoom(generatedRooms[plop], hash.GetHash(generatedRooms.Count())));
        // TODO: Spawn filler rooms
        // TODO: Check if level has [Shop, Loot, Combat, etc]
    }
Esempio n. 2
0
    IEnumerator SpawnNextRoom(Room last, uint hashValue)
    {
        XXHash             roomHash       = new XXHash((int)hashValue);
        SpawnPoint         spawnPoint     = last.spawnPoints.ElementAt(roomHash.Range(0, last.spawnPoints.Count(), (int)hashValue));
        IEnumerable <Room> availableRooms =
            rooms.Where(room => checkInverse(room, spawnPoint) && !checkTag(room, ETag.END) && !checkTag(room, ETag.BLOCK_END));
        Room roomToSpawn = availableRooms.ElementAt(roomHash.Range(0, availableRooms.Count(), (int)hashValue));

        // if (plop < 10) {
        //     roomToSpawn = availableRooms.ElementAt(roomHash.Range(0, availableRooms.Count(), (int) hashValue));
        // } else {
        //     roomToSpawn = rooms.First(room => checkTag(room, ETag.BLOCK_END));
        //     plop = 0;
        // }

        Room       spawnedRoom     = Instantiate(roomToSpawn, Vector2.zero, roomToSpawn.transform.rotation);
        SpawnPoint otherSpawnPoint =
            spawnedRoom.spawnPoints.First(sp => sp.orientation == inverseOrientation(spawnPoint.orientation));

        spawnedRoom.transform.position = spawnPoint.transform.position + -otherSpawnPoint.transform.position;

        yield return(new WaitForSeconds(0.05f));

        if (!spawnedRoom.overlaps)
        {
            last.DestroySpawnPoint(spawnPoint);
            spawnedRoom.DestroySpawnPoint(otherSpawnPoint);
            generatedRooms.Add(spawnedRoom);
        }
        else
        {
            Destroy(spawnedRoom.gameObject);
        }

        yield return(generatedRooms.Count() < level.minimumRooms ?
                     StartCoroutine(SpawnNextRoom(generatedRooms[last.spawnPoints.Count() == 0 ? ++plop : plop], hash.GetHash(hashValue))) : null);
    }
Esempio n. 3
0
        private float GetRandomXXHash(int x, int z, int seed)
        {
            var randomHashObject = new XXHash(seed);

            return(randomHashObject.GetHash(x, z));
        }
Esempio n. 4
0
 //returns an rng for each surface unit
 public static System.Random surfaceRandom(SurfaceUnit su)
 {
     //system.random takes a seed that is calculated from the hash function
     //1 is the planet num, will eventually need a way to calculate this
     return(new System.Random((int)hash.GetHash(su.u, su.v, (int)su.side, 1)));
 }