// Update is called once per frame void Update() { //you cannot end your turn if you are summoning, attacking, or moving a unit if (Input.GetKeyDown(KeyCode.E) && hub.cursor.canSelect && !hub.cursor.summoning && !hub.cursor.attacking) { if (firstTurn) { firstTurn = false; } hub.RemoveTiles("SummonTile"); hub.RemoveTiles("MoveTile"); hub.RemoveTiles("EnemyTile"); Character[] chars = FindObjectsOfType <Character>(); //proc all of the end of turn abilities for (int i = 0; i < chars.Length; i++) { if (chars[i].playerNumber == playerTurn) { chars[i].EndTurn(); } } //increment the turn count, and then set it to 1 if you go overboard playerTurn++; if (playerTurn > numberOfPlayers) { playerTurn = 1; } //set all characters who's turn it is to able to move for (int i = 0; i < chars.Length; i++) { if (chars[i].playerNumber == playerTurn) { chars[i].canMove = true; if (chars[i].name == "Summoner") { ((Summoner)chars[i]).mana += 5; //you get 5 mana every turn! (subject to change) hub.cursor.transform.position = chars[i].transform.position; //put the cursor over the in-turn summoner i = chars.Length + 1; } } } } //say whose turn it is turnDisplay.GetComponent <SpriteRenderer>().sprite = Resources.Load("Prefab/Turns/P" + playerTurn + "Turn", typeof(Sprite)) as Sprite; }
//used to move the cursor void DetectMovement() { //mv shows where the cursor has moved to. This is so I can move the camera with the cursor Vector3 mv = new Vector3(0, 0, 0); //Each key only gives input every tenth of a second. This keeps the cursor //moving smoothley //up if (Input.GetKey(KeyCode.UpArrow) && Time.time - hub.lastTimeUp >= 0.1f) { hub.lastTimeUp = Time.time; mv = new Vector3(0, spacer, 0); } //down if (Input.GetKey(KeyCode.DownArrow) && Time.time - hub.lastTimeDown >= 0.1f) { hub.lastTimeDown = Time.time; mv = new Vector3(0, -1 * spacer, 0); } //right if (Input.GetKey(KeyCode.RightArrow) && Time.time - hub.lastTimeRight >= 0.1f) { hub.lastTimeRight = Time.time; mv = new Vector3(spacer, 0, 0); } //left if (Input.GetKey(KeyCode.LeftArrow) && Time.time - hub.lastTimeLeft >= 0.1f) { hub.lastTimeLeft = Time.time; mv = new Vector3(-1 * spacer, 0, 0); } //for confirm and cancel, I wait a bit longer between inputs to help stop the game //from canceling and confirming between menus. Sometimes this can be noticable, but hardly.. //on confirm if (Input.GetKeyDown(KeyCode.Z) && Time.time - hub.lastTimeZ >= 0.25f) { hub.lastTimeZ = Time.time; //if you have not selected a character, do so if (canSelect && !summoning && !attacking) { DetectSelect(); } //if the character hits confirm, check if there is a summon tile, if so, place the unit there else if (summoning) { if (isOnTile("SummonTile")) { canSelect = true; summoning = false; hub.RemoveTiles("SummonTile"); selectedCharacter = null; } } //if the player is currently trying to select an attack target else if (attacking) { if (isOnTile("EnemyTile")) { canSelect = true; attacking = false; hub.RemoveTiles("EnemyTile"); //print(fightingCharacter.name); fightingCharacter.fight(hub.findCharacterAt(transform.position)); confirmFromMoveMenu(); } } //if you have a character selected, give them options from this point else if (isOnTile("MoveTile")) { GoToMoveMenu(); } } //on cancel if (Input.GetKeyDown(KeyCode.X) && Time.time - hub.lastTimeX >= 0.25f && !summoning) { hub.lastTimeX = Time.time; if (!canSelect) { selectedCharacter.transform.position = new Vector3(charOrgX, charOrgY, 0); } if (selectedCharacter != null) { selectedCharacter = null; } canSelect = true; //remove the extra tiles hub.RemoveTiles("MoveTile"); hub.RemoveTiles("EnemyTile"); hub.RemoveTiles("SummonTile"); } hub.cam.moveCamera(transform.position + mv); transform.position += mv; }