Exemplo n.º 1
0
    void Update()
    {
        Debug.Log($"Ballring: {ballRing}, current Ring: {ring}");
        BiomData biomdata = Bioms.instance.GetCurrentBiomData();

        if (!prerendering)
        {
            // new ring
            Vector2 ballPos   = new Vector2(ballTransform.position.x, ballTransform.position.z);
            Vector2 centerPos = new Vector2(center.position.x, center.position.z);

            float   pillarsRingStep  = biomdata.RingStep;
            Vector2 pillarsFloorSize = biomdata.PillarsFloorSizeRange;

            renderRadius = renderRings * pillarsRingStep;

            if (Vector2.Distance(ballPos, centerPos) >= ballDistance + oldPillarsRingStep)
            {
                if (ballRing % Bioms.instance.GetRingsToNextBioms() == 0)
                {
                    oldPillarsRingStep = pillarsRingStep;
                }
                ballDistance += oldPillarsRingStep;
                ballRing     += 1;
            }
            if (Vector2.Distance(ballPos, centerPos) + renderRadius >= pillarsRingStep + fixedR)
            {
                ring += 1;
                GenerateRing(ring);
            }
        }
    }
Exemplo n.º 2
0
    public void generateModel()
    {
        for (int i = 0; i < chunkSize; i++)
        {
            for (int j = 0; j < chunkSize; j++)
            {
                BiomData biomData = World.instance.biomsData[chunkBiomes[i, j]];

                //Generate the ground
                GameObject g = Instantiate(World.instance.biomModels[(int)biomData.biomModel]);
                g.transform.position = transform.position + Hexagon.getWorldPosition(i, j);
                g.transform.parent   = transform;
                hexagons[i, j]       = g;

                //Generate the structure
                if ((int)biomData.structure != (int)Structures.None)
                {
                    structures[i, j] = Instantiate(World.instance.structureModels[(int)biomData.structure]);
                    structures[i, j].transform.position = transform.position + Hexagon.getWorldPosition(i, j);
                    structures[i, j].transform.parent   = transform;
                }
                else
                {
                    structures[i, j] = null;
                }
            }
        }
    }
Exemplo n.º 3
0
    private void GenerateRing(int ring)
    {
        // Bioms
        if (biomsON)
        {
            Bioms.instance.CheckNewBiom(ballRing);
        }

        BiomData generationData = Bioms.instance.GetCurrentBiomData();
        // pillars param init zone
        float   pillarsRingStep   = generationData.RingStep;
        float   pillarsFrequency  = generationData.PillarsFrequency;
        Vector2 pillarsBodyHeight = generationData.PillarsBodyHeightRange;
        Vector2 pillarsFloorSize  = generationData.PillarsFloorSizeRange;
        Color   pillarsFloorColor = generationData.PillarsFloorColor;
        Color   pillarsBodyColor  = generationData.PillarsBodyColor;
        // trampoline param init zone
        float   trampolineSpawnChance = generationData.TrampolineSpawnChance;
        Vector2 trampolineBodyHeight  = generationData.TrampolineBodyHeightRange;
        Vector2 trampolineFloorSize   = generationData.TrampolineFloorSizeRange;

        float rPrev = fixedR + 10.0f;

        fixedR += pillarsRingStep;
        float r = fixedR;

        int numberOfPillars = 0;

        if (ring == 1)
        {
            numberOfPillars = Mathf.RoundToInt(pillarsFrequency);
        }
        else
        {
            numberOfPillars = Mathf.RoundToInt(pillarsFrequency * r / pillarsRingStep);
        }
        float angleStep = 360.0f / numberOfPillars;

        Vector2 ballPos   = new Vector2(ballTransform.position.x, ballTransform.position.z);
        Vector2 centerPos = new Vector2(center.position.x, center.position.z);

        float ballMoveAngle = Mathf.Atan2(ballPos.y - centerPos.y, ballPos.x - centerPos.x) * (180.0f / Mathf.PI);

        if (ballMoveAngle < 0.0f)
        {
            ballMoveAngle += 360.0f;
        }

        // Cut FOV
        if (ring > 5 && cutFOV)
        {
            renderFOV /= (1.0f + 1.0f / (ring * pillarsRingStep * 0.05f));
        }
        float thetaMin = ballMoveAngle - renderFOV / 2;
        float thetaMax = thetaMin + renderFOV;

        // full circle thetaMin = 0; thetaMax = 360.0f
        for (float theta = thetaMin; theta < thetaMax; theta += angleStep)
        {
            float rDist = Random.Range(rPrev, r); //Mathf.Sqrt(Random.value)
            float x     = center.position.x + rDist * Mathf.Cos(theta * (Mathf.PI / 180.0f));
            float z     = center.position.z + rDist * Mathf.Sin(theta * (Mathf.PI / 180.0f));


            Vector2    bodyHeight;
            Vector2    floorSize;
            GameObject obj;

            // Default pillar
            if (Random.value > trampolineSpawnChance)
            {
                bodyHeight = pillarsBodyHeight;
                floorSize  = pillarsFloorSize;
                obj        = pillarObj;
            }
            // Trampoline pillar
            else
            {
                bodyHeight = trampolineBodyHeight;
                floorSize  = trampolineFloorSize;
                obj        = trampolineObj;
            }
            float h = Random.Range(bodyHeight.x, bodyHeight.y);
            float s = Random.Range(floorSize.x, floorSize.y);

            Color[] color = { pillarsFloorColor, pillarsBodyColor };
            CreatePillar(x, z, s, h, color, obj, !prerendering, ring);
        }
    }
Exemplo n.º 4
0
    private GameObject CreatePillar(float x, float z, float s, float h, Color[] ringColor, GameObject obj, bool isAnimate, int ring)
    {
        Vector3 position   = new Vector3(x, transform.position.y, z);
        Color   floorColor = ringColor[0];
        Color   bodyColor  = ringColor[1];

        BiomData biomData = Bioms.instance.GetCurrentBiomData();

        GameObject pillar = Instantiate(obj, position, Quaternion.identity);

        pillar.GetComponent <Pillar>().SetRing(ring);

        // Animations
        if (isAnimate)
        {
            pillar.GetComponent <Animator>().SetTrigger("Appear");
        }

        // Coloring
        Transform pillarModel = pillar.transform.GetChild(0);

        if (obj.tag == "Bounce")
        {
            pillarModel.GetChild(0).GetComponent <Renderer>().material.color = floorColor;
            pillarModel.GetChild(1).GetComponent <Renderer>().material.color = bodyColor;
        }
        pillarModel.localScale = new Vector3(s, h, s);

        // Puddle
        if (Random.value <= biomData.PuddleSpawnChance && obj.tag == "Bounce")
        {
            Puddle puddle = pillarModel.GetChild(0).gameObject.AddComponent(typeof(Puddle)) as Puddle;

            // Text
            Vector3 textSpawnPosition = pillarModel.GetChild(0).position;
            textSpawnPosition = new Vector3(textSpawnPosition.x, textSpawnPosition.y + 0.1f, textSpawnPosition.z);
            GameObject textPuddle = Instantiate(pillarTextObj, textSpawnPosition, Quaternion.identity);
            textPuddle.transform.parent = pillarModel.GetChild(0);

            if (Random.value <= biomData.PuddleBoostChance)
            {
                // Text
                textPuddle.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = (int)(biomData.PuddleBoostPower * 100) + "%";

                puddle.SetPuddleType(Puddle.PuddleTypes.BOOST);
            }
            else
            {
                // Text
                textPuddle.GetComponentInChildren <TMPro.TextMeshProUGUI>().text = (int)(biomData.PuddleSlowPower * 100) + "%";

                puddle.SetPuddleType(Puddle.PuddleTypes.SLOW);
            }
        }

        // Diamonds
        if (Random.value <= biomData.DiamondsSpawnChance && obj.tag == "Bounce")
        {
            GameObject diamond = Diamond.SpawnDiamond(
                biomData.DiamondsVariety,
                Bioms.instance.GetDiamondsPrefabs(),
                Bioms.instance.GetDiamondsProbabilities(),
                pillarModel.GetChild(0));
            diamond.transform.parent = pillarModel;
        }

        return(pillar);
    }
Exemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        World world = (World)target;

        //Edit the worldsize
        Vector2 worldSize = EditorGUILayout.Vector2Field("WorldSize: ", new Vector2(world.width, world.height));

        world.width  = (int)worldSize.x;
        world.height = (int)worldSize.y;

        //BiomModels
        getObjectsForArray("BiomModels: ", ref showBiomModels, ref world.biomModels, typeof(BiomModels));

        //HexagonBorders
        getObjectsForArray("HexagonBorders: ", ref showHexagonBorders, ref world.hexagonBorderModels, typeof(HexagonBorders));

        //StructureModels
        getObjectsForArray("StructureModels: ", ref showStructureModels, ref world.structureModels, typeof(Structures));

        //BuildingModels
        getObjectsForArray("BuildingModels: ", ref showBuildingModels, ref world.buildingModels, typeof(Buildings));

        //Ressources
        getSpritesForArray("RessourceSprites: ", ref showRessourceSprites, ref world.ressourceSprites, typeof(Ressources));
        getObjectsForArray("RessourceTexts: ", ref showRessourceColors, ref world.ressourceTexts, typeof(Ressources));

        //Bioms
        showBioms = EditorGUILayout.Toggle("Bioms: ", showBioms);
        if (showBioms)
        {
            //Change the size of the array
            BiomData[] arrayNew = new BiomData[EditorGUILayout.DelayedIntField("     Size:", world.biomsData.Length)];
            if (arrayNew.Length != world.biomsData.Length && arrayNew.Length > 0)
            {
                //Copy the values of array
                if (arrayNew.Length > world.biomsData.Length)
                {
                    for (int i = 0; i < world.biomsData.Length; i++)
                    {
                        arrayNew[i] = world.biomsData[i];
                    }
                }
                else
                {
                    for (int i = 0; i < arrayNew.Length; i++)
                    {
                        arrayNew[i] = world.biomsData[i];
                    }
                }

                world.biomsData = arrayNew;
            }

            for (int i = 0; i < world.biomsData.Length; i++)
            {
                EditorGUILayout.LabelField("     " + System.Enum.GetName(typeof(Bioms), i));
                world.biomsData[i].biomModel = (BiomModels)EditorGUILayout.EnumPopup("          BiomModel:", world.biomsData[i].biomModel);
                world.biomsData[i].structure = (Structures)EditorGUILayout.EnumPopup("          Structure:", world.biomsData[i].structure);
                EditorGUILayout.LabelField("");
            }
        }

        //Time
        world.timeText = (Text)EditorGUILayout.ObjectField("Time Text: ", world.timeText, typeof(Text));
    }