Exemple #1
0
    void CheckAngleToTarget()
    {
        if (Input.GetMouseButtonUp(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            float      angleBetweenUnits = 0f;
            if (Physics.Raycast(ray, out hit))
            {
                angleBetweenUnits = Vector3.Angle(hit.transform.position - this.transform.position, transform.forward);
            }
            int degree = Mathf.RoundToInt(angleBetweenUnits);
            if (degree < unitMaxFovAngle)
            {
                Debug.Log($"{degree} - possible");
                CheckDistanceToTarget(hit);
            }
            else
            {
                Debug.Log($"{degree} - not possible");
            }
        }

        void CheckDistanceToTarget(RaycastHit hit)
        {
            Vector3   unitPosition   = this.transform.position;
            Vector3   targetPosition = hit.transform.position;
            Transform target         = hit.transform;

            attackingUnit = tgs.CellGetIndex(tgs.CellGetAtPosition(unitPosition, true));
            defendingUnit = tgs.CellGetIndex(tgs.CellGetAtPosition(targetPosition, true));

            int distanceToTarget = tgs.CellGetHexagonDistance(attackingUnit, defendingUnit);

            if (distanceToTarget <= maxRange)
            {
                RangedAttack(target);
            }
            else
            {
                Debug.Log("Target too far away");
            }
        }

        void RangedAttack(Transform target)
        {
            Debug.Log("Attacking---");
            target.GetComponent <UnitHealth>().Damage();
        }
    }
 void OnMouseUp()
 {
     Vector3 unitPosition = transform.position;
     Cell    cell         = tgs.CellGetAtPosition(unitPosition, true);
     int     row          = cell.row;
     int     column       = cell.column;
 }
Exemple #3
0
    public void PositionUnitInCenterOfCell()
    {
        Cell   cell      = tgs.CellGetAtPosition(transform.position, true);
        int    cellIndex = tgs.CellGetIndex(cell);
        Bounds bounds    = tgs.CellGetRectWorldSpace(cellIndex);

        transform.position = bounds.center;
    }
 private void MarkAllGameObjects()
 {
     GameObject[] gameobjects;
     gameobjects = GameObject.FindGameObjectsWithTag("Enemy");
     foreach (GameObject g in gameobjects)
     {
         Cell cell      = tgs.CellGetAtPosition(g.transform.position, true);
         int  cellIndex = tgs.CellGetIndex(cell);
         tgs.CellSetCrossCost(cellIndex, 12000);
     }
 }
Exemple #5
0
    void Start()
    {
        // playAud = GetComponent<playSequence>();
        //grabs Audio
        treeSounds = gameObject.AddComponent <AudioSource>();
        //TerrainGridSystem ref
        tgs            = TerrainGridSystem.instance;
        randomRotation = 60 * Random.Range(0, 6);
        // Clone Sapling prefabs and Instantiate
        groundTile = tgs.CellGetAtPosition(transform.position, true);
        //transform.SetParent ();
        cellIndex = tgs.CellGetIndex(groundTile);
        neighbors = tgs.CellGetNeighbours(groundTile);
        tgs.CellSetCanCross(cellIndex, false);
        //fills up neighborIndexes with the proper cell indexes
        for (int i = 0; i < neighbors.Count; i++)
        {
            int index = tgs.CellGetIndex(neighbors[i]);
            neighborIndexes.Add(index);
            neighbourPos[i] = tgs.CellGetPosition(index);
            //this gives you neighbor cell position
            //can be used to see which cell you’re being given
            //raycast to this position to get the plant collider and get the sequencer
            if (tgs.CellGetTag(index) == 1)
            {
                //this cell has a tree planted, but don’t run this in start
                //send to an array of “plants nearby”

                //for any rule make a bool in plantlife for “isFollowingRule” to see if neighbours are occupied or following a rule already
                //are two adjacent cells in the index occupied that’s a triad
                //if all cells are occupied that’s an arp, arp beats triad
            }
        }


        if (plantedInEditor)
        {
            ageCounter        -= 1;
            transform.position = tgs.CellGetPosition(cellIndex);
            tgs.CellSetTag(cellIndex, 1);
            tgs.CellToggleRegionSurface(cellIndex, true, growingTexture);
        }
        else
        {
            //Set age and fruit
            ageCounter = 0;
            //fruitAmount = 0;
            growthPeriod = 1;
        }
        StartCoroutine(Growth());
    }
Exemple #6
0
    void Update()
    {
        //Checks if has been picked up and equipped

        //Sends out raycast
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //Checks if raycast hits
        if (Physics.Raycast(ray, out hit))
        {
            //Checks if the hit is a ground tile and within Distance for hoeing
            if (hit.transform.gameObject.tag == "Ground" && Vector3.Distance(_player.transform.position, hit.point) <= shovelDistance && !textureShowing)
            {
                //grabs Cell tile and index
                Cell fertile   = tgs.CellGetAtPosition(hit.point, true);
                int  cellIndex = tgs.CellGetIndex(fertile);
                currentCellIndex = cellIndex;

                if (currentCellIndex != previousCellIndex)
                {
                    previousCellIndex = currentCellIndex;
                }

                //checks if cell is normal Ground
                if (tgs.CellGetTag(cellIndex) == 0)
                {
                    //Sets texture to clickable
                    tgs.CellToggleRegionSurface(cellIndex, true, canClickTexture);

                    //Takes click, sets tile to Fertile
                    if (Input.GetMouseButtonDown(0))
                    {
                        {
                            tgs.CellSetTag(fertile, 1);
                            StartCoroutine(ChangeTexture(cellIndex, fertileTexture));
                        }
                        //soundBoard.PlayOneShot(InteractSound);
                    }
                }

                //Switches tile back to normal Ground
                if (tgs.CellGetTag(previousCellIndex) == 0)
                {
                    StartCoroutine(ChangeTexture(currentCellIndex, groundTexture));
                }
            }
        }
    }
Exemple #7
0
    void Update()
    {
        //Checks if has been picked up and equipped
        if (inventMan.underPlayerControl)
        {
            //Sends out raycast
            if (Input.GetMouseButton(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                //start particle system
                //sphere cast

                //Checks if raycast hits
                if (Physics.Raycast(ray, out hit))
                {
                    //Checks if the hit is a ground tile and within Distance for hoeing
                    if (hit.transform.gameObject.tag == "sequencer" && Vector3.Distance(_player.transform.position, hit.point) <= axDistance)
                    {
                        currentTree = hit.transform.gameObject;
                        Cell tree  = tgs.CellGetAtPosition(hit.point, true);
                        int  index = currentTree.GetComponent <NewPlantLife>().cellIndex;
                        tgs.CellToggleRegionSurface(index, true, groundTexture);
                        tgs.CellSetTag(tree, 0);
                        //play sound
                        //play falling animation

                        if (currentTree.GetComponent <NewPlantLife>().ageCounter == 1)
                        {
                            SpawnCrops(1, 3);
                        }
                        else if (currentTree.GetComponent <NewPlantLife>().ageCounter == 2)
                        {
                            SpawnCrops(3, 6);
                        }
                        else if (currentTree.GetComponent <NewPlantLife>().ageCounter == 3)
                        {
                            SpawnCrops(5, 8);
                        }

                        cameraSource.PlayOneShot(cropYield);
                        Destroy(hit.transform.gameObject);
                    }
                }
            }
        }
    }
Exemple #8
0
    //Checks if fruit has collided with ground
    void OnCollisionEnter(Collision collision)
    {
        rb.isKinematic = true;
        if (collision.gameObject.tag == "Ground")
        {
            onGround = true;

            //Checks what ground tile this is using collision point
            Vector3 collisionPoint = collision.contacts[0].point;
            Cell    groundTile     = tgs.CellGetAtPosition(collisionPoint, true);
            int     cellIndex      = tgs.CellGetIndex(groundTile);

            //Starts Decompose using ground tile
            StartCoroutine(Decompose(groundTile, cellIndex, tgs.CellGetTag(cellIndex)));
        }
    }
Exemple #9
0
    //public int endEnd = 4;


    void Awake()
    {
        //sequencer.enabled = false;
        source = GetComponent <AudioSource>();
        source.outputAudioMixerGroup = mixer;

        tgs = TerrainGridSystem.instance;
        //mixer = Instantiate ();
        farmManager = GameObject.Find("farmManagerNew");
        //octave = farmManager.GetComponent<assignKey>().octave;
        life = GetComponent <NewPlantLife>();
        //sequencer = GameObject.Find ("Sequencer1").GetComponent<AudioHelm.Sequencer> ();
        //note = Random.Range (0, 6);

        bed         = GameObject.FindGameObjectWithTag("Bed");
        sleepScript = bed.GetComponent <Bed>();

        cell   = tgs.CellGetAtPosition(transform.position, true);
        row    = cell.row;
        column = cell.column;

        windDir = sleepScript.windDir;
        WindDirection();

        /*	if (Random.Range(0, 3) == 1)
         *      {
         *              note = 0;
         *              isLeader = true;
         *              start = Random.Range(0, startScale);
         *      }
         *      else
         *      {
         *              note = Random.Range(0, 6);
         *      }
         *
         *      changedSequence = false; */
    }
Exemple #10
0
    void Update()
    {
        //Checks if has been picked up and equipped
        if (inventMan.underPlayerControl)
        {
            //Sends out raycast
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //Checks if raycast hits
            if (Physics.Raycast(ray, out hit))
            {
                //Checks if the hit is a ground tile and within Distance for planting
                if (hit.transform.gameObject.tag == "Ground" && Vector3.Distance(_player.transform.position, hit.point) <= withinPlantingRange && !textureShowing)
                {
                    //grabs Cell tile and index
                    Cell fertile   = tgs.CellGetAtPosition(hit.point, true);
                    int  cellIndex = tgs.CellGetIndex(fertile);
                    currentCellIndex = cellIndex;

                    if (currentCellIndex != previousCellIndex)
                    {
                        previousCellIndex = currentCellIndex;
                    }

                    //checks if cell is fertile
                    if (tgs.CellGetTag(cellIndex) == 1)
                    {
                        //Sets texture to clickable
                        tgs.CellToggleRegionSurface(cellIndex, true, canClickTexture);

                        //If player clicks, we plant seed and clear up Equip slot
                        if (Input.GetMouseButtonDown(0))
                        {
                            plantSeed = true;
                            targetPos = hit.point;
                            playerControl.isHoldingSeed  = false;
                            inventMan.underPlayerControl = false;

                            invent.usedNowTakeAgain(inventMan.slotNumRetake);
                        }
                    }

                    //If it's a new cell, set last cell back to fertileTexture
                    if (tgs.CellGetTag(previousCellIndex) == 1)
                    {
                        StartCoroutine(ChangeTexture(currentCellIndex, fertileTexture));
                    }
                }
            }

            //This will be true either after a fruit decomposes, or after player plants seed
        }
        if (plantSeed)
        {
            //grabs Cell tile and index
            Cell plantTile = tgs.CellGetAtPosition(targetPos, true);
            int  cellIndex = tgs.CellGetIndex(plantTile);

            //checks if cell is Fertile
            if (tgs.CellGetTag(cellIndex) == 1 || planting)
            {
//                Debug.Log("planter");
                //Centers seed on tile
                transform.position = new Vector3(tgs.CellGetPosition(cellIndex).x, transform.position.y, tgs.CellGetPosition(cellIndex).z);
                //Calls PlantSeed function on selected tile
                PlantSeed(plantTile, cellIndex);
            }
        }
        //always rotate seed in world space
        transform.Rotate(0, 1, 0 * Time.deltaTime);
    }
    public void MoveSelectedUnit()
    {
        switch (state)
        {
            case STATE.IDLE:
                break;

            case STATE.MOVING:
                if (moveCounter < moveList.Count)
                {
                    Move(tgs.CellGetPosition(moveList[moveCounter]));
                }
                else
                {
                    moveCounter = 0;
                    state = STATE.MOVESELECT;
                    PositionUnitInCenterOfCell();
                }
                break;

            case STATE.MOVESELECT:
                if (Input.GetMouseButtonUp(0) && this.gameObject.layer == 12)
                {   //definition of target cell
                    int targetCell = tgs.cellHighlightedIndex;
                    if (targetCell != -1)
                    {//check if cell is selected
                        int startCell = tgs.CellGetIndex(tgs.CellGetAtPosition(transform.position, true));
                        float totalCost;
                        //builds a path from startCell to targetCell
                        moveList = tgs.FindPath(startCell, targetCell, out totalCost);
                        if (moveList == null)
                            return;

                        //check if path exceeds unitRange
                        if (unitMovementPoints >= totalCost)
                        {
                            moveCounter = 0;
                            state = STATE.MOVING;
                            unitMovementPoints -= totalCost;
                            Debug.Log("UnitMovementPoints: " + unitMovementPoints);

                        }
                        else
                        {
                            Debug.Log("Movement Range exceeded");
                        }
                    }
                    else
                    {
                        Debug.Log("No Cell");
                    }
                }
                break;
        }
    }