public void setPortTownData(PortTownReturnPacket portTownPacket)
    {
        numOfPortTowns = portTownPacket.getNumofPortTowns_actual();

        portTownCoords_minimap = new byte[numOfPortTowns, 2];
        portTownCoords_world   = new float[numOfPortTowns, 2];
        portTownYRotations     = new float[numOfPortTowns];
        portTownIcons          = new MinimapIcon[numOfPortTowns];

        PortTownIndividualPacket tempRoom;

        for (byte index = 0; index < numOfPortTowns; index++)
        {
            tempRoom = portTownPacket.getPortTownArray()[index];

            portTownCoords_minimap[index, 0] = tempRoom.getPortTownCoords_simple()[0];
            portTownCoords_minimap[index, 1] = tempRoom.getPortTownCoords_simple()[1];
            portTownCoords_world[index, 0]   = tempRoom.getPortTownCoords_upscaled()[0];
            portTownCoords_world[index, 1]   = tempRoom.getPortTownCoords_upscaled()[1];
            portTownYRotations[index]        = tempRoom.getPortTownYRotation() + 90f;

            portTownIcons[index] = new MinimapIcon(createNewIcon(portTownSprite, ParentTransform_tiles),
                                                   convertRoomCoordsToUICoords(tempRoom.getPortTownCoords_simple()[0], tempRoom.getPortTownCoords_simple()[1]),
                                                   false);
        }
    }
    private void placeAllPortTowns(PortTownReturnPacket portTownPacket)
    {
        GameObject tempBuilding;
        PortTownIndividualPacket portTownIndividual;
        int     numOfHouses;
        Color32 tempRoofColor;
        Color32 tempWallColor;

        // int brightnessOffset;

        for (byte index1 = 0; index1 < portTownPacket.getNumofPortTowns_actual(); index1++)
        {
            // Place the pier:
            tempBuilding = Instantiate(prefab_portTownPier, portTownPacket.getPortTownLocation_asVector3(index1), Quaternion.identity);
            tempBuilding.transform.eulerAngles = portTownPacket.getPortTownRotation_asVector3(index1);

            interactablesManager.addObjectToArray(tempBuilding, Constants.interactableID_portTownPier, 0);

            // Now place all the houses:
            portTownIndividual = portTownPacket.getPortTownArray()[index1];
            numOfHouses        = portTownIndividual.getHouseLocations().Length;

            for (byte index2 = 0; index2 < numOfHouses; index2++)
            {
                tempBuilding = Instantiate(prefab_portTownHouse, portTownIndividual.getHouseLocations()[index2], Quaternion.identity);
                tempBuilding.transform.eulerAngles = portTownIndividual.getHouseRotation_asVector3(index2);
                tempBuilding.transform.localScale  = portTownIndividual.getHouseScales()[index2];

                tempRoofColor = portTownIndividual.getHouseRoofColors()[index2];
                tempWallColor = portTownIndividual.getHouseWallColors()[index2];

                setHouseColors(tempRoofColor, tempWallColor, tempBuilding.GetComponent <MeshRenderer>().material);
            }
        }
    }
Exemple #3
0
        public static TerrainBuilderReturnPacket generateTerrain_DemoVer(float roomWidthHeight, int numOfVertsPerEdge)
        {
            // System.Random random_forThread = new System.Random();

            SimplifiedLayoutReturnPacket simplifiedLayout = SimplifiedLayoutTemplates.generateLayout_Demo();

            UpscaledLayoutReturnPacket upscaledLayout = UpscaledLayoutBuilder.upscaleLayout_Demo(simplifiedLayout, roomWidthHeight, numOfVertsPerEdge);

            // Mesh[,] returnMeshes = sliceHeightArrayIntoMultipleMeshes(upscaledLayout.getLandVertexHeights(), roomWidthHeight, numOfVertsPerEdge);
            TerrainMeshDataPacket[,] meshData = sliceHeightArrayIntoMultipleMeshes_2(upscaledLayout.getLandVertexHeights(), roomWidthHeight, numOfVertsPerEdge);

            PortTownReturnPacket portTownPacket = PortTownPlacementGenerator.generatePortTownInformation_DemoVer(simplifiedLayout, upscaledLayout, roomWidthHeight, numOfVertsPerEdge);

            // return new TerrainBuilderReturnPacket(simplifiedLayout, upscaledLayout, returnMeshes);
            return(new TerrainBuilderReturnPacket(simplifiedLayout, upscaledLayout, meshData, portTownPacket));
        }
Exemple #4
0
        public static TerrainBuilderReturnPacket generateTerrain(float roomWidthHeight, int numOfVertsPerEdge, byte sizeOfExplorableArea, byte numberOfKeys)
        {
            System.Random random_forThread = new System.Random();

            // SimplifiedLayoutReturnPacket simplifiedLayout = SimplifiedLayoutTemplates.generateLayout_DebugRoom();
            Debug.Log("Size of area: " + sizeOfExplorableArea);
            SimplifiedLayoutReturnPacket simplifiedLayout = SimplifiedLayoutBuilder.generateLayout_Normal(sizeOfExplorableArea, numberOfKeys, random_forThread);

            UpscaledLayoutReturnPacket upscaledLayout = UpscaledLayoutBuilder.upscaleLayout_Game(simplifiedLayout, roomWidthHeight, numOfVertsPerEdge, random_forThread);

            // Mesh[,] returnMeshes = sliceHeightArrayIntoMultipleMeshes(upscaledLayout.getLandVertexHeights(), roomWidthHeight, numOfVertsPerEdge);
            TerrainMeshDataPacket[,] meshData = sliceHeightArrayIntoMultipleMeshes_2(upscaledLayout.getLandVertexHeights(), roomWidthHeight, numOfVertsPerEdge);

            PortTownReturnPacket portTownPacket = PortTownPlacementGenerator.generatePortTownInformation(simplifiedLayout, upscaledLayout, roomWidthHeight, numOfVertsPerEdge, sizeOfExplorableArea, random_forThread);

            // return new TerrainBuilderReturnPacket(simplifiedLayout, upscaledLayout, returnMeshes);
            return(new TerrainBuilderReturnPacket(simplifiedLayout, upscaledLayout, meshData, portTownPacket));
        }
Exemple #5
0
        // public TerrainBuilderReturnPacket(SimplifiedLayoutReturnPacket simplePacket, UpscaledLayoutReturnPacket upscaledPacket, Mesh[,] terrainMeshes)
        public TerrainBuilderReturnPacket(SimplifiedLayoutReturnPacket simplePacket, UpscaledLayoutReturnPacket upscaledPacket, TerrainMeshDataPacket[,] meshData, PortTownReturnPacket portTownPacket)
        {
            // this.terrainMeshes = terrainMeshes;
            boolArray           = upscaledPacket.getBoolArray();
            boolArray_noNoise   = upscaledPacket.getBoolArray_noNoise();
            this.meshData       = meshData;
            this.simplePacket   = simplePacket;
            this.portTownPacket = portTownPacket;

            numOfKeys = 0;
            for (int index = 0; index < 6; index++)
            {
                if (simplePacket.getHasKey()[index])
                {
                    numOfKeys++;
                }
            }
        }
Exemple #6
0
    // private EnemyObject_Abstract burningEnemy;
    // private Vector3 burningLocation;
    // private bool anEnemyIsBurning = false;
    // private byte burnTimer_current = 0;
    // private const byte burnTimer_max = 6;
    // private const byte burnDamage = 3;



    public void placeStartingEnemies(Vector3 boatPos, bool[,] boolArray, DoorHitboxManager doorHitboxManager, byte areaWidth, byte areaHeight, PortTownReturnPacket portTownPacket, float frequencyOfEnemies)
    {
        this.boolArray         = boolArray;
        this.doorHitboxManager = doorHitboxManager;
        this.areaWidth         = areaWidth;
        this.areaHeight        = areaHeight;
        spawnRateMultiplier    = 100f / (areaWidth * areaHeight - 7);

        setSpawnFrequency(frequencyOfEnemies);


        numOfPortTowns    = portTownPacket.getNumofPortTowns_actual();
        portTownLocations = new Vector3[numOfPortTowns];

        for (byte index = 0; index < numOfPortTowns; index++)
        {
            portTownLocations[index] = portTownPacket.getPortTownLocation_asVector3(index);
        }


        if (shouldSpawnEnemies)
        {
            int numOfStartingEnemies = (int)(10 / spawnRateMultiplier);

            for (int index = 0; index < 3; index++)
            {
                attemptToSpawnRandomEnemy_2(boatPos);
            }
        }
    }
    // ------------------------------------------------------------------------------------------------------
    // ----------- 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]);
    }