//---------------------------------Special4---------------------------------// //Shoot a bomb bullet void GW_Special4() { //Update the force GW_BulletForce = new Vector2(100.0f, 0.0f); //Don't play the after images GW_ParticleSystem.Stop(); E_PlayerPosition = E_FindPlayer.transform.position; //Play shooting animation and turn off iframes GW_Shooting = true; E_Animator.SetBool("EGW_Shooting", GW_Shooting); GW_iFrames = false; //Update bullet instantiation position based on which direction the enemy is facing if (GW_BulletDirection == 1) { GW_BulletPos = new Vector2(gameObject.transform.position.x + 0.4f, gameObject.transform.position.y + 0.3f); } else { GW_BulletPos = new Vector2(gameObject.transform.position.x - 0.4f, gameObject.transform.position.y + 0.3f); } GW_FollowPlayerY(); GW_Shoot(GW_BulletForce, 6, GW_BulletBomb, E_State.Patrolling, 0.0f, 0.0f); }
//---------------------------------Special2---------------------------------// //Stay in place and shoot six homing bulllets private void GW_Special2() { GW_BulletForce = new Vector2(0.0f, 0.0f); //Don't play the after images GW_ParticleSystem.Stop(); //Instantiate crosshair if (!GW_InstantiatedCrossHair) { Instantiate(GW_Crosshair, gameObject.transform.position, gameObject.transform.rotation); GW_InstantiatedCrossHair = true; } //Play shooting animation and turn off iframes GW_Shooting = true; E_Animator.SetBool("EGW_Shooting", GW_Shooting); GW_iFrames = false; //Update bullet instantiation position based on which direction the enemy is facing if (GW_BulletDirection == 1) { GW_BulletPos = new Vector2(gameObject.transform.position.x + 0.4f, GW_BulletPos.y); } else { GW_BulletPos = new Vector2(gameObject.transform.position.x - 0.4f, GW_BulletPos.y); } GW_Shoot(GW_BulletForce, 6, GW_BulletHoming, E_State.Patrolling, 0.0f, 0.3f); }
//---------------------------------Patrolling---------------------------------// //Look for the player and if close go attacking private void GW_Patrolling() { GW_ParticleSystem.Stop(); E_PlayerPosition = E_FindPlayer.transform.position; E_DistanceFromPlayer = new Vector2(E_PlayerPosition.x - this.gameObject.transform.position.x, E_PlayerPosition.y - this.gameObject.transform.position.y); if (Mathf.Abs(E_DistanceFromPlayer.x) <= 8.0f) //&& Mathf.Abs(E_DistanceFromPlayer.y) <= 5.0f) { //Player is close enough, start shooting E_CurrentState = E_State.Attacking; } else { //Reset everything E_CurrentState = E_State.Patrolling; GW_Shooting = false; E_Animator.SetBool("EGW_Shooting", GW_Shooting); GW_HasShot = false; E_Animator.SetBool("EGW_HasShot", GW_HasShot); GW_BulletInstantiationTimer = 0.47f; GW_BetweenShotsTimer = 0.5f; GW_ShotsCount = 0; GW_InstantiatedCrossHair = false; } }
private void GW_Shoot(Vector2 Force, int BulletCount, GameObject BulletToInstantiate, E_State NextState, float OffsetX, float OffsetY) { //If we are in attacking state, start shooting while alternating between shooting and between shots animations if (GW_Shooting && !GW_HasShot) { //Fire rate timer if (GW_BulletInstantiationTimer <= 0.0f) { GW_InstaBullet = (GameObject)Instantiate(BulletToInstantiate, GW_BulletPos, transform.rotation); GW_InstaBullet.GetComponent <Rigidbody2D>().AddRelativeForce(Force * GW_BulletDirection); GW_InstaBullet.transform.localScale = gameObject.transform.localScale; GW_ShotsCount++; GW_HasShot = true; GW_BulletInstantiationTimer = 0.47f; GW_Shooting = false; GW_BulletPos = new Vector2(GW_BulletPos.x + OffsetX, GW_BulletPos.y + OffsetY); } else { GW_BulletInstantiationTimer -= Time.deltaTime; } } //Give 0.5f delay between each shot enough for the between shots animation to play if (GW_HasShot) { if (GW_BetweenShotsTimer >= 0.0f) { GW_BetweenShotsTimer -= Time.deltaTime; } else { GW_HasShot = false; E_Animator.SetBool("EGW_HasShot", GW_HasShot); GW_BetweenShotsTimer = 0.5f; } } //If more than three shots have been shot, go into special state. if (GW_ShotsCount >= BulletCount) { E_CurrentState = NextState; GW_Special1Movement = false; GW_ShotsCount = 0; GW_Shooting = false; E_Animator.SetBool("EGW_Shooting", GW_Shooting); GW_HasShot = false; E_Animator.SetBool("EGW_HasShot", GW_HasShot); //Save the current position of the gunwoman GW_CurrentPos = gameObject.transform.position; GW_BulletInstantiationTimer = 0.47f; GW_BetweenShotsTimer = 0.5f; GW_InstantiatedCrossHair = false; } }
//---------------------------------Attacking---------------------------------// //Track the player's position and shoot private void GW_Attacking() { GW_BulletForce = new Vector2(350.0f, 0.0f); E_PlayerPosition = E_FindPlayer.transform.position; //Don't play the after images GW_ParticleSystem.Stop(); E_Animator.SetBool("EGW_Shooting", GW_Shooting); //Update bullet instantiation position based on which direction the Gun Woman is facing if (GW_BulletDirection == 1) { GW_BulletPos = new Vector2(gameObject.transform.position.x + 0.4f, gameObject.transform.position.y + 0.3f); } else { GW_BulletPos = new Vector2(gameObject.transform.position.x - 0.4f, gameObject.transform.position.y + 0.3f); } GW_FollowPlayerY(); GW_Shoot(GW_BulletForce, 8, GW_Bullet, E_State.Special1, 0.0f, 0.0f); }
// Update is called once per frame void Update() { //Debug.Log(GW_BulletDirection); E_PlayerPosition = E_FindPlayer.transform.position; E_DistanceFromPlayer = new Vector2(E_PlayerPosition.x - this.gameObject.transform.position.x, E_PlayerPosition.y - this.gameObject.transform.position.y); //Determine which animation we're on E_Animator.SetBool("EGW_Shooting", GW_Shooting); E_Animator.SetBool("EGW_HasShot", GW_HasShot); if (E_CurrentState != E_State.Staggered) { if (E_CurrentState == E_State.Reloading) { GW_ReloadingPos = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 2.0f); if (GW_ReloadingTimer >= 0.0f) { if (!GW_HasReloading) { GW_InstaReloading = (GameObject)Instantiate(GW_Reloading, GW_ReloadingPos, new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)); GW_HasReloading = true; } GW_ReloadingTimer -= Time.deltaTime; } else { Destroy(GW_InstaReloading); GW_ReloadingTimer = 2.0f; GW_HasReloading = false; E_CurrentState = E_State.Patrolling; } } //Check if the enemy is not doing her special move else if (E_CurrentState != E_State.Special) { GW_ParticleSystem.Stop(); if (Mathf.Abs(E_DistanceFromPlayer.x) <= 8.0f) //&& Mathf.Abs(E_DistanceFromPlayer.y) <= 5.0f) { //Player is close enough, start shooting E_CurrentState = E_State.Attacking; } else { //If we go back to patrolling, reset everything E_CurrentState = E_State.Patrolling; GW_Shooting = false; GW_HasShot = false; GW_BulletInstantiationTimer = 0.4f; GW_BetweenShotsTimer = 0.3f; GW_ShotsCount = 0; } if (E_CurrentState == E_State.Attacking) { GW_Shooting = true; GW_BulletPos = new Vector2(gameObject.transform.position.x - 0.1f, gameObject.transform.position.y); //If we are in attacking state, start shooting while alternating between shooting and between shots animations if (GW_Shooting && !GW_HasShot) { if (GW_BulletInstantiationTimer <= 0.0f) { GW_InstaBullet = (GameObject)Instantiate(GW_Bullet, GW_BulletPos, transform.rotation); GW_InstaBullet.GetComponent <Rigidbody2D>().AddRelativeForce(GW_BulletForce * GW_BulletDirection); GW_InstaBullet.transform.localScale = gameObject.transform.localScale; GW_ShotsCount++; GW_HasShot = true; GW_BulletInstantiationTimer = 0.4f; } else { GW_BulletInstantiationTimer -= Time.deltaTime; } } //Give 0.3f delay between each shot if (GW_HasShot) { if (GW_BetweenShotsTimer >= 0.0f) { GW_BetweenShotsTimer -= Time.deltaTime; } else { GW_HasShot = false; GW_BetweenShotsTimer = 0.3f; } } //If more than three shots have been shot, go into special state. if (GW_ShotsCount >= 3) { E_CurrentState = E_State.Special; GW_ShotsCount = 0; GW_Shooting = false; GW_HasShot = false; GW_CurrentPos = gameObject.transform.position; } } } //In the special state, go up, then return to patrolling. The only reason we go back to this state is let the system calcualte the distance between //the enemy and the player again so that if the player is far away, the enemy will not get stuck in an attacking-special loop else { GW_ParticleSystem.Play(); if (GW_SpecialCount >= 3 && GW_GoneUp) { //Add the velocity based on which directions the enemy was facing when the scene was loaded E_RigidBody.velocity = new Vector2(-8.0f * GW_HoizontalSpecialDirection, 0.0f); //Shoot bullets vertically while moveing to the left GW_ShootVertically(GW_GoneUp); if (Mathf.Abs(gameObject.transform.position.x - GW_CurrentPos.x) >= 10.0f) { //Once the enemy has moved 10 units, stop moving and flip. E_RigidBody.velocity = new Vector2(0.0f, 0.0f); //flip Vector3 P_Scale = gameObject.transform.localScale; P_Scale.x *= -1; gameObject.transform.localScale = P_Scale; //flip bullet direction GW_BulletDirection *= -1; //Start reloading E_CurrentState = E_State.Reloading; GW_SpecialCount = 0; } } else if (GW_SpecialCount >= 3 && !GW_GoneUp) { E_RigidBody.velocity = new Vector2(8.0f * GW_HoizontalSpecialDirection, 0.0f); GW_ShootVertically(GW_GoneUp); if (Mathf.Abs(gameObject.transform.position.x - GW_CurrentPos.x) >= 10.0f) { E_RigidBody.velocity = new Vector2(0.0f, 0.0f); Vector3 P_Scale = gameObject.transform.localScale; P_Scale.x *= -1; gameObject.transform.localScale = P_Scale; GW_BulletDirection *= -1; E_CurrentState = E_State.Reloading; GW_SpecialCount = 0; } } else if (!GW_GoneUp) { E_RigidBody.velocity = new Vector2(0.0f, 8.0f); if (Mathf.Abs(gameObject.transform.position.y - GW_CurrentPos.y) >= 4.0f) { E_RigidBody.velocity = new Vector2(0.0f, 0.0f); GW_GoneUp = true; E_CurrentState = E_State.Patrolling; GW_SpecialCount++; } } else { E_RigidBody.velocity = new Vector2(0.0f, -8.0f); if (Mathf.Abs(gameObject.transform.position.y - GW_CurrentPos.y) >= 4.0f) { E_RigidBody.velocity = new Vector2(0.0f, 0.0f); GW_GoneUp = false; E_CurrentState = E_State.Patrolling; GW_SpecialCount++; } } } } else { if (E_StaggeredTimer > 0.0f) { E_StaggeredTimer -= Time.deltaTime; } else { E_Animator.enabled = true; E_CurrentState = E_PreviousState; E_SpriteRenderer.color = Color.white; E_StaggeredTimer = 0.05f; } } }