/** * <summary>Executes the player's throwing attack.</summary> * * <param name="player">The attacking player.</param> * */ public void PlayerThrow(PlayerNumber.PlayerNum player) { if (CheckIfPlayerAttacking(player)) { return; } switch (player) { case PlayerNumber.PlayerNum.PlayerOne: app.view.players.playerOne.Throw(); break; case PlayerNumber.PlayerNum.PlayerTwo: app.view.players.playerTwo.Throw(); break; case PlayerNumber.PlayerNum.PlayerThree: app.view.players.playerThree.Throw(); break; case PlayerNumber.PlayerNum.PlayerFour: app.view.players.playerFour.Throw(); break; default: break; } }
/** * <summary>Get's the player data file for the player.</summary> * * <param name="player">The player whose data we need.</param> * * <returns>A reference to the player data script associated with the * player.</returns> */ private PlayerData GetPlayerData(PlayerNumber.PlayerNum player) { PlayerData playerData = null; switch (player) { case PlayerNumber.PlayerNum.PlayerOne: playerData = app.data.playerData.playerOne; break; case PlayerNumber.PlayerNum.PlayerTwo: playerData = app.data.playerData.playerTwo; break; case PlayerNumber.PlayerNum.PlayerThree: playerData = app.data.playerData.playerThree; break; case PlayerNumber.PlayerNum.PlayerFour: playerData = app.data.playerData.playerFour; break; default: break; } return(playerData); }
/** * <summary>Sends a message to the appropriate player to change their current sprite to match * their desired aiming direction.</summary> * * <param name="player">The player to be rotated.</param> * <param name="rotation">The direction of rotation, or aiming direction.</param> */ public void RotatePlayer(PlayerNumber.PlayerNum player, Vector2 rotation) { if (CheckIfPlayerAttacking(player)) { return; } switch (player) { case PlayerNumber.PlayerNum.PlayerOne: app.view.players.playerOne.Rotate(rotation); break; case PlayerNumber.PlayerNum.PlayerTwo: app.view.players.playerTwo.Rotate(rotation); break; case PlayerNumber.PlayerNum.PlayerThree: app.view.players.playerThree.Rotate(rotation); break; case PlayerNumber.PlayerNum.PlayerFour: app.view.players.playerFour.Rotate(rotation); break; default: break; } }
/** * <summary>Sends a message to the appropriate player to update their position * in the world based on the supplied value.</summary> * * <param name="player">The player to be moved.</param> * <param name="movement">The direction of movement.</param> */ public void MovePlayer(PlayerNumber.PlayerNum player, Vector2 movement) { if (CheckIfPlayerAttacking(player)) { return; } switch (player) { case PlayerNumber.PlayerNum.PlayerOne: //Move player one app.view.players.playerOne.Movement(movement); break; case PlayerNumber.PlayerNum.PlayerTwo: //Move player two app.view.players.playerTwo.Movement(movement); break; case PlayerNumber.PlayerNum.PlayerThree: //Move player three app.view.players.playerThree.Movement(movement); break; case PlayerNumber.PlayerNum.PlayerFour: //Move player four app.view.players.playerFour.Movement(movement); break; default: break; } }
/** * <summary>Executes the player's melee attack and triggers the attack animation * on screen.</summary> * * <param name="player">The attacking player.</param> */ public void PlayerMeleeAttack(PlayerNumber.PlayerNum player) { if (CheckIfPlayerAttacking(player)) { return; } switch (player) { case PlayerNumber.PlayerNum.PlayerOne: app.data.playerData.playerOne.IsAttacking = true; app.view.players.playerOne.MeleeAttack(); break; case PlayerNumber.PlayerNum.PlayerTwo: app.data.playerData.playerTwo.IsAttacking = true; app.view.players.playerTwo.MeleeAttack(); break; case PlayerNumber.PlayerNum.PlayerThree: app.data.playerData.playerThree.IsAttacking = true; app.view.players.playerThree.MeleeAttack(); break; case PlayerNumber.PlayerNum.PlayerFour: app.data.playerData.playerFour.IsAttacking = true; app.view.players.playerFour.MeleeAttack(); break; default: break; } StartCoroutine(Attack(player)); }
/** * <summary>Deals damage to an enemy when a player weapon interacts * with them. Some enemies can only be killed by certain weapons. Necessary * player information that made the attack is automatically acquired.</summary> * * <param name="weapon">The player weapon game object.</param> * <param name="enemy">The enemy game object.</param> */ private void OnWeaponWithEnemy(GameObject weapon, GameObject enemy) { Element weaponScript = weapon.GetComponent <Element>(); EnemyData enemyData = GetEnemyData(enemy); EnemyView enemyView = enemy.GetComponent <EnemyView>(); PlayerData playerData = null; PlayerNumber.PlayerNum player = PlayerNumber.PlayerNum.PlayerOne; if (weaponScript is MeleeWeaponView) { //Handle all logic for melee weapons here /** Notes * 1. Ghost's and Death can't be killed with melee attacks */ MeleeWeaponView playerWeapon = weapon.GetComponent <MeleeWeaponView>(); player = playerWeapon.BelongsTo; playerData = GetPlayerData(player); if (enemy.layer == 16 || (enemy.layer >= 18 && enemy.layer <= enemyMaxLayer)) { enemyView.CurrentHealth -= playerData.Melee; } } else if (weaponScript is ProjectileView) { //Handle all logic for projectile weapons here //ProjectileInfo projectileInfo = app.data.projectiles.RetrieveProjectileInfo(weapon); //player = projectileInfo.Player; ProjectileView playerProjectile = weapon.GetComponent <ProjectileView>(); playerData = GetPlayerData(playerProjectile.BelongsTo); if (enemy.layer >= 16 && enemy.layer <= enemyMaxLayer) { enemyView.CurrentHealth -= playerData.Shot; } RemoveProjectile(weapon); } if (enemyView.CurrentHealth <= 0) { playerData.Score += enemyData.ScoreOnDeath; Destroy(enemy.gameObject); } UpdatePlayerHUDS(player); }
/** * <summary>Returns a vector 2 direction for determining where to place the player's * melee box when rotating the player's sprite.</summary> * * <param name="player">The player whose direction needs to be examined.</param> */ protected Vector2 GetMeleeBoxPosOnRotate(PlayerNumber.PlayerNum player) { PlayerData playerData = GetPlayerData(player); Vector2 newPos = Vector2.zero; switch (playerData.CurrentDirection) { case PlayerData.Direction.North: newPos = Vector2.up; break; case PlayerData.Direction.NorthEast: newPos = Vector2.one.normalized; break; case PlayerData.Direction.East: newPos = Vector2.right; break; case PlayerData.Direction.SouthEast: newPos = new Vector2(1f, -1f).normalized; break; case PlayerData.Direction.South: newPos = Vector2.down; break; case PlayerData.Direction.SouthWest: newPos = new Vector2(-1f, -1f).normalized; break; case PlayerData.Direction.West: newPos = Vector2.left; break; case PlayerData.Direction.NorthWest: newPos = new Vector2(-1f, 1f).normalized; break; default: break; } return(newPos); }
/** * <summary>Provides a rotation for the player's melee box when rotating the player. Will obtain * a reference to the player's data.</summary> * * <param name="player">The player whose melee box is being rotated.</param> * * <returns>A vector 3 detailing the player's melee box rotation.</returns> */ public Vector3 GetNewMeleeBoxRotation(PlayerNumber.PlayerNum player) { PlayerData playerData = GetPlayerData(player); Vector3 rotation = new Vector3(0f, 0f, 0f); switch (playerData.CurrentDirection) { case PlayerData.Direction.North: rotation.z = 90f; break; case PlayerData.Direction.NorthEast: rotation.z = 45f; break; case PlayerData.Direction.East: rotation.z = 0f; break; case PlayerData.Direction.SouthEast: rotation.z = 315f; break; case PlayerData.Direction.South: rotation.z = 270f; break; case PlayerData.Direction.SouthWest: rotation.z = 215f; break; case PlayerData.Direction.West: rotation.z = 180f; break; case PlayerData.Direction.NorthWest: rotation.z = 135f; break; default: break; } return(rotation); }
/** * <summary>Private co-routine that carries out the player's melee attack * and then resets their sprites to default. Receives references to the * PlayerData and PlayerView internally.</summary> * * <param name="player">The attacking player.</param> * */ IEnumerator Attack(PlayerNumber.PlayerNum player) { PlayerData playerData = null; PlayerView playerView = null; switch (player) { case PlayerNumber.PlayerNum.PlayerOne: playerData = app.data.playerData.playerOne; playerView = app.view.players.playerOne; break; case PlayerNumber.PlayerNum.PlayerTwo: playerData = app.data.playerData.playerTwo; playerView = app.view.players.playerTwo; break; case PlayerNumber.PlayerNum.PlayerThree: playerData = app.data.playerData.playerThree; playerView = app.view.players.playerThree; break; case PlayerNumber.PlayerNum.PlayerFour: playerData = app.data.playerData.playerFour; playerView = app.view.players.playerFour; break; default: break; } playerView.meleeBox.SetActive(true); yield return(new WaitForSeconds(0.2f)); playerView.SetCurrentDirectionSprite(playerData, playerView); playerData.IsAttacking = false; playerView.meleeBox.SetActive(false); }
/** * <summary>Uses a potion that the player currently holds. In current state * potions will kill all enemies on screen. Will reduce number of potions * held by player by one.</summary> * * <param name="player">The player using a potion.</param> */ public void UsePotion(PlayerNumber.PlayerNum player) { switch (player) { case PlayerNumber.PlayerNum.PlayerOne: if (app.data.playerData.playerOne.Potions != 0) { app.data.objectsInView.KillAllEnemies(); app.data.playerData.playerOne.Potions--; } break; case PlayerNumber.PlayerNum.PlayerTwo: if (app.data.playerData.playerTwo.Potions != 0) { app.data.objectsInView.KillAllEnemies(); app.data.playerData.playerTwo.Potions--; } break; case PlayerNumber.PlayerNum.PlayerThree: if (app.data.playerData.playerThree.Potions != 0) { app.data.objectsInView.KillAllEnemies(); app.data.playerData.playerThree.Potions--; } break; case PlayerNumber.PlayerNum.PlayerFour: if (app.data.playerData.playerFour.Potions != 0) { app.data.objectsInView.KillAllEnemies(); app.data.playerData.playerFour.Potions--; } break; default: break; } }
/** * <summary>Private helper function which checks if player is already attacking * to limit the player to one attack at a time.</summary> * * <param name="player">The player that needs to be evaluated.</param> */ private bool CheckIfPlayerAttacking(PlayerNumber.PlayerNum player) { switch (player) { case PlayerNumber.PlayerNum.PlayerOne: if (app.data.playerData.playerOne.IsAttacking) { return(true); } break; case PlayerNumber.PlayerNum.PlayerTwo: if (app.data.playerData.playerTwo.IsAttacking) { return(true); } break; case PlayerNumber.PlayerNum.PlayerThree: if (app.data.playerData.playerThree.IsAttacking) { return(true); } break; case PlayerNumber.PlayerNum.PlayerFour: if (app.data.playerData.playerFour.IsAttacking) { return(true); } break; default: break; } return(false); }
/** * <summary>Sends a message to the UI to update the player's health.</summary> * * <param name="player">The player whose health needs to be updated.</param> */ public void UpdatePlayerHealth(PlayerNumber.PlayerNum player) { switch (player) { case PlayerNumber.PlayerNum.PlayerOne: app.view.ui.UpdatePlayerOneHealth(); break; case PlayerNumber.PlayerNum.PlayerTwo: app.view.ui.UpdatePlayerTwoHealth(); break; case PlayerNumber.PlayerNum.PlayerThree: app.view.ui.UpdatePlayerThreeHealth(); break; case PlayerNumber.PlayerNum.PlayerFour: app.view.ui.UpdatePlayerFourHealth(); break; default: break; } }
/** * <summary>Sends a message to the UI to update the player's score.</summary> * * <param name="player">The player whose score needs to be updated.</param> * */ public void UpdatePlayerScore(PlayerNumber.PlayerNum player) { switch (player) { case PlayerNumber.PlayerNum.PlayerOne: app.view.ui.UpdatePlayerOneScore(); break; case PlayerNumber.PlayerNum.PlayerTwo: app.view.ui.UpdatePlayerTwoScore(); break; case PlayerNumber.PlayerNum.PlayerThree: app.view.ui.UpdatePlayerThreeScore(); break; case PlayerNumber.PlayerNum.PlayerFour: app.view.ui.UpdatePlayerFourScore(); break; default: break; } }
/** * <summary>Sends a message to the input controller to use a potion the player holds.</summary> * * <param name="player">The player using the potion.</param> */ protected void OnPotion(PlayerNumber.PlayerNum player) { app.controller.input.UsePotion(player); }
/** * <summary>Sends a message to the input controller to execute a player melee attack.</summary> * * <param name="player">The attacking player.</param> */ protected void OnMeleeAttack(PlayerNumber.PlayerNum player) { app.controller.input.PlayerMeleeAttack(player); }
/** * <summary>Sends a message to the input controller to execute a player throw attack.</summary> * * <param name="player">The attacking player.</param> */ protected void OnThrow(PlayerNumber.PlayerNum player) { app.controller.input.PlayerThrow(player); }
/** * <summary>Sends a message to the input controller to rotate the player.</summary> * * <param name="movement">The direction of rotation.</param> * <param name="player">The player to rotate.</param> */ protected void OnRotate(PlayerNumber.PlayerNum player, Vector2 rotation) { app.controller.input.RotatePlayer(player, rotation); }
/** * <summary>Sends a message to the input controller to move the player.</summary> * * <param name="movement">The direction of movement.</param> * <param name="player">The player to move.</param> */ protected void OnMovement(PlayerNumber.PlayerNum player, Vector2 movement) { app.controller.input.MovePlayer(player, movement); }
/** * <summary>Updates the health and score text information * in the HUD for the player.</summary> * * <param name="player">The player whose info we want * to update on screen.</param> * */ private void UpdatePlayerHUDS(PlayerNumber.PlayerNum player) { app.controller.ui.UpdatePlayerHealth(player); app.controller.ui.UpdatePlayerScore(player); }
/** * <summary>Get's the sprite that is relevant to the player's current * facing direction.</summary> * * <param name="player">The player that rotated.</param> * <param name="rotation">The vector2 that represents the direction of rotation.</param> */ protected Sprite GetPlayerSpriteOnRotation(PlayerNumber.PlayerNum player, Vector2 rotation) { Sprite playerSprite = null; PlayerData playerData = GetPlayerData(player); if (rotation.x > SpriteChangeThreshold) { //Moving East if (rotation.y > SpriteChangeThreshold) { //Moving NorthEast if (playerData.CurrentDirection == PlayerData.Direction.NorthEast) { return(null); } playerData.CurrentDirection = PlayerData.Direction.NorthEast; playerSprite = playerData.NorthEastSprite; } else if (rotation.y < -SpriteChangeThreshold) { //Moving SouthEast if (playerData.CurrentDirection == PlayerData.Direction.SouthEast) { return(null); } playerData.CurrentDirection = PlayerData.Direction.SouthEast; playerSprite = playerData.SouthEastSprite; } else { //Moving East if (playerData.CurrentDirection == PlayerData.Direction.East) { return(null); } playerData.CurrentDirection = PlayerData.Direction.East; playerSprite = playerData.EastSprite; } } else if (rotation.x < -SpriteChangeThreshold) { //moving west if (rotation.y > SpriteChangeThreshold) { //Moving NorthWest if (playerData.CurrentDirection == PlayerData.Direction.NorthWest) { return(null); } playerData.CurrentDirection = PlayerData.Direction.NorthWest; playerSprite = playerData.NorthWestSprite; } else if (rotation.y < -SpriteChangeThreshold) { //Moving SouthWest if (playerData.CurrentDirection == PlayerData.Direction.SouthWest) { return(null); } playerData.CurrentDirection = PlayerData.Direction.SouthWest; playerSprite = playerData.SouthWestSprite; } else { //Moving West if (playerData.CurrentDirection == PlayerData.Direction.West) { return(null); } playerData.CurrentDirection = PlayerData.Direction.West; playerSprite = playerData.WestSprite; } } else if (Mathf.Abs(rotation.y) > SpriteChangeThreshold) { //Moving north or south if (rotation.y > 0f) { //Moving North if (playerData.CurrentDirection == PlayerData.Direction.North) { return(null); } playerData.CurrentDirection = PlayerData.Direction.North; playerSprite = playerData.NorthSprite; } else { //Moving South if (playerData.CurrentDirection == PlayerData.Direction.South) { return(null); } playerData.CurrentDirection = PlayerData.Direction.South; playerSprite = playerData.SouthSprite; } } return(playerSprite); }
/** * <summary>Returns a vector 2 to apply to the player's projectile to throw it in the * appropriate direction.</summary> * * <param name="player">The player whose direction needs to be evaluated.</param> * * <returns>A vector 2 describing the projectiles direction of movement.</returns> */ protected Vector2 GetThrowVector(PlayerNumber.PlayerNum player) { Vector2 throwDirection = Vector2.zero; PlayerData.Direction temp = PlayerData.Direction.North; switch (player) { case PlayerNumber.PlayerNum.PlayerOne: temp = app.data.playerData.playerOne.CurrentDirection; break; case PlayerNumber.PlayerNum.PlayerTwo: temp = app.data.playerData.playerTwo.CurrentDirection; break; case PlayerNumber.PlayerNum.PlayerThree: temp = app.data.playerData.playerThree.CurrentDirection; break; case PlayerNumber.PlayerNum.PlayerFour: temp = app.data.playerData.playerFour.CurrentDirection; break; default: break; } switch (temp) { case PlayerData.Direction.North: throwDirection = Vector2.up; break; case PlayerData.Direction.NorthEast: throwDirection = new Vector2(1, 1).normalized; break; case PlayerData.Direction.East: throwDirection = Vector2.right; break; case PlayerData.Direction.SouthEast: throwDirection = new Vector2(1, -1).normalized; break; case PlayerData.Direction.South: throwDirection = Vector2.down; break; case PlayerData.Direction.SouthWest: throwDirection = new Vector2(-1, -1).normalized; break; case PlayerData.Direction.West: throwDirection = Vector2.left; break; case PlayerData.Direction.NorthWest: throwDirection = new Vector2(-1, 1).normalized; break; } return(throwDirection); }