override public bool checkState(Player player) { bool canAttack; // Is the player in a valid animation to attack canAttack = false; curPlayer = player; stateInfo = curPlayer.anim.GetCurrentAnimatorStateInfo(0); if (stateInfo.nameHash == flinchStateHash) { setFlinch(false); } else if (stateInfo.nameHash == idleStateHash || stateInfo.nameHash == runStateHash || stateInfo.nameHash == jumpStateHash) { attack = false; // Player is in a valid animation to attack running or idle canAttack = true; setBlock(false); setLaunch(false); } else if (stateInfo.nameHash == blockStateHash) { setBlock(true); } else if (!attack && contact() == true) { if (stateInfo.nameHash == grappleStateHash) { attack = grapple(); } else if (stateInfo.nameHash == lightAttackStateHash) { attack = lightAttack(); } else if (stateInfo.nameHash == specStateHash[0]) { attack = specialAttack(0); } else if (stateInfo.nameHash == heavyAttackStateHash) { attack = heavyAttack(); } } else if (attack == true && stateInfo.nameHash == grappleSuccessStateHash) { attack = false; hitFactory.MakeHitMarker(curPlayer.player.gameObject, 0); curPlayer.player.anim.SetTrigger("Launch"); curPlayer.player.playerState.sideForcePush(isFacingLeft(), 120); } return(attack || !canAttack); //Don't allow the player to attack again until the attack/move is finished }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { bool dealDamage = true; Player victim = (Player)other.gameObject.GetComponent(typeof(Player)); hitFactory.MakeHitMarker(other.gameObject, 3); //Do not deal damage if the player is blocking. if (victim.playerState.isBlock()) { //If the lightning bolt collides to the right of the player. if (this.transform.position.x > victim.transform.position.x) { if (!victim.playerState.isFacingLeft()) { dealDamage = false; } } //If the rock collides to the left of the player. else { if (victim.playerState.isFacingLeft()) { dealDamage = false; } } } //Otherwise, deal damage. if (dealDamage) { if (superLaser) { victim.playerState.setLaunch(true); victim.playerState.environmentDamage(damage); // Rocks deal 100DMG //Launch the player in the corresponding direction. if (this.transform.position.x > victim.transform.position.x) { victim.playerState.forceLaunch(true, 20); } else { victim.playerState.forceLaunch(false, 20); } } else { victim.playerState.setFlinch(true); victim.playerState.environmentDamage(damage); //Launch the player in the corresponding direction. if (this.transform.position.x > victim.transform.position.x) { victim.playerState.sideForcePush(true, 200); } else { victim.playerState.sideForcePush(false, 200); } Destroy(this.gameObject); } } } else if (other.gameObject.tag == "Platform") { } else { Destroy(this.gameObject); } }
// Called when a 2D object collides with another 2D object void OnCollisionEnter2D(Collision2D other) { bool dealDamage = true; bool inMotion = true; float horizVelocity = this.gameObject.rigidbody2D.velocity.x; if (horizVelocity > 3 || horizVelocity < -3) { inMotion = true; } else { inMotion = false; } if (other.gameObject.tag == "Player" && inMotion) { hitFactory.MakeHitMarker(other.gameObject, 4); victim = (Player)other.gameObject.GetComponent(typeof(Player)); this.gameObject.rigidbody2D.velocity = new Vector3(0, 0, 0); //Kill momentum. if (!hit) { //Do not deal damage if the player is blocking. if (victim.playerState.isBlock()) { //If the rock collides to the right of the player. if (this.transform.position.x > victim.transform.position.x) { if (!victim.playerState.isFacingLeft()) { dealDamage = false; } } //If the rock collides to the left of the player. else { if (victim.playerState.isFacingLeft()) { dealDamage = false; } } } //Otherwise, deal damage. if (dealDamage == true) { victim.playerState.setLaunch(true); victim.playerState.environmentDamage(100); // Rocks deal 100DMG //Launch the player in the corresponding direction. if (this.transform.position.x > victim.transform.position.x) { victim.playerState.forceLaunch(false, 200); } else { victim.playerState.forceLaunch(true, 200); } } hit = true; } playHit(); //The rock 'breaks' when it collides with a player. } //Rocks break each other. if (other.gameObject.tag == "Rock" && inMotion) { this.gameObject.rigidbody2D.velocity = new Vector3(0, 0, 0); //Kill momentum. hitFactory.MakeHitMarker(other.gameObject, 4); //Create a hit marker at the player's location. playHit(); //The rock 'breaks' when it collides with another rock. } }
override public bool checkState(Player player) { bool canAttack; // Is the player in a valid animation to attack canAttack = false; curPlayer = player; stateInfo = curPlayer.anim.GetCurrentAnimatorStateInfo(0); if (stateInfo.nameHash == flinchStateHash) { setFlinch(false); } else if (stateInfo.nameHash == idleStateHash || stateInfo.nameHash == runStateHash || stateInfo.nameHash == jumpStateHash) { attack = false; // Player is in a valid animation to attack running or idle canAttack = true; setBlock(false); setLaunch(false); } else if (stateInfo.nameHash == blockStateHash) { setBlock(true); } else if (!attack && contact() == true) { if (stateInfo.nameHash == grappleStateHash) { attack = grapple(); } else if (stateInfo.nameHash == lightAttackStateHash) { attack = lightAttack(); } else if (stateInfo.nameHash == specStateHash[4]) { attack = specialAttack(specState); } else if (stateInfo.nameHash == heavyAttackStateHash) { attack = heavyAttack(); } else if (stateInfo.nameHash == counterStateHash) { attack = counterAttack(); } } else if (attack == true && stateInfo.nameHash == grappleSuccessStateHash) { hitFactory.MakeHitMarker(curPlayer.player.gameObject, 0); attack = false; curPlayer.player.playerState.sideForcePush(isFacingLeft(), 200); } else { // Special attack for Noir can have 4 states of charging for (int i = 0; i < 4; i++) { if (stateInfo.nameHash == specStateHash[i]) { canAttack = false; specState = i + 1; } } } return(attack || !canAttack); //Don't allow the player to attack again until the attack/move is finished }