//Dragon Kick public override void Ability3() { GameManager.actionInProcess = true; Debug.Log("Ability3"); Debug.Log("Cooldown : " + currentCooldowns[2]); if (currentCooldowns[2] > 0) { GameManager.actionInProcess = false; return; } TileBehavior targetTile = GetTarget(); if (targetTile != null && !HitEnemy(targetTile, curStatArr[1] + 2) && !targetTile.HasUnit() && targetTile.tileType != "wall") { Debug.Log("about to attack move"); GetComponent <PlayerManager>().StartMoveDuringAttackAnimation(); targetTile = GetTarget(); HitEnemy(targetTile, curStatArr[1]); } updateCooldowns(); currentCooldowns[2] += abilityCooldowns[2]; Debug.Log("Cooldown After: " + currentCooldowns[2]); GameManager.actionInProcess = false; }
IEnumerator MoveInDirection(string direction) { float tileSize = GetComponent <SpriteRenderer>().sprite.bounds.size.x; // Calculate the steps you need to take //Take that step! if (direction.Equals("up")) { myCharacter.transform.position += new Vector3(0, tileSize); TileBehavior upTile = myCharacter.occupiedTile.Up; if (upTile != null && upTile.tileType != WALL && !upTile.HasUnit()) { myCharacter.occupiedTile.ClearUnit(); myCharacter.occupiedTile = upTile; myCharacter.myDirection = Character.Direction.UP; } } else if (direction.Equals("right")) { myCharacter.transform.position += new Vector3(tileSize, 0); TileBehavior rightTile = myCharacter.occupiedTile.Right; if (rightTile != null && rightTile.tileType != WALL && !rightTile.HasUnit()) { myCharacter.occupiedTile.ClearUnit(); myCharacter.occupiedTile = rightTile; myCharacter.myDirection = Character.Direction.RIGHT; } } else if (direction.Equals("down")) { myCharacter.transform.position += new Vector3(0, -tileSize); TileBehavior downTile = myCharacter.occupiedTile.Down; if (downTile != null && downTile.tileType != WALL && !downTile.HasUnit()) { myCharacter.occupiedTile.ClearUnit(); myCharacter.occupiedTile = downTile; myCharacter.myDirection = Character.Direction.DOWN; } } else if (direction.Equals("left")) { myCharacter.transform.position += new Vector3(-tileSize, 0); TileBehavior leftTile = myCharacter.occupiedTile.Left; if (leftTile != null && leftTile.tileType != WALL && !leftTile.HasUnit()) { myCharacter.occupiedTile.ClearUnit(); myCharacter.occupiedTile = leftTile; myCharacter.myDirection = Character.Direction.LEFT; } } myCharacter.updateCooldowns(); myCharacter.RecalculateDepth(); myCharacter.StartBounceAnimation(); yield return(new WaitForSeconds(stepDuration)); myCharacter.occupiedTile.PlaceUnit(myCharacter); }
public bool validTarget(TileBehavior tile) { if (tile == null) { return(false); } Debug.Log("target exists : " + tile.HasUnit()); Character target = tile.GetUnit(); return(target != null && target != this); }
public void AttackEnemy() { GameManager.actionInProcess = true; MakeAbilitySound(regularPunchSound); int damage = curStatArr[0]; TileBehavior target = GetTarget(); if (target != null && target.HasUnit() && target.GetUnit() != this) { Debug.Log("Attacked"); Character enemy = target.GetUnit(); if (enemy.HPDamage(curStatArr[1])) { experience += enemy.value; Debug.Log("experience : " + (experience)); } } updateCooldowns(); GameManager.actionInProcess = false; return; }
public void Turn() { if (myCharacter.currentHealth <= 0) { return; } //See if player is in line of sight if (DetectPlayer()) { float tileSize = GetComponent <SpriteRenderer>().sprite.bounds.size.x; //Calculate path to player's tile from this tile List <string> steps = TileBehavior.CalculateMovement(new List <string>(), myCharacter.occupiedTile, PlayerManager.singleton.GetTile(), tileSize, viewDistance); //If there exists a path, take the first step towards it if (steps != null) { //If player is adjacent if (steps.Count <= 0) { myCharacter.Ability1(); } else { StartCoroutine(MoveInDirection(steps[0])); } } } else { List <string> directions = new List <string>(); directions.Add("up"); directions.Add("down"); directions.Add("left"); directions.Add("right"); while (directions.Count > 0) { int rand = Random.Range(0, directions.Count); string picked = directions[rand]; directions.RemoveAt(rand); if (picked == "up") { TileBehavior upTile = myCharacter.occupiedTile.Up; if (upTile != null && upTile.tileType != WALL && !upTile.HasUnit()) { StartCoroutine(MoveInDirection(picked)); break; } } else if (picked == "left") { TileBehavior leftTile = myCharacter.occupiedTile.Left; if (leftTile != null && leftTile.tileType != WALL && !leftTile.HasUnit()) { StartCoroutine(MoveInDirection(picked)); break; } } else if (picked == "down") { TileBehavior downTile = myCharacter.occupiedTile.Down; if (downTile != null && downTile.tileType != WALL && !downTile.HasUnit()) { StartCoroutine(MoveInDirection(picked)); break; } } else if (picked == "right") { TileBehavior rightTile = myCharacter.occupiedTile.Right; if (rightTile != null && rightTile.tileType != WALL && !rightTile.HasUnit()) { StartCoroutine(MoveInDirection(picked)); break; } } } } }
void Update() { if (!GameManager.actionInProcess) { if (myCharacter.currentHealth <= 0) { // Load a new scene the player dies GameManager.Reset(); myCharacter.ResetHealth(); UIManager.singleton.Loading(); SceneManager.LoadScene(sceneName: "Game"); } if (inShop) { // no input works if you are in shop return; } /*else if (Input.GetKey(KeyCode.LeftShift)) { * if ((Input.GetKey(KeyCode.W) && Input.GetKeyDown(KeyCode.A)) || (Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.A))) { * Debug.Log("upleft"); * StartCoroutine(MoveUnitInDirection("upleft")); * } * if ((Input.GetKey(KeyCode.W) && Input.GetKeyDown(KeyCode.D)) || (Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.D))) { * Debug.Log("upright"); * StartCoroutine(MoveUnitInDirection("upright")); * } * if ((Input.GetKey(KeyCode.S) && Input.GetKeyDown(KeyCode.A)) || (Input.GetKeyDown(KeyCode.S) && Input.GetKey(KeyCode.A))) { * Debug.Log("downleft"); * StartCoroutine(MoveUnitInDirection("downleft")); * } * if ((Input.GetKey(KeyCode.S) && Input.GetKeyDown(KeyCode.D)) || (Input.GetKeyDown(KeyCode.S ) && Input.GetKey(KeyCode.D))) { * Debug.Log("downright"); * StartCoroutine(MoveUnitInDirection("downright")); * } * }*/ else if (Input.GetKey(KeyCode.LeftArrow)) { myCharacter.myDirection = Character.Direction.LEFT; Debug.Log(myCharacter.myDirection); myCharacter.setFlip(true); directionUI.SwitchDirection("left"); } else if (Input.GetKey(KeyCode.DownArrow)) { myCharacter.myDirection = Character.Direction.DOWN; Debug.Log(myCharacter.myDirection); directionUI.SwitchDirection("down"); } else if (Input.GetKey(KeyCode.RightArrow)) { myCharacter.myDirection = Character.Direction.RIGHT; Debug.Log(myCharacter.myDirection); myCharacter.setFlip(false); directionUI.SwitchDirection("right"); } else if (Input.GetKey(KeyCode.UpArrow)) { myCharacter.myDirection = Character.Direction.UP; Debug.Log(myCharacter.myDirection); directionUI.SwitchDirection("up"); } else if (Input.GetKeyDown(KeyCode.W)) { TileBehavior upTile = myCharacter.occupiedTile.Up; if (upTile != null && upTile.tileType != WALL && !upTile.HasUnit()) { StartCoroutine(MoveUnitInDirection("up")); } } else if (Input.GetKeyDown(KeyCode.A)) { TileBehavior leftTile = myCharacter.occupiedTile.Left; if (leftTile != null && leftTile.tileType != WALL && !leftTile.HasUnit()) { StartCoroutine(MoveUnitInDirection("left")); } } else if (Input.GetKeyDown(KeyCode.S)) { TileBehavior downTile = myCharacter.occupiedTile.Down; if (downTile != null && downTile.tileType != WALL && !downTile.HasUnit()) { StartCoroutine(MoveUnitInDirection("down")); } } else if (Input.GetKeyDown(KeyCode.D)) { TileBehavior rightTile = myCharacter.occupiedTile.Right; if (rightTile != null && rightTile.tileType != WALL && !rightTile.HasUnit()) { StartCoroutine(MoveUnitInDirection("right")); } } else if (Input.GetKeyDown(KeyCode.F)) { myCharacter.AttackEnemy(); GameManager.UpdateEnemies(); } else if (Input.GetKeyDown(KeyCode.Alpha1)) { myCharacter.Ability1(); GameManager.UpdateEnemies(); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { myCharacter.Ability2(); GameManager.UpdateEnemies(); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { myCharacter.Ability3(); GameManager.UpdateEnemies(); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { myCharacter.Ability4(); GameManager.UpdateEnemies(); } else if (Input.GetKeyDown(KeyCode.G)) // Save Character { Character new_char = myCharacter.saveCharacter(); saved_data.saveGame(new_char); } else if (Input.GetKeyDown(KeyCode.Alpha0)) { if (saved_data != null) { saved_data.saveGame(myCharacter); } else { Debug.Log("savedata should exist..."); } //Check if profile exists } } }