Exemplo n.º 1
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);
            }
        }
    }
Exemplo n.º 2
0
    public void manageTouches_canMove(bool[,] boolArray, DoorHitboxManager doorHitboxManager)
    {
        if (touchReader_keyboard.getHasMouseOrKeyInput())
        {
            touchReturnPacket = touchReader_keyboard.getThumbstickData(normalStickPositions, shootingMode);
        }
        else
        {
            touchReturnPacket = touchReader.getThumbstickData();
        }

        uiManager.setThumbsticks(touchReturnPacket);

        stickAngles_raw     = touchReturnPacket.getStickAngles();
        stickMagnitudes_raw = uiManager.getRealStickMagnitude();
        hasTouches_raw      = touchReturnPacket.getHasTouch();

        setStickData();
        // checkForDoubleTap_movement();

        moveShip_target(stickAngle_movement, stickMagnitude_movement, boolArray, doorHitboxManager);

        checkCannonStick();
        cannonFiringManager.checkCannonReload(playerBoatTransform_delayed.position);

        hasTouchPrevious_movement = hasTouch_movement;
        // hasTouchPrevious_cannon = hasTouch_cannon;
    }
Exemplo n.º 3
0
    private void moveShip_target(float angle, float magnitude, bool[,] boolArray, DoorHitboxManager doorHitboxManager)
    {
        // if (autodrive)
        // {
        //     if (magnitude >= 0.5f)
        //     {
        //         autodriveForward_target = convertAngMagToVector3_updateExisting(angle + Mathf.PI/4f, Mathf.Min(1f, magnitude*1.25f), autodriveForward_target);
        //         // autodriveForward_target = convertAngMagToVector3(angle + Mathf.PI/4f, Mathf.Min(1f, magnitude*1.25f));
        //         updateAutodriveForward();
        //     }



        //     Constants.moveGameObject_andChangeForward(playerBoatTransform_target,
        //                                                 autodriveForward_current * Constants.shipMoveSpeed,
        //                                                 boolArray,
        //                                                 doorHitboxManager);
        // } else {
        Constants.moveGameObject_andChangeForward(playerBoatTransform_target,
                                                  // convertAngMagToVector3(angle + Mathf.PI/4f, Mathf.Min(1f, magnitude*1.25f)) * Constants.shipMoveSpeed,
                                                  worldspaceVector_movement * Constants.shipMoveSpeed,
                                                  boolArray,
                                                  doorHitboxManager);
        // }
    }
Exemplo n.º 4
0
        public static bool checkForConflict_V2(bool[,] boolArray, DoorHitboxManager doorHitboxManager, Vector2 posToCheck)
        {
            if (doorHitboxManager.checkIfPosIsInDoor(posToCheck))
            {
                return(false);
            }

            return(checkForConflict_V2_noDoors(boolArray, posToCheck));
        }
Exemplo n.º 5
0
    public void initializeCannonballData(bool[,] boolArray, DoorHitboxManager doorHitboxManager, float frequencyOfEnemies, Color32 color_cannonballPlayer)
    {
        this.boolArray              = boolArray;
        this.doorHitboxManager      = doorHitboxManager;
        this.color_cannonballPlayer = color_cannonballPlayer;

        // numOfCannonballs_player = 2;
        numOfCannonballs_player = cannonData.getStaringNumOfCannonballs();
        if (frequencyOfEnemies <= 1)
        {
            numOfCannonballs_enemy = 25;
        }
        else
        {
            numOfCannonballs_enemy = (byte)(15 + Mathf.Round(10 * frequencyOfEnemies)); //this number should never be larger than 127...
            Debug.Log("NumOfCannonballs... " + numOfCannonballs_enemy);
        }

        wakeController.initializeData(numOfCannonballs_enemy);

        cannonballArray_player  = new CannonballIndividual[numOfCannonballs_player];
        cannonballArray_enemies = new CannonballIndividual[numOfCannonballs_enemy];

        GameObject playerCannonballPrefab = getPlayerCannonballPrefab();
        GameObject tempCannonballObject;

        for (byte index = 0; index < numOfCannonballs_player; index++)
        {
            tempCannonballObject          = Instantiate(playerCannonballPrefab, Vector3.zero, Quaternion.identity);
            cannonballArray_player[index] = tempCannonballObject.GetComponent <CannonballIndividual>();

            tempCannonballObject.GetComponent <SpriteRenderer>().color = color_cannonballPlayer;
            tempCannonballObject.transform.localScale = Vector3.one * cannonData.getCannonballSize();
        }

        for (byte index = 0; index < numOfCannonballs_enemy; index++)
        {
            tempCannonballObject           = Instantiate(prefab_cannonball_enemy, Vector3.zero, Quaternion.identity);
            cannonballArray_enemies[index] = tempCannonballObject.GetComponent <CannonballIndividual>();
        }


        if (!cannonData.getExplodes())
        {
            cannonBonkManager.initializeCannnonbonkArray((byte)(numOfCannonballs_player + numOfCannonballs_enemy / 2), color_cannonballPlayer, color_cannonballEnemy);
        }
        else
        {
            cannonBonkManager.initializeCannnonbonkArray((byte)(numOfCannonballs_player * 8 + numOfCannonballs_enemy / 2), color_cannonballPlayer, color_cannonballEnemy);
        }
    }
Exemplo n.º 6
0
        private static Vector3 calculateReflectionVector(bool[,] boolArray, DoorHitboxManager doorHitboxManager, Vector3 collisionPoint)
        {
            Vector2 collision_butV2 = new Vector2(collisionPoint.x, collisionPoint.z);
            Vector2 tempVector      = new Vector2(0.0000001f, 0f);

            // This will call 'checkForConflict' on a bunch of points in a circle around the collisionPoint.
            //   (these vectors shouldn't require the use of calculation, except maybe to multiply by the boat's move speed...)
            // If any of these points are in the water (ie, it returns true), then add that vector to a running total.
            for (int index = 0; index < Constants.walls_hittestVectors.Length; index++)
            {
                if (checkForConflict_V2(boolArray, doorHitboxManager, collision_butV2 + Constants.walls_hittestVectors[index] * Constants.wallHittestRadius))
                {
                    tempVector += Constants.walls_hittestVectors[index] * Constants.wallHittestRadius;
                }
            }

            // After all the checks are done, normalize the vector and return it.
            tempVector = tempVector.normalized;
            return(new Vector3(tempVector.x, 0, tempVector.y));
        }
Exemplo n.º 7
0
 private bool checkIfPositionIsInWater(Vector3 position, bool[,] boolArray, DoorHitboxManager doorHitboxManager)
 {
     return(BoolArrayManager.checkForConflict_V3(boolArray, doorHitboxManager, position));
 }
Exemplo n.º 8
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]);
    }
Exemplo n.º 9
0
 public static void moveGameObject_sameForward(Transform objectTransform, Vector3 moveVec, bool[,] boolArray, DoorHitboxManager doorHitboxManager)
 {
     objectTransform.position += BoolArrayManager.adjustMovementBasedOnWalls(boolArray, objectTransform.position, moveVec, doorHitboxManager);
 }
Exemplo n.º 10
0
 public static void moveGameObject_andChangeForward(Transform objectTransform, Vector3 moveVec, bool[,] boolArray, DoorHitboxManager doorHitboxManager)
 {
     if (moveVec.magnitude > 0.05f)
     {
         objectTransform.forward   = moveVec.normalized;
         objectTransform.position += BoolArrayManager.adjustMovementBasedOnWalls(boolArray, objectTransform.position, moveVec, doorHitboxManager);
     }
 }
Exemplo n.º 11
0
 public static bool checkForConflict_V3(bool[,] boolArray, DoorHitboxManager doorHitboxManager, Vector3 posToCheck)
 {
     return(checkForConflict_V2(boolArray, doorHitboxManager, new Vector2(posToCheck.x, posToCheck.z)));
 }
Exemplo n.º 12
0
        public static Vector3 adjustMovementBasedOnWalls(bool[,] boolArray, Vector3 boatPos, Vector3 movementVec, DoorHitboxManager doorHitboxManager)
        {
            // Use lerping to find if the boat's next position would be inside the land (and later, if it'd be inside a door)
            // If no conflict, return movementVec as is?

            if (checkForConflict_V3(boolArray, doorHitboxManager, boatPos + movementVec))
            {
                return(movementVec);
            }

            // If there is a conflict... keep track of which box it is that we landed on.
            // Check the 5x5 box around this point. For any non-conflicts, add the constants' vector to
            // a running total. Then, normalize this vector.

            Vector3 reflectionVector = calculateReflectionVector(boolArray, doorHitboxManager, boatPos + movementVec);

            // Now, nudge the boat in the direction of the reflection vector until it lands in the water:

            Vector3 newMoveVec = new Vector3(movementVec.x, 0, movementVec.z);

            int breaker = 180;

            do
            {
                newMoveVec += reflectionVector * Constants.wallRepelSpeed;
                if (newMoveVec.magnitude > Constants.shipMoveSpeed)
                {
                    newMoveVec = newMoveVec.normalized * Constants.shipMoveSpeed;
                }

                if (breaker-- <= 0)
                {
                    return(new Vector3(0f, 0f, 0f));
                }
            } while (!checkForConflict_V3(boolArray, doorHitboxManager, boatPos + newMoveVec));

            // I'll need a function like... 'checkForConflict', which will check the position against the boolArray and the doors,
            // and return true/false if it can move there or not.

            // I'll likely need a proper Lerp-like function to find a smooth line between each discrete vertex... and then decide
            // whether or not a point is on the 'safe' side of that line.

            // I'll need a function like... 'calculateReflectionVector', which 'checkForConflict's every box within a 5x5 square.
            // (I should be able to assume the player will never be within 3 of the walls...)
            // For every conflict it finds, it will use the Constants' vector array to produce and return a new 'normal' vector.

            // I... should be able to handle the rest in here?

            return(newMoveVec);

            // I image each door could have four integers... two for 'startXY' and two for 'endXY'.
            // If the checked position lies within these integers, it will be considered a conflict...
            // And when a door opens... either this object is removed from the list, or the four verts
            // get set to 0?
            // Perhaps a door has two lists... one that controls the 3D model, and one that controls the
            // blocking area.
            // WHen a key is collected, every 'hitbox' for that door is immediately removed from that list.
            // When the door is approached, the model is 'opened' and that controller is removed from the list...
            // This sounds good?
            // In this case, the 3D model one would be considered a collectable, so would be stored in the same
            // list as the keys... and when collected, the model will play the 'open' animation instead of being
            // destroyed along with the in-memory version...

            // The collectables should be handleable with the distance between the real XYZ vectors...
            // Like how I intend to handle the auto targeting as well, using the enemies...
            // This could also be done every 1/10 of a second or so, to reduce overhead?
        }