public GeneratorChunk GetFullyGeneratedChunk(IntVector2 gridPosition)
        {
            GeneratorChunk chunk = GetChunk(gridPosition);

            if (chunk.CurrentState != GeneratorChunk.State.Done)
            {
                if (_activeTask != null)
                {
                    if (chunk.CurrentState != GeneratorChunk.State.ReadyToTriggerNeighbours)
                    {
                        _activeTask.Wait();
                    }
                    if (_activeTask.IsCompleted)
                    {
                        _activeTask = null;
                    }
                }
                if (_activeTask == null)
                {
                    chunk.GenerateToState(GeneratorChunk.State.Done);
                    _activeTask = Task.Run(() => PrepareNeighbours(chunk));
                }
            }
            return(chunk);
        }
 private void PrepareNeighbours(GeneratorChunk chunk)
 {
     foreach (Direction direction in DirectionSupport.VALUES)
     {
         GetChunk(chunk, direction).GenerateToState(GeneratorChunk.State.ReadyToTriggerNeighbours);
     }
 }
 private GeneratorChunk GetChunkByIndex(IntVector2 chunkIndex)
 {
     if (!_chunks.ContainsKey(chunkIndex))
     {
         _chunks[chunkIndex] = new GeneratorChunk(this, _world, chunkIndex);
     }
     return(_chunks[chunkIndex]);
 }
        private GeneratorChunk GetBiomeChunk(GeneratorChunk chunk, IntVector2 offset)
        {
            int        x          = Mathx.DivideRoundDown(chunk.ChunkIndex.x, _biomeSizeInChunks);
            int        y          = Mathx.DivideRoundDown(chunk.ChunkIndex.y, _biomeSizeInChunks);
            IntVector2 chunkIndex = new IntVector2(x, y);

            chunkIndex += offset;
            chunkIndex *= _biomeSizeInChunks;
            return(GetChunkByIndex(chunkIndex));
        }
コード例 #5
0
    public IEnumerator CreateTraders()
    {
        for (int idx = 0; idx < numberTrader; ++idx)
        {
            GeneratorChunk chunk     = safeRoom[Random.Range(0, safeRoom.Count)];
            float          chunkPosX = chunk.Location.x + 0.5f;
            float          chunkPosY = chunk.Location.y + 0.5f;
            int            x         = Random.Range((int)chunkPosX * (int)grid.chunkSize, ((int)(chunkPosX + 0.5f)) * (int)grid.chunkSize);
            int            y         = Random.Range((int)chunkPosY * (int)grid.chunkSize, ((int)(chunkPosY + 0.5f)) * (int)grid.chunkSize);

            Trader newTrader = Instantiate(trader, new Vector3(x, 0, y), Quaternion.identity) as Trader;
            newTrader.transform.SetParent(transform.parent);

            yield return(0);
        }
    }
コード例 #6
0
    private void SpawnSafeZoneCampfire()
    {
        GeneratorGrid        grid         = GetComponent <GeneratorGrid>();
        List <GeneratorRoom> safeRoomList = grid.SafeRoomList;

        foreach (GeneratorRoom room in safeRoomList)
        {
            GeneratorChunk chunk = room.chunks[Random.Range(0, room.chunks.Count)];

            float x = Random.Range(chunk.Location.x * (int)grid.chunkSize, (chunk.Location.x + 1) * (int)grid.chunkSize);
            float y = Random.Range(chunk.Location.y * (int)grid.chunkSize, (chunk.Location.y + 1) * (int)grid.chunkSize);

            SafeZone newCampfireSafeZone = Instantiate(safeZoneCampfire, new Vector3(x, 0, y), Quaternion.identity) as SafeZone;
            newCampfireSafeZone.transform.SetParent(transform.parent);
        }
    }
コード例 #7
0
ファイル: GeneratorGrid.cs プロジェクト: Halloweens/RogueRpg
    public bool IsRoom(int xPosition, int yPosition)
    {
        GeneratorChunk chunk = GetChunk(xPosition, yPosition);

        if (chunk == null)
        {
            return(false);
        }

        foreach (GeneratorRoom room in roomList)
        {
            if (room.chunks.Find(x => x == chunk) != null)
            {
                return(true);
            }
        }

        return(false);
    }
コード例 #8
0
    public IEnumerator CreateEnemies()
    {
        for (int idx = 0; idx < numberOfEnemies; ++idx)
        {
            List <GeneratorChunk> room = unSafeRoomList[UnityEngine.Random.Range(0, unSafeRoomList.Count)].chunks;

            GeneratorChunk chunk = room[UnityEngine.Random.Range(0, room.Count)];
            float          x     = UnityEngine.Random.Range(chunk.Location.x * (int)grid.chunkSize, (chunk.Location.x + 1) * (int)grid.chunkSize);
            float          y     = UnityEngine.Random.Range(chunk.Location.y * (int)grid.chunkSize, (chunk.Location.y + 1) * (int)grid.chunkSize);

            Enemy newEnemy = Instantiate(enemy, new Vector3(x, 1.5f, y), Quaternion.identity) as Enemy;
            newEnemy.transform.SetParent(transform.parent);
            newEnemy.AllItems = allItems;

            yield return(0);
        }

        FireAllEnemiesCreated();
    }
コード例 #9
0
    public void SpawnBoss()
    {
        GeneratorGrid         grid           = GetComponent <GeneratorGrid>();
        RoomList              unSafeRoomList = grid.UnSafeRoomList;
        List <GeneratorChunk> room           = unSafeRoomList[Random.Range(0, unSafeRoomList.Count)].chunks;

        GeneratorChunk chunk = room[Random.Range(0, room.Count)];

        float x = Random.Range(chunk.Location.x * (int)grid.chunkSize, (chunk.Location.x + 1) * (int)grid.chunkSize);
        float y = Random.Range(chunk.Location.y * (int)grid.chunkSize, (chunk.Location.y + 1) * (int)grid.chunkSize);

        Enemy theBoss = Instantiate(boss, new Vector3(x, 0, y), Quaternion.identity) as Enemy;

        theBoss.transform.SetParent(transform.parent);

        if (bossCreated != null)
        {
            bossCreated();
        }
    }
コード例 #10
0
    private void SpawnPortal()
    {
        GeneratorGrid         grid           = GetComponent <GeneratorGrid>();
        RoomList              unSafeRoomList = grid.UnSafeRoomList;
        List <GeneratorChunk> room           = unSafeRoomList[Random.Range(0, unSafeRoomList.Count)].chunks;

        GeneratorChunk chunk = room[Random.Range(0, room.Count)];

        float x = Random.Range(chunk.Location.x * (int)grid.chunkSize, (chunk.Location.x + 1) * (int)grid.chunkSize);
        float y = Random.Range(chunk.Location.y * (int)grid.chunkSize, (chunk.Location.y + 1) * (int)grid.chunkSize);

        PortalToOtherLevel newPortal = Instantiate(portal, new Vector3(x, 0, y), Quaternion.identity) as PortalToOtherLevel;

        newPortal.transform.SetParent(transform.parent);

        if (portalCreated != null)
        {
            portalCreated();
        }
    }
コード例 #11
0
    public IEnumerator CreatePlayer()
    {
        safeRoom = safeRoomList[Random.Range(0, safeRoomList.Count)].chunks;

        GeneratorChunk chunk     = safeRoom[Random.Range(0, safeRoom.Count)];
        float          chunkPosX = chunk.Location.x + 0.5f;
        float          chunkPosY = chunk.Location.y + 0.5f;
        int            x         = Random.Range((int)chunkPosX * (int)grid.chunkSize, ((int)(chunkPosX + 0.5f)) * (int)grid.chunkSize);
        int            y         = Random.Range((int)chunkPosY * (int)grid.chunkSize, ((int)(chunkPosY + 0.5f)) * (int)grid.chunkSize);


        Player newPlayer = Instantiate(player, new Vector3(x, 0.1f, y), Quaternion.identity) as Player;

        newPlayer.transform.SetParent(transform.parent);
        createdPlayer = newPlayer;

        CreateCamera(newPlayer);
        CreateUIRoot(newPlayer);

        yield return(0);
    }
コード例 #12
0
ファイル: GeneratorGrid.cs プロジェクト: Halloweens/RogueRpg
    private GeneratorChunk CreateChunk(Vector2i chunkPos, GeneratorChunk prefab, Color color, GameObject parent = null)
    {
        if (chunks[chunkPos.x, chunkPos.y] != null)
        {
            return(null);
        }

        GeneratorChunk chunk = Instantiate(prefab) as GeneratorChunk;

        //GeneratorChunk ceiling = (GeneratorChunk)Instantiate(prefab);
        chunk.Initialize(this, chunkPos);
        //ceiling.Initialize(this, chunkPos);

        chunks[chunkPos.x, chunkPos.y] = chunk;

        GameObject chunkGo = chunk.gameObject;

        //GameObject ceilingGo = ceiling.gameObject;

        chunkGo.name = "Ground";
        //ceilingGo.name = "Ceiling";

        chunkGo.transform.position = new Vector3(chunkPos.x * chunkSize + chunkGo.transform.position.x, 0f, chunkPos.y * chunkSize + chunkGo.transform.position.z);
        //ceilingGo.transform.position = new Vector3(chunkPos.x * chunkSize + ceilingGo.transform.position.x, 5f, chunkPos.y * chunkSize + ceilingGo.transform.position.z);
        //to modify
        chunkGo.transform.localScale = new Vector3(chunkSize / 10, 1f, chunkSize / 10);
        //ceilingGo.transform.localScale = new Vector3(chunkSize / 10, 1f, chunkSize / 10);

        //Debug//chunkGo.GetComponentInChildren<Renderer>().material.color = color;
        //ceilingGo.GetComponentInChildren<Renderer>().material.color = color;

        if (parent != null)
        {
            chunkGo.transform.SetParent(parent.transform);
            //ceilingGo.transform.SetParent(parent.transform);
        }


        return(chunk);
    }
コード例 #13
0
ファイル: GeneratorGrid.cs プロジェクト: Halloweens/RogueRpg
    public GeneratorRoom CreateRoom(Vector2i chunkPos, GeneratorChunk groundPrefab, Vector2i roomSize, bool isSecure = false)
    {
        GeneratorRoom newRoom = new GeneratorRoom();
        GameObject    room    = new GameObject();

        room.transform.SetParent(parent.transform);
        Color testColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1.0f);

        room.name = "Room";

        for (int i = 0; i < roomSize.y; i++)
        {
            for (int j = 0; j < roomSize.x; j++)
            {
                GeneratorChunk c = CreateChunk(chunkPos + new Vector2i(j, i), groundPrefab, testColor, room);
                newRoom.chunks.Add(c);
            }
        }

        if (isSecure)
        {
            newRoom.isSafe = true;
            room.name      = "SecureRoom";
            safeRoomList.Add(newRoom);
        }
        else
        {
            unSafeRoomList.Add(newRoom);
        }

        newRoom.location = chunkPos;
        newRoom.size     = roomSize;

        roomList.Add(newRoom);

        return(newRoom);
    }
 public GeneratorChunk GetBiomeChunk(GeneratorChunk chunk)
 {
     return(GetBiomeChunk(chunk, IntVector2.ZERO));
 }
コード例 #15
0
ファイル: GeneratorGrid.cs プロジェクト: Halloweens/RogueRpg
    public GeneratorCorridor CreateCorridor(GeneratorChunk groundPrefab, Vector2i room1Pos, Vector2i room2Pos)
    {
        GeneratorCorridor newCorridor = new GeneratorCorridor();

        Color      testColor = new Color(0.9f, 0.9f, 0.9f, 1.0f);
        Vector2i   currPos   = room1Pos;
        GameObject corridor  = new GameObject();

        corridor.transform.SetParent(parent.transform);
        corridor.name = "Corridor";

        while (currPos.x != room2Pos.x || currPos.y != room2Pos.y)
        {
            while (currPos.y != room2Pos.y)
            {
                if (!IsRoom(currPos.x, currPos.y) && IsCoordValid(currPos.x, currPos.y))
                {
                    GeneratorChunk c = CreateChunk(currPos, groundPrefab, testColor, corridor);
                    if (c != null)
                    {
                        newCorridor.chunks.Add(c);
                    }
                }
                // Bug appen
                if (GetChunk(currPos.x, currPos.y) == null)
                {
                    Debug.LogError("Bug possible with Corridor");
                    return(null);
                }

                if (room2Pos.y > currPos.y)
                {
                    currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Up);
                }
                else if (room2Pos.y < currPos.y)
                {
                    currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Down);
                }
                else
                {
                    break;
                }
                //
            }

            if (!IsRoom(currPos.x, currPos.y) && IsCoordValid(currPos.x, currPos.y))
            {
                GeneratorChunk c = CreateChunk(currPos, groundPrefab, testColor, corridor);
                if (c != null)
                {
                    newCorridor.chunks.Add(c);
                }
            }
            //Bug appen
            if (GetChunk(currPos.x, currPos.y) == null)
            {
                Debug.LogError("Bug possible with Corridor");
                return(null);
            }

            if (room2Pos.x > currPos.x)
            {
                currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Right);
            }
            else if (room2Pos.x < currPos.x)
            {
                currPos = GetChunk(currPos.x, currPos.y).Location + GeneratorDirections.ToVector2i(GeneratorDirection.Left);
            }
            else
            {
                break;
            }
            //
        }

        if (corridor.transform.childCount < 1)
        {
            Destroy(corridor);
        }

        corridorList.Add(newCorridor);

        return(newCorridor);
    }
 public GeneratorChunk GetChunk(GeneratorChunk chunk, Direction direction)
 {
     return(GetChunkByIndex(chunk.ChunkIndex + direction.Offset()));
 }
コード例 #17
0
        public SoundFontPresets(IReadable input)
        {
            var id   = input.Read8BitChars(4);
            var size = input.ReadInt32LE();

            if (id.ToLower() != "list")
            {
                throw new Exception("Invalid soundfont. Could not find pdta LIST chunk.");
            }
            var readTo = input.Position + size;

            id = input.Read8BitChars(4);
            if (id.ToLower() != "pdta")
            {
                throw new Exception("Invalid soundfont. The LIST chunk is not of type pdta.");
            }

            Modulator[] presetModulators     = null;
            Generator[] presetGenerators     = null;
            Modulator[] instrumentModulators = null;
            Generator[] instrumentGenerators = null;

            ZoneChunk         pbag = null;
            ZoneChunk         ibag = null;
            PresetHeaderChunk phdr = null;
            InstrumentChunk   inst = null;

            while (input.Position < readTo)
            {
                id   = input.Read8BitChars(4);
                size = input.ReadInt32LE();
                switch (id.ToLower())
                {
                case "phdr":
                    phdr = new PresetHeaderChunk(id, size, input);
                    break;

                case "pbag":
                    pbag = new ZoneChunk(id, size, input);
                    break;

                case "pmod":
                    presetModulators = new ModulatorChunk(id, size, input).Modulators;
                    break;

                case "pgen":
                    presetGenerators = new GeneratorChunk(id, size, input).Generators;
                    break;

                case "inst":
                    inst = new InstrumentChunk(id, size, input);
                    break;

                case "ibag":
                    ibag = new ZoneChunk(id, size, input);
                    break;

                case "imod":
                    instrumentModulators = new ModulatorChunk(id, size, input).Modulators;
                    break;

                case "igen":
                    instrumentGenerators = new GeneratorChunk(id, size, input).Generators;
                    break;

                case "shdr":
                    SampleHeaders = new SampleHeaderChunk(id, size, input).SampleHeaders;
                    break;

                default:
                    throw new Exception("Invalid soundfont. Unrecognized sub chunk: " + id);
                }
            }
            var pZones = pbag.ToZones(presetModulators, presetGenerators);

            PresetHeaders = phdr.ToPresets(pZones);
            var iZones = ibag.ToZones(instrumentModulators, instrumentGenerators);

            Instruments = inst.ToInstruments(iZones);
        }
コード例 #18
0
ファイル: SoundFontPresets.cs プロジェクト: raynler/DoomUnity
        public SoundFontPresets(BinaryReader reader)
        {
            string id   = new string(IOHelper.Read8BitChars(reader, 4));
            int    size = reader.ReadInt32();

            if (!id.ToLower().Equals("list"))
            {
                throw new Exception("Invalid soundfont. Could not find pdta LIST chunk.");
            }
            long readTo = reader.BaseStream.Position + size;

            id = new string(IOHelper.Read8BitChars(reader, 4));
            if (!id.ToLower().Equals("pdta"))
            {
                throw new Exception("Invalid soundfont. The LIST chunk is not of type pdta.");
            }

            Modulator[] presetModulators     = null;
            Generator[] presetGenerators     = null;
            Modulator[] instrumentModulators = null;
            Generator[] instrumentGenerators = null;

            ZoneChunk         pbag = null;
            ZoneChunk         ibag = null;
            PresetHeaderChunk phdr = null;
            InstrumentChunk   inst = null;

            while (reader.BaseStream.Position < readTo)
            {
                id   = new string(IOHelper.Read8BitChars(reader, 4));
                size = reader.ReadInt32();

                switch (id.ToLower())
                {
                case "phdr":
                    phdr = new PresetHeaderChunk(id, size, reader);
                    break;

                case "pbag":
                    pbag = new ZoneChunk(id, size, reader);
                    break;

                case "pmod":
                    presetModulators = new ModulatorChunk(id, size, reader).Modulators;
                    break;

                case "pgen":
                    presetGenerators = new GeneratorChunk(id, size, reader).Generators;
                    break;

                case "inst":
                    inst = new InstrumentChunk(id, size, reader);
                    break;

                case "ibag":
                    ibag = new ZoneChunk(id, size, reader);
                    break;

                case "imod":
                    instrumentModulators = new ModulatorChunk(id, size, reader).Modulators;
                    break;

                case "igen":
                    instrumentGenerators = new GeneratorChunk(id, size, reader).Generators;
                    break;

                case "shdr":
                    sHeaders = new SampleHeaderChunk(id, size, reader).SampleHeaders;
                    break;

                default:
                    throw new Exception("Invalid soundfont. Unrecognized sub chunk: " + id);
                }
            }
            Zone[] pZones = pbag.ToZones(presetModulators, presetGenerators);
            pHeaders = phdr.ToPresets(pZones);
            Zone[] iZones = ibag.ToZones(instrumentModulators, instrumentGenerators);
            insts = inst.ToInstruments(iZones);
        }
 public GeneratorChunk GetBiomeChunk(GeneratorChunk chunk, Direction direction)
 {
     return(GetBiomeChunk(chunk, direction.Offset()));
 }