// Update is called once per frame //public VoidProjectile[] private void FixedUpdate() { Astronaut plr = Astronaut.TheAstronaut; if (Alive && !isStunned()) { if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling)) { Vector3 dif = (plr.transform.position - this.transform.position); if (dif.magnitude < 10f) { bool los = (Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" })).collider == null); if (Existence >= 1f) { //create some orbs over time //MyVoidField.Activate if (EyeOpen) { MoveDirection = (dif.normalized * .5f) * (1f + (2f * Astronaut.AggressionLevelF)); if ((Time.time - AppearTime) >= 4f) { //Debug.Log("Want to fade"); fadeOut(); } } } else { MoveDirection = new Vector3(); if (!los) { if (Existence > 0f) { } } else { if ((Time.time - DisappearTime) >= (2f * (1f - Astronaut.AggressionLevelF))) { if (Existence == 0f) { stealthTeleport(); fadeIn(); } } } } //LookDirection = (int)((dif.x != 0) ? Mathf.Sign(dif.x) : LookDirection); } } } else { MoveDirection = new Vector3(); } if (Alive) { MyCollider.enabled = (Existence > 0f); MySpriteRenderer.sprite = ((EyeOpen && (Existence >= 1f)) ? EyeOpenSprite : EyeClosedSprite); if (EyeOpen || Fading) { MySpriteRenderer.color = new Color(MySpriteRenderer.color.r, MySpriteRenderer.color.g, MySpriteRenderer.color.b, Existence); } else { } if (Fading) { if (FadingIn) { Existence = Mathf.Clamp01(Existence + (Time.fixedDeltaTime * 1f)); if (Existence >= 1f) { if (Astronaut.AggressionLevel > 0) { MyVoidField.Activate(); } EyeOpen = true; Fading = false; AppearTime = Time.time; } } else { Existence = Mathf.Clamp01(Existence - (Time.fixedDeltaTime * 1f)); if (Existence <= 0f) { Fading = false; DisappearTime = Time.time; fadefinishtime = Time.time; } //Dispose of the Projectiles since we're fading out for (int i = 0; i < MyOrbittingProjectiles.Length; i++) { if (MyOrbittingProjectiles[i] != null) { MyOrbittingProjectiles[i].Disposing = true; MyOrbittingProjectiles[i] = null; } } } } if (Existence > .5f) { if (!NegativeParticles.isPlaying) { NegativeParticles.Play(); } } else { if (NegativeParticles.isPlaying) { NegativeParticles.Stop(); } } if (Existence <= 0f) { MySpriteRenderer.enabled = false; //Dispose of the Projectiles since we're fading out if (isIncinerating()) { IncinerationTime = Time.time; } for (int i = 0; i < MyOrbittingProjectiles.Length; i++) { if (MyOrbittingProjectiles[i] != null) { MyOrbittingProjectiles[i].Disposing = true; MyOrbittingProjectiles[i] = null; } } } else { MySpriteRenderer.enabled = true; if (EyeOpen) { float sr = (1f / (OrbitSpawnRate * (1f + (2f * Astronaut.AggressionLevelF)) * 1f)); for (int i = 0; i < MyOrbittingProjectiles.Length; i++) { if (MyOrbittingProjectiles[i] != null) { MyOrbittingProjectiles[i].transform.position = getOrbitalPosition(i); } else { if (!isStunned()) { if (Time.time - lastProjectileFormTime > sr) { formProjectile(i); } } } } } else { for (int i = 0; i < MyOrbittingProjectiles.Length; i++) { if (MyOrbittingProjectiles[i] != null) { MyOrbittingProjectiles[i].Disposing = true; MyOrbittingProjectiles[i] = null; } } } } if (Alive) { MyRigidbody.velocity = new Vector3(MoveDirection.x, MoveDirection.y, 0f); OrbitalTime += Time.fixedDeltaTime; } else { if ((NegativeParticles) && (NegativeParticles.isPlaying)) { NegativeParticles.Stop(); } } } float sf = (1f + 1.5f * Astronaut.AggressionLevelF); SpeedFactor = Mathf.Lerp(SpeedFactor, sf, .5f); }
void FixedUpdate() { Astronaut plr = Astronaut.TheAstronaut; if (Alive && !isStunned()) { bool stateexpired = (Time.time >= (StateTime + StateDuration)); switch (MyState) { case State.None: { break; } case State.Waiting: { MyRigidbody.bodyType = RigidbodyType2D.Dynamic; /* * float sdif = (this.transform.position.x - StartPosition.x); * if (Mathf.Abs(sdif) > 2f) * { * float sig = Mathf.Sign(sdif); * GoLeftGoRight = (sig >= 0f); * } * MyRigidbody.AddForce(new Vector2(GoLeftGoRight ? -1f : 1f, 0f) * 3f); */ //if (stateexpired) //{ bool ch = false; if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling)) { Vector3 dif = (plr.transform.position - this.transform.position); if (((SurpriseFromLava && (Mathf.Abs(dif.x) < 3f)) || (!SurpriseFromLava)) && (dif.magnitude < 15f)) { RaycastHit2D rh = Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" })); if ((rh.distance <= 0f)) { //The player is present. Invade their space //Debug.Log("Approach"); //ParticleSystem s = ShootWindUpGlow; InvadeStartTime = Time.time; setState(State.Invading, 2f); ch = true; //Debug.Log("Visible"); } else { //Debug.Log("hiding..."); } } } if (!ch) { setState(State.Waiting, .5f); } //} //if (MyRigidbody.velocity.x != 0f) //{ //MySpriteRenderer.flipX = (Mathf.Sign(MyRigidbody.velocity.x) < 0f); //} break; } case State.Invading: { bool ch = false; MyRigidbody.bodyType = RigidbodyType2D.Dynamic; if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling)) { Vector3 dif = (plr.transform.position - this.transform.position); if (dif.magnitude < 10f) { RaycastHit2D rh = Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" })); LookDirection = (int)((dif.x != 0) ? Mathf.Sign(dif.x) : LookDirection); if ((Time.time - LastLoveDuckTime) >= LOVEDUCKINTERVAL) { LoveDuck = !LoveDuck; LastLoveDuckTime = Time.time; if (!SurpriseFromLava) { Vector3 crs = Vector3.Cross(dif, Vector3.forward); MoveDirection = (((dif) + (crs * LoveDuckOffset * (LoveDuck ? 1f : -1f))).normalized * (1f - FreezeFactor) * MoveSpeed); MySpriteRenderer.sortingOrder = 0; MyCollider.enabled = true; } else { if (surprising) { ch = true; setState(State.Waiting, .5f); SurpriseFromLava = false; MyCollider.enabled = true; } else { MoveDirection = new Vector3(0f, 1f * MoveSpeed * (1f - FreezeFactor) * 2f * (1f - FreezeFactor), 0f); surprising = true; Am.am.oneshot(Am.am.M.LavaPillarSpout); NegativeParticles.Play(); MyCollider.enabled = false; } } } else { if (SurpriseFromLava) { if (SurpriseParticles) { SurpriseParticles.Emit(5); } } } if (rh.distance <= 0f) { // //ParticleSystem s = ShootWindUpGlow; if (dif.magnitude < 5f) { NearTime = Mathf.Clamp01(NearTime + (Time.deltaTime / 1f)); } else { NearTime = Mathf.Clamp01(NearTime - (Time.deltaTime / 1f)); } if ((dif.magnitude < 2f) && ((NearTime >= 1f))) { ch = true; setState(State.Exploding, 2f - ((1f * Astronaut.AggressionLevelF))); } else { //MyRigidbody.AddForce(new Vector2(dif.normalized.x, dif.normalized.y) * 5f); //setState(); } //Debug.Log("Visible"); } else { setState(State.Invading, .5f); } } else { setState(State.Waiting, .5f); } } if (LookDirection != 0f) { MySpriteRenderer.flipX = (LookDirection > 0f); } if (!ch) { MyRigidbody.velocity = new Vector3(MoveDirection.x, MoveDirection.y, 0f); } if (stateexpired) { SurpriseFromLava = false; StateTime = Time.time; } break; } case State.Exploding: { //MyRigidbody.bodyType = RigidbodyType2D.Static; //MyRigidbody.velocity = new Vector2(); if (!PepperField.isPlaying) { PepperField.Play(); } if (!CoalescingEffect.isPlaying) { CoalescingEffect.Play(true); } bool ch = false; float f = ((Time.time - StateTime) / StateDuration); MySpriteRenderer.transform.localScale = originalspritesize * (1f + ((1f + (1f * Astronaut.AggressionLevelF)) * f)); ExplosionEffect.transform.localScale = (Vector3.one * (.25f + (.75f * f))); if ((!Telegraphed) && (((StateTime + StateDuration) - Time.time) < TelegraphDelay)) { Telegraphed = true; TelegraphEffect.Play(true); } if (stateexpired) { explode(); setState(State.Aftermathing, 1f); } break; } case State.Aftermathing: { MySpriteRenderer.transform.localScale = originalspritesize; if (stateexpired) { setState(State.Waiting, 1f); } break; } } } else { if (Alive) { if (PepperField.isPlaying) { PepperField.Stop(); } if (CoalescingEffect.isPlaying) { CoalescingEffect.Stop(true); } setState(State.Waiting, .5f); if (isStunned()) { MySpriteRenderer.transform.localScale = originalspritesize; } } } freezeStep(); }