public override void Update(GameTime gametime) { switch (projectileState) { case PROJECTILE_STATE.STILL: this.Visible = false; explosion.Visible = false; break; // Using Lerp here could use target - pos and normalise for direction and then apply // Velocity case PROJECTILE_STATE.FIRING: this.Visible = true; PixelPosition = Vector2.Lerp(PixelPosition, Target, 0.02f * RocketVelocity); // rotate towards the Target this.angleOfRotation = TurnToFace(PixelPosition, Target, angleOfRotation, 1f); if (Vector2.Distance(PixelPosition, Target) < 2) { projectileState = PROJECTILE_STATE.EXPOLODING; } break; case PROJECTILE_STATE.EXPOLODING: explosion.DrawOrder = 2; explosion.PixelPosition = Target; explosion.Visible = true; break; } // if the explosion is visible then just play the animation and count the timer if (explosion.Visible) { explosion.Update(gametime); ExplosionTimer += gametime.ElapsedGameTime.Milliseconds; } // if the timer goes off the explosion is finished if (ExplosionTimer > ExplosionVisibleLimit) { explosion.Visible = false; ExplosionTimer = 0; projectileState = PROJECTILE_STATE.STILL; } base.Update(gametime); }
public override void Update(GameTime gametime) { switch (projectileState) { case PROJECTILE_STATE.STILL: this.Visible = false; explosion.Visible = false; explosionTime = TimeSpan.FromSeconds(2); break; // Using Lerp here could use target - pos and normalise for direction and then apply // Velocity case PROJECTILE_STATE.FIRING: this.Visible = true; //PixelPosition = Vector2.Lerp(PixelPosition, Target, 0.02f * RocketVelocity); PixelPosition += Target; // rotate towards the Target this.angleOfRotation = TurnToFace(PixelPosition, Target, angleOfRotation, 1f); if (Vector2.Distance(PixelPosition, Target) <= 2f) { //explosion.PixelPosition += new Vector2(PixelPosition.X, PixelPosition.Y); explosion.Visible = true; projectileState = PROJECTILE_STATE.EXPLODING; } break; case PROJECTILE_STATE.EXPLODING: explosion.Visible = true; explosion.PixelPosition = PixelPosition; //explosion.PixelPosition = explosionLocation; break; } if (projectileState == PROJECTILE_STATE.EXPLODING) { explosion.Update(gametime); explosionTime -= gametime.ElapsedGameTime; if (explosionTime <= TimeSpan.Zero) { explosion.Visible = false; projectileState = PROJECTILE_STATE.STILL; } } //// if the explosion is visible then just play the animation and count the timer //if (explosion != null) //{ // if (explosion.Visible) // { // explosion.Update(gametime); // ExplosionTimer += gametime.ElapsedGameTime.Milliseconds; // } //} //// if the timer goes off the explosion is finished. //if (ExplosionTimer > ExplosionVisibleLimit) //{ // //explosion.Visible = false; // ExplosionTimer = 0; // projectileState = PROJECTILE_STATE.STILL; //} base.Update(gametime); }