예제 #1
0
    private void GetExplosionNeighbours(Vector3Int origin, int explosionYield)
    {
        GameObject[] enemies   = GameObject.FindGameObjectsWithTag("Enemy");
        Vector3Int   playerPos = player.GetComponent <MovementController>().playerCellPosition;

        for (int x = -1 * explosionYield; x <= 1 * explosionYield; x++)
        {
            for (int y = -1 * explosionYield; y <= 1 * explosionYield; y++)
            {
                int modX = origin.x + x;
                int modY = origin.y + y;

                if (modX < mapManager.mapXMax && modX > mapManager.mapXMin && modY < mapManager.mapYMax && modY > mapManager.mapYMin)
                {
                    if (mapManager.HexCellDistance(mapManager.evenq2cube(origin), mapManager.evenq2cube(new Vector3Int(modX, modY, 0))) <= 1 * explosionYield)
                    {
                        foreach (GameObject enemy in enemies)
                        {
                            Vector3Int enemyPos = gridLayout.WorldToCell(enemy.transform.position);

                            if (enemyPos.x == modX && enemyPos.y == modY)
                            {
                                enemy.GetComponent <EnemyShipControl>().DestroySelf(true);
                            }
                        }
                        if (playerPos.x == modX && playerPos.y == modY)
                        {
                            playerHealthControl.PlayerHit(1 * explosionYield);
                            if (playerHealthControl.currentPlayerHealth <= 0)
                            {
                                //playerHealthControl.DestroyPlayer();
                                playerHealthControl.StartCoroutine("DestroyPlayer");
                            }
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    public void landButton()
    {
        if (planetState)
        {
            currentPlanet.GetComponent <PlanetController>().PlanetMined();
            movementController.HasMoved   = false;
            abilityController.AbilityUsed = false;
            Debug.Log(planetName);
            //Debug.Log("The resources have been collected from this planet --> "+currentPlanet.GetComponent<PlanetController>().ResourcesCollectd);
            Vector3Int currentPlanetCell = gridLayout.WorldToCell(currentPlanet.transform.position);
            Debug.Log(currentPlanetCell);
            if (currentPlanet.GetComponent <PlanetController>().ResourcesCollectd)
            {
                uiController.ResourcesCollectedWarning();
            }
            else
            {
                float distToStarGate = mapManager.HexCellDistance(mapManager.evenq2cube(mapManager.StarGateSpawnPoint), mapManager.evenq2cube(currentPlanetCell));
                //Debug.Log(distToStarGate);
                //Debug.Log(planetResourceAmount);
                //Debug.Log((int)(planetResourceAmount * (distToStarGate * (1 / ((float)mapManager.mapXMax / 2 - 1)) + (((float)mapManager.mapXMax / 2 - 2) / ((float)mapManager.mapXMax / 2 - 1)))));
                int distModifiedResourceAmount = (int)(planetResourceAmount * (distToStarGate * (1 / ((float)mapManager.mapXMax / 2 - 1)) + (((float)mapManager.mapXMax / 2 - 2) / ((float)mapManager.mapXMax / 2 - 1))));
                currentPlanet.GetComponent <PlanetController>().ResourcesCollectd = true;
                resourceAndUpgradeManager.ModifyResources(distModifiedResourceAmount, true);
                resourceAndUpgradeManager.AdjustThreatLevel(1500);
                uiController.SetThreatLevelSlider(resourceAndUpgradeManager.ThreatLevel);
                mapManager.ContextualSpawnEnemies();
            }

            foreach (PlanetObject planet in mapManager.spawnedPlanets)
            {
                if (planet.xCoordinate == currentPlanetCell.x && planet.yCoordinate == currentPlanetCell.y)
                {
                    mapManager.spawnedPlanets.Add(new PlanetObject(planet.xCoordinate, planet.yCoordinate, planet.planetString, currentPlanet.GetComponent <PlanetController>().ResourcesCollectd));
                    mapManager.spawnedPlanets.Remove(planet);
                    break;
                }
            }
            resourceAndUpgradeManager.SaveResourceAndUpgradeData();
            //foreach (PlanetObject planet in mapManager.spawnedPlanets)
            //{
            //    Debug.Log("The planet at " + planet.xCoordinate + "x " + planet.yCoordinate + "y" + " has had it's resources collected --> " + planet.resourcesCollected);
            //}

            if (mapManager.saveName == "TutorialFile")
            {
                tutorialManager.ExplainCombat();
            }
        }
    }
예제 #3
0
    private void Update()
    {
        if (mapManager.saveName == "TutorialFile")
        {
            if (mapManager.revealedTilesUnique.Count >= 20 && !flowchart.GetBooleanVariable("Exploration"))
            {
                flowchart.SetBooleanVariable("Exploration", true);
                flowchart.ExecuteBlock("Tutorial5");
                Debug.Log("Exploration changed");
            }

            if (readyToExplainWarpGate && !explainedWarpGate)
            {
                if (mapManager.HexCellDistance(mapManager.evenq2cube(gridLayout.WorldToCell(player.transform.position)), mapManager.evenq2cube(gridLayout.WorldToCell(starGate.transform.position))) < 3)
                {
                    ExplainWarpGate();
                }
            }
        }
    }
예제 #4
0
    public void TakeTurn()
    {
        if (!shotIncoming)
        {
            int          distToPlayer = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(player.gameObject.GetComponent <MovementController>().playerCellPosition));
            GameObject[] rockets      = GameObject.FindGameObjectsWithTag("Rocket");
            foreach (GameObject rocket in rockets)
            {
                int distToRocket = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                Debug.Log(thisEnemyName + " is " + distToRocket + " hexes from a rocket");
                if (distToRocket < resourceAndUpgradeManager.CurrentMaxRocketYield + 2)
                {
                    runAway = true;
                }
            }

            if (rockets.Length <= 0)
            {
                runAway = false;
            }


            switch (thisEnemyName)
            {
            case "EnemyA":
                List <Vector3Int> playerFlats    = mapManager.GetFlats(3, movementController.playerCellPosition, false);
                List <Vector3Int> playerEndFlats = mapManager.GetFlats(3, movementController.playerCellPosition, true);
                Vector3Int        nearestEndFlat = playerEndFlats[0];
                int distToNearestEndFlat         = 999999;
                foreach (Vector3Int flat in playerEndFlats)
                {
                    int distToFlat = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(flat));

                    if (distToFlat < distToNearestEndFlat)
                    {
                        distToNearestEndFlat = distToFlat;
                        nearestEndFlat       = flat;
                    }
                }

                Vector3Int nearestFlat       = playerFlats[0];
                int        distToNearestFlat = 999999;
                foreach (Vector3Int flat in playerFlats)
                {
                    int distToFlat = mapManager.HexCellDistance(mapManager.evenq2cube(enemyCellPosition), mapManager.evenq2cube(flat));
                    if (distToFlat < distToNearestFlat)
                    {
                        distToNearestFlat = distToFlat;
                        nearestFlat       = flat;
                    }
                    if (flat == enemyCellPosition)
                    {
                        inFlats = true;
                        break;
                    }
                    else
                    {
                        inFlats = false;
                    }
                }
                if (enemyCellPosition != nearestEndFlat && !inFlats || runAway)
                {
                    if (distToPlayer < 3)
                    {
                        nearestEndFlat = nearestFlat;
                    }
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i = 1;
                    foreach (Vector3Int neighbour in neighbours)
                    {
                        if (i == 1)
                        {
                            shortestMove     = neighbour;
                            shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat));

                            if (rockets.Length > 0)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                            }
                        }
                        else
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat)) < shortestMoveDist)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(nearestEndFlat));
                            }

                            int thisSumFurthestFromRocketsDist = 0;
                            foreach (GameObject rocket in rockets)
                            {
                                thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                            }
                            if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                            }
                        }
                        i++;
                    }
                    foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                    {
                        if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                        {
                            mapManager.spawnedEnemies.Remove(listEnemy);
                            break;
                        }
                    }

                    if (runAway)
                    {
                        SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                        transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    else
                    {
                        SetOrientation(gridLayout.CellToWorld(shortestMove));
                        transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    enemyCellPosition = gridLayout.WorldToCell(transform.position);
                    thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                    mapManager.spawnedEnemies.Add(thisEnemyObject);
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                }


                break;

            case "EnemyB":
                if (distToPlayer > 1 || runAway)
                {
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i = 1;
                    foreach (Vector3Int neighbour in neighbours)
                    {
                        if (i == 1)
                        {
                            shortestMove     = neighbour;
                            shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);

                            if (rockets.Length > 0)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                            }
                        }
                        else
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords) < shortestMoveDist)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);
                            }

                            int thisSumFurthestFromRocketsDist = 0;
                            foreach (GameObject rocket in rockets)
                            {
                                thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                            }
                            if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                            {
                                furthestFromRockets        = neighbour;
                                sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                            }
                        }
                        i++;
                    }

                    foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                    {
                        if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                        {
                            mapManager.spawnedEnemies.Remove(listEnemy);
                            break;
                        }
                    }

                    if (runAway)
                    {
                        SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                        transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    else
                    {
                        SetOrientation(gridLayout.CellToWorld(shortestMove));
                        transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                    }
                    enemyCellPosition = gridLayout.WorldToCell(transform.position);
                    thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                    mapManager.spawnedEnemies.Add(thisEnemyObject);
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                }

                break;

            case "EnemyC":
                if (distToPlayer > 2 || runAway)
                {
                    List <Vector3Int> neighbours          = mapManager.GetNeighbours(enemyCellPosition, 1);
                    Vector3Int        shortestMove        = new Vector3Int(0, 0, 0);
                    int        shortestMoveDist           = 100;
                    Vector3Int longestJump                = new Vector3Int(0, 0, 0);
                    int        longestJumpDist            = 0;
                    Vector3Int furthestFromRockets        = new Vector3Int(0, 0, 0);
                    int        sumFurthestFromRocketsDist = 0;
                    int        i        = 1;
                    int        randJump = Random.Range(0, 2);
                    if (jumpChargeTracker < 1 && randJump > 0.1)
                    {
                        jumpChargeTracker = 1;
                        List <Vector3Int> playerNeighbours = mapManager.GetNeighbours(movementController.playerCellPosition, 2);

                        foreach (Vector3Int playerNeighbour in playerNeighbours)
                        {
                            if (mapManager.HexCellDistance(mapManager.evenq2cube(playerNeighbour), mapManager.evenq2cube(enemyCellPosition)) > longestJumpDist)
                            {
                                longestJump     = playerNeighbour;
                                longestJumpDist = mapManager.HexCellDistance(mapManager.evenq2cube(playerNeighbour), mapManager.evenq2cube(enemyCellPosition));
                            }
                        }
                        foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                        {
                            if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                            {
                                mapManager.spawnedEnemies.Remove(listEnemy);
                                break;
                            }
                        }
                        SetOrientation(gridLayout.CellToWorld(longestJump));
                        transform.position += (gridLayout.CellToWorld(longestJump) - gridLayout.CellToWorld(enemyCellPosition));
                        enemyCellPosition   = gridLayout.WorldToCell(transform.position);
                        thisEnemyObject     = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                        mapManager.spawnedEnemies.Add(thisEnemyObject);
                    }
                    else
                    {
                        foreach (Vector3Int neighbour in neighbours)
                        {
                            if (i == 1)
                            {
                                shortestMove     = neighbour;
                                shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);

                                if (rockets.Length > 0)
                                {
                                    furthestFromRockets        = neighbour;
                                    sumFurthestFromRocketsDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rockets[0].transform.position)));
                                }
                            }
                            else
                            {
                                if (mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords) < shortestMoveDist)
                                {
                                    shortestMove     = neighbour;
                                    shortestMoveDist = mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), movementController.playerCellPositionCubeCoords);
                                }

                                int thisSumFurthestFromRocketsDist = 0;
                                foreach (GameObject rocket in rockets)
                                {
                                    thisSumFurthestFromRocketsDist += mapManager.HexCellDistance(mapManager.evenq2cube(neighbour), mapManager.evenq2cube(gridLayout.WorldToCell(rocket.transform.position)));
                                }
                                if (thisSumFurthestFromRocketsDist > sumFurthestFromRocketsDist)
                                {
                                    furthestFromRockets        = neighbour;
                                    sumFurthestFromRocketsDist = thisSumFurthestFromRocketsDist;
                                }
                            }
                            i++;
                        }

                        foreach (EnemyObject listEnemy in mapManager.spawnedEnemies)
                        {
                            if (listEnemy.xCoordinate == thisEnemyObject.xCoordinate && listEnemy.yCoordinate == thisEnemyObject.yCoordinate)
                            {
                                mapManager.spawnedEnemies.Remove(listEnemy);
                                break;
                            }
                        }

                        if (runAway)
                        {
                            SetOrientation(gridLayout.CellToWorld(furthestFromRockets));
                            transform.position += (gridLayout.CellToWorld(furthestFromRockets) - gridLayout.CellToWorld(enemyCellPosition));
                        }
                        else
                        {
                            SetOrientation(gridLayout.CellToWorld(shortestMove));
                            transform.position += (gridLayout.CellToWorld(shortestMove) - gridLayout.CellToWorld(enemyCellPosition));
                        }
                        enemyCellPosition = gridLayout.WorldToCell(transform.position);
                        thisEnemyObject   = new EnemyObject(enemyCellPosition.x, enemyCellPosition.y, thisEnemyObject.enemyString);
                        mapManager.spawnedEnemies.Add(thisEnemyObject);

                        if (jumpChargeTracker >= 1)
                        {
                            jumpChargeTracker--;
                        }
                    }
                }
                else
                {
                    Instantiate(enemyLaser, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity);
                    if (jumpChargeTracker >= 1)
                    {
                        jumpChargeTracker--;
                    }
                }

                break;

            default:
                break;
            }
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        //player = GameObject.FindGameObjectWithTag("Player"); //at one point, the player game object was being set every update. I don't think this is necessary, but it may have had some effect.
        //if (clickManager.MouseClicked && !turnOffAb) //check if the laser has been activated
        if (clickManager.TouchRegistered && !turnOffAb)                  //check if the laser has been activated
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //get the current position of the mouse pointer
            //target = gridLayout.WorldToCell(ray.origin); //set the position of the target to the position of the mouse pointer in grid coordinates
            target = gridLayout.WorldToCell(clickManager.TouchPosition); //set the position of the target to the position of the mouse pointer in grid coordinates
            //target = gridLayout.WorldToCell(clickManager.ClickPosition); //set the position of the target to the position of the mouse pointer in grid coordinates
            //clickDistance = Vector3.Distance(gridLayout.CellToWorld(target), gridLayout.CellToWorld(gridLayout.WorldToCell(player.transform.position))); //this is find the distance between the player and the point where they click. It converts multiple times bewteen the grid and world coordinates because it wants the world coordinates of the exact center of the relevant hexs. The easiest way I have found to do this is to first take world coordinates, convert them to grid coordinates, then convert those back to world coordinates
            playerHex     = gridLayout.WorldToCell(player.transform.position);                                           //get the current position of the player in grid coordinates
            clickDistance = mapManager.HexCellDistance(mapManager.evenq2cube(target), mapManager.evenq2cube(playerHex)); //This calculation determines the distance to the clicked cell using the cube coordiante method

            if (laserState && clickDistance <= laserRange)                                                               //if the player clicks the mouse and it is within the set range for the laser then initiate the firing sequence
            {
                //The purpose of this loop is to identify what hexes within the range above are also identified by the highlighted hexes shown to the player. This is a hack and there must certainly be a better way to do this, but it ultimately comes down to figuring out a better method of measuring distance on the hex grid
                for (int x = -laserRange; x <= laserRange; x++)     //iterate x's
                {
                    for (int y = -laserRange; y <= laserRange; y++) //iterate y's
                    {
                        //Debug.Log(target);
                        //Debug.Log(playerHex + new Vector3Int(x, y, 0));
                        if (target == (playerHex + new Vector3Int(x, y, 0)) && weaponState) //check if the target hex matches one of the highlighted hexes
                        {
                            GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
                            foreach (GameObject enemy in enemies) //loop through the list of any enemies currently in the scene and destroy them
                            {
                                if (!enemy.GetComponent <EnemyShipControl>().CheckShotRunning)
                                {
                                    StartCoroutine(enemy.GetComponent <EnemyShipControl>().CheckShot(target));
                                }
                            }

                            instX = player.transform.position.x;                                                                                         //set the x position of the instatiation equal to the player's current x position
                            instY = player.transform.position.y;                                                                                         //set the y position of the instatiation equal to the player's current x position
                            //laserSpwanMod = Vector3.Normalize(player.transform.position - ray.origin); //calculate a vector that points between the target and the player, then normalize it
                            laserSpwanMod = Vector3.Normalize(player.transform.position - clickManager.TouchPosition);                                   //calculate a vector that points between the target and the player, then normalize it
                            //laserSpwanMod = Vector3.Normalize(player.transform.position - clickManager.ClickPosition); //calculate a vector that points between the target and the player, then normalize it
                            newInstance = Instantiate(laser, new Vector3(instX - (laserSpwanMod.x), instY - (laserSpwanMod.y), 0), Quaternion.identity); //Instantiate the laser object and apply some modifications that move the laser off of the ceneter of the player game object and to the edge of the ship sprite (this looks better in game then spawning at the center).
                            turnOffAb   = true;
                        }
                    }
                }
            }
            else if (jumpState)
            {
                bool makeJump = false;
                foreach (Vector3Int cell in jumpCells)
                {
                    if (target == cell)
                    {
                        makeJump = true;
                    }
                }
                if (makeJump)
                {
                    JumpActive();
                    //Debug.Log("set true at Ab con 112");
                    abilityUsed = true;
                    clickManager.WaitForQuarterSec();
                    movementController.MovePlayer(target, false);
                    //jumpRange = 0;
                    jumpRange -= (int)clickDistance;
                    uiController.SetJumpCharge(jumpRange, maxJumpRange);
                    if (turnManager.combatActive)
                    {
                        movementController.HasMoved = true;
                        uiController.SetEndTurnButtonState();
                    }
                    turnManager.StartCoroutine(turnManager.UpdateTurn());
                }
            }
            else if (rocketState)
            {
                bool inRange = false;
                foreach (Vector3Int flat in playerFlats)
                {
                    if (target == flat)
                    {
                        inRange = true;
                    }
                }
                if (inRange && !hasFired)
                {
                    Debug.Log("sending off a rocket");
                    hasFired = true;
                    currentRocketReloadAmount = 0;
                    Instantiate(rocket, player.transform.position, Quaternion.identity);
                    turnManager.StartCoroutine(turnManager.UpdateTurn());
                }
            }
        }
        if (turnOffAb)
        {
            timer += Time.deltaTime;
            if (timer > 0.5)
            {
                //Debug.Log("Timer");
                if (laserState)
                {
                    LaserActive();
                }
                if (turnManager.combatActive)
                {
                    //laserRange = 0;
                    laserRange -= (int)clickDistance;
                    uiController.SetLaserCharge(laserRange, maxLaserRange);
                }
                timer     = 0;
                turnOffAb = false;
                //Debug.Log("set true at Ab con 156");
                abilityUsed = true;
                turnManager.StartCoroutine(turnManager.UpdateTurn());
                if (turnManager.combatActive && movementController.HasMoved)
                {
                    uiController.SetEndTurnButtonState();
                }
            }
        }
    }
예제 #6
0
    void LateUpdate()
    {
        //This update loop is looking for player input and determining if movement is available to the hex indicated
        if (!abilityController.abilityActive && (!turnManager.combatActive || turnManager.playerTurn) && movementState) //if the ability active flag is true then disable movement
        {
            //The next two parameters and the following if statement are for keyboard movement. Primary movement is mouse based, but keyboard is kept for an alternate control scheme. Will need to make sure that all functionality is duplicated on the keyboard
            //sidewaysMovement = Input.GetAxis("Horizontal");
            //upDownMovement = Input.GetAxis("Vertical");
            //
            ////Determine if the player has moved yet for a given keypress. Since up/down movement does not require any addition definition, that is used as the initiation of all motion
            //if (upDownMovement == 0)
            //{
            //    //hasMoved = false;
            //}
            //else if (upDownMovement != 0 && !hasMoved) //If up or down input is detected and the player has not moved, then call the movement function and set hasMoved to true
            //{
            //    hasMoved = true;
            //    GetMovementDirection();
            //}

            //the following if statement controls the mouse movement
            //if (clickManager.MouseClicked) //listen for mouse input from the user
            if (TouchRegistered) //listen for mouse input from the user
            {
                //Debug.Log("Movement Controller hears the touch");
                cantMove = false;
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);              //when the mouse is clicked, create a ray whose origin is at the mouse click position
                //clickCellPosition = gridLayout.WorldToCell(ray.origin); //extract the mouse click position from the ray and convert it to grid space
                clickCellPosition = gridLayout.WorldToCell(clickManager.TouchPosition);   //extract the mouse click position from the ray and convert it to grid space
                //clickCellPosition = gridLayout.WorldToCell(clickManager.ClickPosition); //extract the mouse click position from the ray and convert it to grid space
                clickCellPositionCubeCoords  = mapManager.evenq2cube(clickCellPosition);  //the clicked cell coordinates converted to cube coordinates
                playerCellPositionCubeCoords = mapManager.evenq2cube(playerCellPosition); //the player cell coordinates converted to cube coordinates



                //Debug.Log("Clicked distance " + mapManager.HexCellDistance(playerCellPositionCubeCoords, clickCellPositionCubeCoords));
                //Debug.Log("Clicked on "+clickCellPosition);
                //Calculate the distance between the player game object and the clicked cell
                clickDistance = mapManager.HexCellDistance(playerCellPositionCubeCoords, clickCellPositionCubeCoords);
                int i = 1;
                foreach (EnemyObject enemyPos in mapManager.spawnedEnemies)
                {
                    //Debug.Log("Enemy " + i + " " + enemyPos.xCoordinate + " " + enemyPos.yCoordinate);
                    i++;

                    if (clickCellPosition.x == enemyPos.xCoordinate && clickCellPosition.y == enemyPos.yCoordinate)
                    {
                        cantMove = true;
                    }
                }

                if (clickCellPosition.x > mapManager.mapXMax - 2 || clickCellPosition.x < mapManager.mapXMin + 2 || clickCellPosition.y > mapManager.mapYMax - 1 || clickCellPosition.y < mapManager.mapYMin + 1)
                {
                    cantMove = true;
                }

                if (!turnManager.combatActive)
                {
                    hasMoved = false;
                }

                if (clickCellPosition.x == playerCellPosition.x && clickCellPosition.y == playerCellPosition.y)
                {
                    cantMove = true;
                }

                //if (clickDistance < 0.33f) //Each cell is 32 pixels wide, so if the click distance is 32 or less then allow the player to move
                if (clickDistance <= moveRange && !cantMove && !hasMoved && !clickManager.waitForQuarterSec) //distance calculations in cube coordinates return distance in integer units so this can be compared directly to the value defining the movement range
                {
                    StopCoroutine(MoveLongerDistance());
                    MovePlayer(clickCellPosition, true);
                    MoveCount++;
                    resourceAndUpgradeManager.AdjustThreatLevel(MoveCount);
                    uiController.SetThreatLevelSlider(resourceAndUpgradeManager.ThreatLevel);

                    if (turnManager.combatActive)
                    {
                        abilityController.jumpRange--;
                        StartCoroutine(turnManager.UpdateTurn());
                    }
                    else
                    {
                        if (resourceAndUpgradeManager.ThreatLevel >= 1)
                        {
                            resourceAndUpgradeManager.MaxThreatLevelAssault();
                        }
                    }
                    //Debug.Log("MC 116");
                }
                else if (clickDistance > moveRange && !cantMove && !hasMoved && !clickManager.waitForQuarterSec && !turnManager.combatActive)
                {
                    if (!longMoveRunning)
                    {
                        StartCoroutine(MoveLongerDistance());
                    }
                    if (resourceAndUpgradeManager.ThreatLevel >= 1)
                    {
                        resourceAndUpgradeManager.MaxThreatLevelAssault();
                    }
                }
            }
        }
    }