public void DrawExplosion(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (explosionTime > 0.3f) { CurrentState = State.DEAD; } float circleRadius; float f = 1f - explosionTime * 3.33f; float k; if (explosionTime < 0.1f) { circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime; k = 1; } else { circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 200f; k = f + 0.3f; } // 0.1 = 5 float blastRadius = (sprite.Width / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f)); Color blastColor = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * f * 1.5f, Constans.MAIN_EXPLOSION_COLOR.G / 255f * f * 1.5f, Constans.MAIN_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f); line.ClearVectors(); line.CreateCircle(blastRadius, 20); Vector2 corner = CalculateScreenPosition(); float blastX = corner.X + sprite.Width / 2f; float blastY = corner.Y + sprite.Height / 2f; line.Colour = blastColor; line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY)); if (circleRadius >= 0) { corner.X += sprite.Width / 2f; corner.Y += sprite.Height / 2f; corner.X -= circleRadius; corner.Y -= circleRadius; Color color = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * k, Constans.MAIN_EXPLOSION_COLOR.G * k / 255f, Constans.MAIN_EXPLOSION_COLOR.B * k / 255f, k); spriteBatch.Draw(circle, new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2), color); } }
public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { if (explosionTime < 0) { return; } if (shouldPlaySound) { SoundPlayer.Instance.PlaySound("explosion1"); shouldPlaySound = false; } if (explosionTime > 0.3f || CurrentState.Equals(State.EXPLODED)) { CurrentState = State.EXPLODED; return; } float circleRadius; float f = 1f - explosionTime * 3.33f; float k; if (explosionTime < 0.1f) { circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime; k = 1; } else { circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 200f; k = f + 0.3f; } // 0.1 = 5 float blastRadius = (spriteWidth / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f)); Color blastColor = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * f * 1.5f, Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * f * 1.5f, Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f); line.ClearVectors(); line.CreateCircle(blastRadius, 100); Vector2 corner = ScreenUtils.TranslateToScreenCoordinates(position); float blastX = corner.X /*- spriteWidth / 2f*/; float blastY = corner.Y /* - spriteWidth / 2f*/; line.Colour = blastColor; line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY)); if (circleRadius >= 0) { corner.X -= circleRadius; corner.Y -= circleRadius; Color color = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * k, Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * k, Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * k, k); spriteBatch.Draw(circle, new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2), color); } }