void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); clickCellPosition = gridLayout.WorldToCell(ray.origin); clickDistance = Vector3.Distance(gridLayout.CellToWorld(clickCellPosition), gridLayout.CellToWorld(movementController.playerCellPosition)); //Debug.Log("Click distance: " + clickDistance); Debug.Log("Click position: " + clickCellPosition); //Debug.Log(Vector3.Distance(gridLayout.CellToWorld(clickCellPosition), gridLayout.CellToWorld(movementController.playerCellPosition))); if (clickDistance < 0.35f) { //Debug.Log("Pre Player Transform: "+playerTransform.position); playerTransform.position += (gridLayout.CellToWorld(clickCellPosition) - gridLayout.CellToWorld(movementController.playerCellPosition)); //Debug.Log("Post Player Transform: " + playerTransform.position); //Debug.Log("Delta Click Cell Position: " + (gridLayout.CellToWorld(clickCellPosition) - gridLayout.CellToWorld(movementController.playerCellPosition))); movementController.playerCellPosition = gridLayout.WorldToCell(playerTransform.position); playerTransform.position = gridLayout.CellToWorld(movementController.playerCellPosition); //Debug.Log("Adj Player Transform: " + playerTransform.position); mapManager.UpdateFogOfWar(movementController.Vision, movementController.playerCellPosition); //Debug.Log("Player Cell Position: " + gridLayout.CellToWorld(movementController.playerCellPosition)); } } }
//public void GetMovementDirection() //{ // //The GetMovementDirection function determines the players intended movement based on updown and left right keys // if (upDownMovement < 0) // { // if (sidewaysMovement > 0) // { // direction = new Vector3(0.5f, -0.5f); //Move player down right // } // else if (sidewaysMovement < 0) // { // direction = new Vector3(-0.5f, -0.5f); //Move player down left // } // else // { // direction = new Vector3(0, -1, 0); //Move player down // } // // } // else if (upDownMovement > 0) // { // if (sidewaysMovement > 0) // { // direction = new Vector3(0.5f, 0.5f); //Move player up right // } // else if (sidewaysMovement < 0) // { // direction = new Vector3(-0.5f, 0.5f); //Move player up left // } // else // { // direction = new Vector3(0, 1, 0); //Move player up // } // } // //Once direction is determined, the player transform is moved to that location and centered in the destination cell // // transform.position += direction * moveScale; // playerCellPosition = gridLayout.WorldToCell(transform.position); // transform.position = gridLayout.CellToWorld(playerCellPosition); // mapManager.UpdateFogOfWar(vision, playerCellPosition); //A call to the fog of war function is made to update what the player can see //} public void MovePlayer(Vector3Int moveTarget, bool regularMove) { SetOrientation(gridLayout.CellToWorld(moveTarget)); //first, orient the ship correctly for the hex it will be moving to transform.position += (gridLayout.CellToWorld(moveTarget) - gridLayout.CellToWorld(playerCellPosition)); //update the player game object transform position to the new coordinates from the clicked cell (look at how to do this smoothly) playerCellPosition = gridLayout.WorldToCell(transform.position); //update the player cell position //transform.position = gridLayout.CellToWorld(playerCellPosition); //use the updated player cell position to ensure the player game object is centered in the cell playerCellPositionCubeCoords = mapManager.evenq2cube(playerCellPosition); //transform.position = Vector3.Lerp(transform.position,gridLayout.CellToWorld(playerCellPosition),Time.deltaTime); //use the updated player cell position to ensure the player game object is centered in the cell mapManager.UpdateFogOfWar(vision, playerCellPosition); //clear the fog of was from the new position if (regularMove) { hasMoved = true; if (turnManager.combatActive && abilityController.AbilityUsed) { uiController.SetEndTurnButtonState(); } } //Debug.Log("has moved is "+hasMoved); }
void Start() { movementState = true; gridLayout = GameObject.Find("Grid").GetComponent <GridLayout>(); //search for and save a reference to the grid layout component playerCellPosition = gridLayout.WorldToCell(transform.position); //get a reference to the player cell position in cell coordinates transform.position = gridLayout.CellToWorld(playerCellPosition); //center the player game object within it's nearest cell by converting the cell coordinates to world coordinates gameController = GameObject.Find("GameController"); mapManager = gameController.GetComponent <ManageMap>(); //get a reference to the map manager clickManager = gameController.GetComponent <ClickManager>(); //get a reference to the map manager resourceAndUpgradeManager = gameController.GetComponent <ResourceAndUpgradeManager>(); uiController = gameController.GetComponent <UIControl>(); turnManager = gameController.GetComponent <TurnManager>(); vision = resourceAndUpgradeManager.CurrentMaxSensorRange; mapManager.UpdateFogOfWar(vision, playerCellPosition); //run an update fog of war command from the map manager to clear the fog around the player character on scene start //rotTrack = 0; //set rotation tracking to 0 (this will likely be depreicated with a new rotation system abilityActive = false; //set the ability active flag to false cantMove = false; abilityController = GameObject.Find("Player").GetComponent <AbilityController>(); }
private void LoadResourceAndUpgradeData() { if (QuickSaveRoot.Exists(resourceAndUpgradeDataSaveFileName)) //if a save file exists, load data from that file { QuickSaveReader instReader = QuickSaveReader.Create(resourceAndUpgradeDataSaveFileName); //create an instance of the quick save reader to pull in the save file resources = instReader.Read <int>("resources"); TotalResources = instReader.Read <int>("totalResources"); SolarSystemNumber = instReader.Read <int>("solarSystemNumber"); currentMaxLaserRange = instReader.Read <int>("currentMaxLaserRange"); currentMaxLaserRecharge = instReader.Read <int>("currentMaxLaserRecharge"); currentMaxRocketRange = instReader.Read <int>("currentMaxRocketRange"); currentMaxRocketReload = instReader.Read <int>("currentMaxRocketReload"); currentMaxRocketYield = instReader.Read <int>("currentMaxRocketYield"); currentMaxJumpRange = instReader.Read <int>("currentMaxJumpRange"); currentMaxJumpRecharge = instReader.Read <int>("currentMaxJumpRecharge"); currentMaxShieldBoost = instReader.Read <int>("currentMaxShieldBoost"); currentShieldOverboostActive = instReader.Read <bool>("currentShieldOverboostActive"); currentMaxShieldBoostRecharge = instReader.Read <int>("currentMaxShieldBoostRecharge"); currentMaxHealth = instReader.Read <int>("currentMaxHealth"); currentMaxShields = instReader.Read <int>("currentMaxShields"); currentMaxSensorRange = instReader.Read <int>("currentMaxSensorRange"); rocketsInstalled = instReader.Read <bool>("rocketsInstalled"); jumpDriveInstalled = instReader.Read <bool>("jumpDriveInstalled"); shieldBoostInstalled = instReader.Read <bool>("shieldBoostInstalled"); abilityController.maxLaserRange = currentMaxLaserRange; abilityController.rocketRange = currentMaxRocketRange; abilityController.rocketReloadTime = currentMaxRocketReload; abilityController.maxJumpRange = currentMaxJumpRange; abilityController.shieldBoostRechargeTime = CurrentMaxShieldBoostRecharge; movementController.Vision = CurrentMaxSensorRange; mapManager.UpdateFogOfWar(CurrentMaxSensorRange, gridlayout.WorldToCell(player.transform.position)); playerHealthControl.currentPlayerHealth = instReader.Read <int>("currentHealth"); playerHealthControl.currentPlayerShields = instReader.Read <int>("currentShields"); abilityController.jumpRange = instReader.Read <int>("currentJumpCharge"); abilityController.laserRange = instReader.Read <int>("currentLaserCharge"); //Debug.Log("Laser range loaded as " + abilityController.laserRange); abilityController.currentShieldBoostCharge = instReader.Read <int>("currentShieldBoostCharge"); abilityController.currentRocketReloadAmount = instReader.Read <int>("currentRocketReload"); laserRangeUpgradeCost = instReader.Read <int>("laserRangeUpgradeCost"); laserRechargeUpgradeCost = instReader.Read <int>("laserRechargeUpgradeCost"); rocketRangeUpgradeCost = instReader.Read <int>("rocketRangeUpgradeCost"); rocketReloadUpgradeCost = instReader.Read <int>("rocketReloadUpgradeCost"); rocketYieldUpgradeCost = instReader.Read <int>("rocketYieldUpgradeCost"); jumpRangeUpgradeCost = instReader.Read <int>("jumpRangeUpgradeCost"); jumpRechargeUpgradeCost = instReader.Read <int>("jumpRechargeUpgradeCost"); shieldBoostUpgradeCost = instReader.Read <int>("shieldBoostUpgradeCost"); shieldOverboostUpgradeCost = instReader.Read <int>("shieldOverboostUpgradeCost"); shieldBoostRechargeUpgradeCost = instReader.Read <int>("shieldBoostRechargeUpgradeCost"); shieldMaxUpgradeCost = instReader.Read <int>("shieldMaxUpgradeCost"); healthMaxUpgradeCost = instReader.Read <int>("healthMaxUpgradeCost"); sensorRangeUpgradeCost = instReader.Read <int>("sensorRangeUpgradeCost"); threatLevel = instReader.Read <float>("threatLevel"); MaxThreatLevelCounter = instReader.Read <int>("maxThreatLevelCounter"); uiController.SetHealthState(CurrentMaxHealth, playerHealthControl.currentPlayerHealth, CurrentMaxShields, playerHealthControl.currentPlayerShields); uiController.SetLaserCharge(abilityController.laserRange, currentMaxLaserRange); uiController.SetJumpCharge(abilityController.jumpRange, CurrentMaxJumpRange); uiController.SetShieldBoostRechargeState(abilityController.currentShieldBoostCharge, CurrentMaxShieldBoostRecharge); uiController.SetRocketReloadState(abilityController.currentRocketReloadAmount, CurrentMaxRocketReload); uiController.SetResourceCount(resources); uiController.SetUpgradeButtons(); uiController.SetThreatLevelSlider(ThreatLevel); Debug.Log("Tried to load resources and upgrades"); } }