Esempio n. 1
0
    private void generateSurroundingTerrain()
    {
        TerrainBuilderReturnPacket terrainPacket = TerrainBuilder.generateTerrain_titleVer(Constants.roomWidthHeight, Constants.numOfVertsPerEdge);

        Mesh[,] terrainMeshes = terrainPacket.getTerrainMeshes();
        // Mesh[,] terrainMeshes = TerrainBuilder.sliceHeightArrayIntoMultipleMeshes(terrainPacket.getHeightArray(), Constants.roomWidthHeight, Constants.numOfVertsPerEdge);

        int numOfRooms_horizontal = terrainMeshes.GetLength(0);
        int numOfRooms_vertical   = terrainMeshes.GetLength(1);


        Color32[] terrainColors = persistentData.getTerrainColors();

        Texture2D terrainTexture = new Texture2D(4, 1);

        terrainTexture.wrapMode   = TextureWrapMode.Clamp;
        terrainTexture.filterMode = FilterMode.Point;

        terrainMaterial.mainTexture = terrainTexture;

        terrainTexture.SetPixel(0, 0, terrainColors[0]);
        terrainTexture.SetPixel(1, 0, terrainColors[1]);
        terrainTexture.SetPixel(2, 0, terrainColors[2]);
        terrainTexture.SetPixel(3, 0, terrainColors[3]);
        terrainTexture.Apply();

        waterPlane.GetComponent <Renderer>().material.SetColor("_Color", new Color32(terrainColors[0].r, terrainColors[0].g, terrainColors[0].b, 64));

        byte  fogInc   = 153;
        float fogScale = 0.4f;

        RenderSettings.fogColor = new Color32((byte)(terrainColors[2].r * fogScale + fogInc), (byte)(terrainColors[2].g * fogScale + fogInc), (byte)(terrainColors[2].b * fogScale + fogInc), 255);

        // Instantiate the 3D terrain meshes:
        GameObject newTerrainParent = new GameObject("Empty");

        for (int indexX = 0; indexX < numOfRooms_horizontal; indexX++)
        {
            for (int indexY = 0; indexY < numOfRooms_vertical; indexY++)
            {
                GameObject newTerrain = new GameObject("Empty");
                newTerrain.AddComponent <MeshFilter>();
                newTerrain.AddComponent <MeshRenderer>();
                newTerrain.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                newTerrain.GetComponent <MeshFilter>().mesh   = terrainMeshes[indexX, indexY];
                newTerrain.GetComponent <Renderer>().material = terrainMaterial;

                newTerrain.GetComponent <Transform>().position = new Vector3(((indexX * Constants.roomWidthHeight) - 1.5f * Constants.roomWidthHeight), 0,
                                                                             ((-indexY * Constants.roomWidthHeight) + 3.5f * Constants.roomWidthHeight));
                newTerrain.GetComponent <Transform>().parent = newTerrainParent.GetComponent <Transform>();
            }
        }

        newTerrainParent.GetComponent <Transform>().localScale  = new Vector3(100f, 100f, 100f);
        newTerrainParent.GetComponent <Transform>().eulerAngles = new Vector3(2.3f, 0f, 0f);
        newTerrainParent.GetComponent <Transform>().position    = new Vector3(0f, -223f, 0f);
    }
Esempio n. 2
0
    // ------------------------------------------------------------------------------------------------------
    // ----------- Terrain generation and initialization stuff: --------------------------------------------------------
    // ------------------------------------------------------------------------------------------------------

    private void generateTerrain()
    {
        // TerrainBuilderReturnPacket terrainPacket = TerrainBuilder.generateTerrain(Constants.roomWidthHeight, Constants.numOfVertsPerEdge);
        TerrainBuilderReturnPacket terrainPacket = persistentData.getTerrainPacket();

        Mesh[,] terrainMeshes = terrainPacket.getTerrainMeshes();
        // Mesh[,] terrainMeshes = TerrainBuilder.sliceHeightArrayIntoMultipleMeshes(terrainPacket.getHeightArray(), Constants.roomWidthHeight, Constants.numOfVertsPerEdge);

        boolArray = terrainPacket.getBoolArray();
        persistentData.setAreaTotal(terrainPacket.getNumOfRooms());
        persistentData.setKeysTotal(terrainPacket.getNumOfKeys());
        persistentData.setDoorsTotal(terrainPacket.getNumOfLockedDoors());

        numOfRooms_horizontal = (byte)terrainMeshes.GetLength(0);
        numOfRooms_vertical   = (byte)terrainMeshes.GetLength(1);

        waterManager.setWaterSize(numOfRooms_horizontal, numOfRooms_vertical, Constants.roomWidthHeight);

        // color the pixels in the terrainMaterial?
        // Color32[] terrainColors = TerrainColorGenerator.GenerateTerrainColors();
        Color32[] terrainColors = persistentData.getTerrainColors();

        Texture2D terrainTexture = new Texture2D(4, 1);

        terrainTexture.wrapMode   = TextureWrapMode.Clamp;
        terrainTexture.filterMode = FilterMode.Point;

        terrainMaterial.mainTexture = terrainTexture;

        //terrainTexture.SetPixel(0, 0, terrainColors[3]);
        terrainTexture.SetPixel(0, 0, terrainColors[0]);
        terrainTexture.SetPixel(1, 0, terrainColors[1]);
        terrainTexture.SetPixel(2, 0, terrainColors[2]);
        terrainTexture.SetPixel(3, 0, terrainColors[3]);
        terrainTexture.Apply();

        //waterManager.setWaterTint(terrainColors[3]);
        waterManager.setWaterTint(terrainColors[0]);

        Debug.Log("Water color is: " + (terrainColors[0]));

        persistentData.setTerrainColors(terrainColors);

        // Instantiate the 3D terrain meshes:
        GameObject newTerrainParent = new GameObject("terrainParent");

        MeshFilter   terrainMeshFilter;
        MeshRenderer terrainMeshRenderer;

        for (int indexX = 0; indexX < numOfRooms_horizontal; indexX++)
        {
            for (int indexY = 0; indexY < numOfRooms_vertical; indexY++)
            {
                GameObject newTerrain = new GameObject("terrainPiece");

                terrainMeshFilter      = newTerrain.AddComponent <MeshFilter>();
                terrainMeshFilter.mesh = terrainMeshes[indexX, indexY];

                terrainMeshRenderer = newTerrain.AddComponent <MeshRenderer>();
                terrainMeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                terrainMeshRenderer.material          = terrainMaterial;

                newTerrain.transform.position = new Vector3(((indexX * Constants.roomWidthHeight) - 2f * Constants.roomWidthHeight), -0.5f,
                                                            ((-indexY * Constants.roomWidthHeight) + 2f * Constants.roomWidthHeight));
                newTerrain.transform.parent = newTerrainParent.transform;
            }
        }

        // Move the player's boat to the starting location:
        playerBoatTransform_target.position = new Vector3((((float)terrainPacket.getPlayerStartingLocation()[0]) + 0.5f) * Constants.roomWidthHeight,
                                                          0f, (((float)terrainPacket.getPlayerStartingLocation()[1]) + 0.5f) * -Constants.roomWidthHeight);
        playerBoatTransform_delayed.position = playerBoatTransform_target.position;
        // And bookmark the first 'port town' where the player spawns:
        // bookmarkNewPortTownLocation(playerBoatTransform_target.position.x, playerBoatTransform_target.position.z);


        // Instantiate the interactables:
        doorHitboxManager = new DoorHitboxManager(terrainPacket.getDoorLocations(), terrainPacket.getDoorSides(), terrainPacket.getDoorColors());

        // first instantiate the final treasure:
        interactablesManager.addObjectToArray(instantiateItem_initial(terrainPacket.getFinalTreasureLocation()[0], terrainPacket.getFinalTreasureLocation()[1], Constants.interactableID_treasureFinal),
                                              Constants.interactableID_treasureFinal,
                                              0);

        // Then instantiate all the keys:
        byte[,] itemLocations = terrainPacket.getKeyLocations();
        bool[] hasKey  = terrainPacket.getHasKey();
        byte[] itemIDs = { Constants.interactableID_key1, Constants.interactableID_key2, Constants.interactableID_key3, Constants.interactableID_key4, Constants.interactableID_key5, Constants.interactableID_key6 };
        for (short index = 0; index < 6; index++)
        {
            if (hasKey[index])
            {
                interactablesManager.addObjectToArray(instantiateItem_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index]),
                                                      itemIDs[index],
                                                      index);
            }
        }

        // then instantiate all the door prefabs:
        itemLocations = terrainPacket.getDoorLocations();
        itemIDs       = terrainPacket.getDoorColors();
        byte[] doorSide = terrainPacket.getDoorSides();

        for (short index = 0; index < itemIDs.Length; index++)
        {
            interactablesManager.addObjectToArray(instantiateDoor_initial(itemLocations[index, 0], itemLocations[index, 1], itemIDs[index], doorSide[index]),
                                                  itemIDs[index],
                                                  index);
        }

        // Now instantiate the minimap:
        minimapManager.initializeMinimapData(terrainPacket.getSimplePacket(), terrainPacket.getBoolArray_noNoise(), persistentData);

        // Now instantiate all the port towns:
        PortTownReturnPacket portTownPacket = terrainPacket.getPortTownPacket();

        placeAllPortTowns(portTownPacket);
        minimapManager.setPortTownData(portTownPacket);


        // Instantiate the enemy manager:
        enemyManager.placeStartingEnemies(playerBoatTransform_target.position, boolArray, doorHitboxManager,
                                          (byte)(numOfRooms_horizontal - 3), (byte)(numOfRooms_vertical - 3),
                                          portTownPacket, persistentData.getDensityOfEnemies_value());


        // Cannonball related stuff:
        touchManager.setArrowAndWheelColors(terrainColors[0]);
        cannonballManager.initializeCannonballData(boolArray, doorHitboxManager, persistentData.getDensityOfEnemies_value(), persistentData.getShipColors()[5]);
    }