Added the Rainbow Party Cannon

This commit is contained in:
Dominic committed 2020-11-14 00:20:53 -06:00
1 parent fc43732ab4
commit cd3b3beb01
10 files changed
+1083

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
using CalamityMod.Projectiles.Magic;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Items.Weapons.Magic
{
public class RainbowPartyCannon : ModItem
{
public static readonly Color[] ColorSet = new Color[]
{
new Color(188, 192, 193), // White
new Color(157, 100, 183), // Purple
new Color(249, 166, 77), // Honey-ish orange
new Color(255, 105, 234), // Pink
new Color(67, 204, 219), // Sky blue
new Color(249, 245, 99), // Bright yellow
new Color(236, 168, 247), // Purplish pink
};
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Rainbow Party Cannon");
Tooltip.SetDefault("You should never see this lol");
}
public override void SetDefaults()
{
item.damage = 2200;
item.magic = true;
item.mana = 25;
item.width = 52;
item.height = 30;
item.crit += 4;
item.useTime = item.useAnimation = 24;
item.useStyle = ItemUseStyleID.HoldingOut;
item.noMelee = true;
item.knockBack = 3.5f;
item.value = CalamityGlobalItem.RarityHotPinkBuyPrice;
item.rare = 10;
item.Calamity().customRarity = CalamityRarity.Developer;
item.UseSound = SoundID.Item11;
item.autoReuse = true;
item.noUseGraphic = true;
item.shoot = ModContent.ProjectileType<RainbowPartyCannonProjectile>();
item.channel = true;
item.shootSpeed = 20f;
}
public static string DiscoHex => $"c/{(int)MathHelper.Lerp(156f, 255f, Main.DiscoR / 256f):X2}{108:X2}{251:X2}:";
public override void ModifyTooltips(List<TooltipLine> tooltips)
{
var tt2 = tooltips.FirstOrDefault(x => x.Name == "Tooltip0" && x.mod == "Terraria");
tt2.text = $"[" + DiscoHex + "Let the rainbow remind you that together we will always shine...]";
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

+100
View File
@@ -0,0 +1,100 @@
using CalamityMod.Items.Weapons.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class PartyComet : ModProjectile
{
public ref float Time => ref projectile.ai[0];
public const float FadeinTime = 40f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Comet");
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 12;
Main.projFrames[projectile.type] = 3;
}
public override void SetDefaults()
{
projectile.width = 72;
projectile.height = 72;
projectile.friendly = true;
projectile.penetrate = 1;
projectile.magic = true;
projectile.timeLeft = 300;
projectile.usesLocalNPCImmunity = true;
projectile.alpha = 255;
projectile.localNPCHitCooldown = 16;
}
public override void AI()
{
Time++;
projectile.Opacity = Utils.InverseLerp(0f, 20f, Time, true);
projectile.velocity = projectile.velocity.RotatedBy(Math.Sin(Time / 30f) * 0.0125f);
projectile.rotation = projectile.velocity.ToRotation() - MathHelper.PiOver2;
projectile.frameCounter++;
if (projectile.frameCounter % 4 == 3)
projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type];
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D cometTexture = ModContent.GetTexture(Texture);
spriteBatch.Draw(cometTexture,
projectile.Center + Vector2.UnitY * projectile.gfxOffY - Main.screenPosition,
cometTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame),
Color.White * projectile.Opacity,
projectile.rotation,
cometTexture.Size() * 0.5f,
projectile.scale,
SpriteEffects.None,
0f);
return false;
}
public override void Kill(int timeLeft)
{
if (projectile.owner == Main.myPlayer)
{
// Generate pretty sparkles.
for (int i = 0; i < 18; i++)
{
Vector2 velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(9f, 20f);
Projectile.NewProjectile(projectile.Center, velocity, ModContent.ProjectileType<PartySparkle>(), projectile.damage, 1f, projectile.owner);
}
// And release a bunch of rockets.
Vector2 baseDirection = projectile.velocity.SafeNormalize(-Vector2.UnitY).RotatedBy(MathHelper.PiOver2 * Math.Sign(Math.Cos(projectile.velocity.ToRotation())));
for (int i = 0; i < (int)RainbowRocket.PartyCannonExplosionType.Count; i++)
{
Vector2 velocity = -projectile.velocity.SafeNormalize(-Vector2.UnitY);
velocity = velocity.RotatedBy(MathHelper.Lerp(-1.1f, 1.1f, i / (float)(int)RainbowRocket.PartyCannonExplosionType.Count));
velocity *= Main.rand.NextFloat(7f, 15f);
Projectile rocket = Projectile.NewProjectileDirect(projectile.Center, velocity, ModContent.ProjectileType<RainbowRocket>(), projectile.damage * 3, 1f, projectile.owner);
rocket.ai[1] = i;
}
}
if (!Main.dedServ)
{
for (int i = 0; i < 80; i++)
{
Dust dust = Dust.NewDustPerfect(projectile.Center, 263);
dust.color = CalamityUtils.MulticolorLerp((Main.rand.NextFloat(0.4f) + Main.GlobalTime * 0.4f) % 0.999f, RainbowPartyCannon.ColorSet);
dust.scale = Main.rand.NextFloat(0.6f, 0.9f);
dust.velocity = Vector2.UnitY.RotatedByRandom(MathHelper.TwoPi) * Main.rand.NextFloat(12f, 16f);
dust.noGravity = true;
}
}
Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/LargeWeaponFire").WithVolume(0.45f), projectile.Center);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

+120
View File
@@ -0,0 +1,120 @@
using CalamityMod.Items.Weapons.Magic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class PartySparkle : ModProjectile
{
public float Time
{
get => projectile.ai[0];
set => projectile.ai[0] = value;
}
public float ColorSpectrumHue
{
get => projectile.ai[1];
set => projectile.ai[1] = value;
}
public const int Lifetime = 90;
public const int FadeinTime = 18;
public const int FadeoutTime = 18;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Pretty Sparkle");
}
public override void SetDefaults()
{
projectile.width = 72;
projectile.height = 72;
projectile.friendly = true;
projectile.penetrate = -1;
projectile.tileCollide = false;
projectile.magic = true;
projectile.timeLeft = Lifetime;
projectile.usesLocalNPCImmunity = true;
projectile.localNPCHitCooldown = 10;
projectile.scale = 0.001f;
}
public override void AI()
{
if (Time == 1f)
{
projectile.scale = Main.rand.NextFloat(0.4f, 1.1f);
CalamityGlobalProjectile.ExpandHitboxBy(projectile, (int)(72 * projectile.scale));
ColorSpectrumHue = Main.rand.NextFloat(0f, 0.9999f);
projectile.netUpdate = true;
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
}
Time++;
projectile.velocity *= 0.96f;
projectile.rotation = projectile.rotation.AngleLerp(MathHelper.PiOver2, 0.085f);
ColorSpectrumHue = (ColorSpectrumHue + 0.333f / Lifetime) % 0.999f; // Go 33% across the color spectrum throughout the sparkle's life instead of using a static sprite.
projectile.Opacity = Utils.InverseLerp(0f, FadeinTime, Time, true) * Utils.InverseLerp(Lifetime, Lifetime - FadeoutTime, Time, true);
projectile.velocity = projectile.velocity.RotatedBy(Math.Sin(Time / 30f) * 0.0125f);
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Texture2D sparkleTexture = ModContent.GetTexture(Texture);
Color sparkleColor = CalamityUtils.MulticolorLerp(ColorSpectrumHue, RainbowPartyCannon.ColorSet) * projectile.Opacity * 0.5f;
sparkleColor.A = 0;
sparkleColor *= MathHelper.Lerp(1f, 1.5f, Utils.InverseLerp(Lifetime * 0.5f - 15f, Lifetime * 0.5f + 15f, Time, true));
Color orthogonalsparkleColor = Color.Lerp(sparkleColor, Color.White, 0.5f) * 0.5f;
Vector2 origin = sparkleTexture.Size() / 2f;
Vector2 sparkleScale = new Vector2(0.3f, 1f) * projectile.Opacity * projectile.scale;
Vector2 orthogonalsparkleScale = new Vector2(0.3f, 2f) * projectile.Opacity * projectile.scale;
spriteBatch.Draw(sparkleTexture,
projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY,
null,
sparkleColor,
MathHelper.PiOver2 + projectile.rotation,
origin,
orthogonalsparkleScale,
SpriteEffects.None,
0f);
spriteBatch.Draw(sparkleTexture,
projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY,
null,
sparkleColor,
projectile.rotation,
origin,
sparkleScale,
SpriteEffects.None,
0f);
spriteBatch.Draw(sparkleTexture,
projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY,
null,
orthogonalsparkleColor,
MathHelper.PiOver2 + projectile.rotation,
origin,
orthogonalsparkleScale * 0.6f,
SpriteEffects.None,
0f);
spriteBatch.Draw(sparkleTexture,
projectile.Center - Main.screenPosition + Vector2.UnitY * projectile.gfxOffY,
null,
orthogonalsparkleColor,
projectile.rotation,
origin,
sparkleScale * 0.6f,
SpriteEffects.None,
0f);
return false;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

@@ -0,0 +1,103 @@
using Microsoft.Xna.Framework;
using System;
using Terraria;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class RainbowPartyCannonProjectile : ModProjectile
{
public Player Owner => Main.player[projectile.owner];
public ref float Time => ref projectile.ai[0];
public const float ChargeDelay = 60f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Party Cannon");
}
public override void SetDefaults()
{
projectile.width = 92;
projectile.height = 66;
projectile.penetrate = -1;
projectile.magic = true;
projectile.tileCollide = false;
projectile.ignoreWater = true;
}
public override void AI()
{
Item heldItem = Owner.ActiveItem();
projectile.damage = (int)((heldItem?.damage ?? 0) * Owner.MagicDamage());
UpdatePlayerVisuals(Owner.Center);
bool stillUsingCannon = Owner.channel && !Owner.noItems && !Owner.CCed;
if (!stillUsingCannon)
{
projectile.Kill();
return;
}
if (Time > ChargeDelay && Time % heldItem.useTime == 0)
{
ConsumeManaAndFireProjectile(heldItem);
}
else if (Time <= ChargeDelay && !Main.dedServ)
{
if (Main.rand.NextBool(3))
{
Vector2 velocityDirection = projectile.velocity.RotatedByRandom(0.1f);
Vector2 shotOffset = velocityDirection * projectile.Size * 0.5f;
Dust.NewDustPerfect(projectile.Center + shotOffset, Main.rand.Next(139, 143), velocityDirection * Main.rand.NextFloat(5f, 9f));
}
}
Time++;
// Forces the cannon to disappear immediately if anything goes wrong.
projectile.timeLeft = 2;
}
public void ConsumeManaAndFireProjectile(Item heldItem)
{
if (Owner.whoAmI != Main.myPlayer)
return;
if (!Owner.CheckMana(heldItem.mana, true))
{
projectile.Kill();
return;
}
Main.PlaySound(heldItem.UseSound, projectile.Center);
Vector2 spawnPosition = projectile.Center + projectile.velocity * 150f;
Projectile.NewProjectile(spawnPosition, projectile.velocity.SafeNormalize(Vector2.Zero) * heldItem.shootSpeed, ModContent.ProjectileType<PartyComet>(), projectile.damage, projectile.knockBack, Owner.whoAmI);
}
public void UpdatePlayerVisuals(Vector2 center)
{
// Place the cannon directly into the player's hand at all times.
projectile.Center = center;
// Set the direction of the cannon if it hasn't been set yet.
if (projectile.velocity == Vector2.Zero || projectile.velocity.Length() != 1f)
projectile.velocity = (Main.MouseWorld - center).SafeNormalize(Vector2.UnitX * projectile.direction);
projectile.rotation = projectile.velocity.ToRotation();
projectile.direction = projectile.spriteDirection = (Math.Cos(projectile.rotation) > 0).ToDirectionInt();
// The crystal is a holdout projectile. Change the player's channel and direction values to reflect this.
Owner.ChangeDir(projectile.direction);
Owner.heldProj = projectile.whoAmI;
Owner.itemTime = 2;
Owner.itemAnimation = 2;
Owner.itemRotation = (projectile.velocity * projectile.direction).ToRotation();
if (projectile.spriteDirection == -1)
projectile.rotation += MathHelper.Pi;
}
public override bool CanDamage() => false;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

+700
View File
@@ -0,0 +1,700 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.Projectiles.Magic
{
public class RainbowRocket : ModProjectile
{
public enum PartyCannonExplosionType
{
Pink = 0,
Orange = 1,
Yellow = 2,
White = 3,
SkyBlue = 4,
Purple = 5,
PalePink = 6,
Count = 7
}
internal PrimitiveTrail TrailDrawer = null;
public ref float Time => ref projectile.ai[0];
public PartyCannonExplosionType RocketType
{
get => (PartyCannonExplosionType)(int)projectile.ai[1];
set => projectile.ai[1] = (int)value;
}
public const float SwerveAngle = 0.02f;
public const float SwerveAngleOffsetMax = 0.04f;
public const float SwerveTime = 60f;
public const float HomingAcceleration = 0.4f;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Rainbow Rocket");
Main.projFrames[projectile.type] = 3;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 20;
ProjectileID.Sets.TrailingMode[projectile.type] = 2;
}
public override void SetDefaults()
{
projectile.width = 28;
projectile.height = 52;
projectile.friendly = true;
projectile.penetrate = 1;
projectile.timeLeft = 180;
projectile.magic = true;
}
#region AI
public override void AI()
{
Time++;
Lighting.AddLight(projectile.Center, Main.hslToRgb((float)Math.Sin(Time / 20f) * 0.5f + 0.5f, 0.9f, 0.9f).ToVector3());
projectile.tileCollide = Time > 60f;
projectile.frameCounter++;
if (projectile.frameCounter % 4 == 3)
projectile.frame = (projectile.frame + 1) % Main.projFrames[projectile.type];
NPC potentialTarget = projectile.Center.ClosestNPCAt(2300f, true, true);
if (Time < SwerveTime)
DoMovement_IdleSwerveFly();
else if (potentialTarget != null)
DoMovement_FlyToTarget(potentialTarget);
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.PiOver2;
}
private void DoMovement_IdleSwerveFly()
{
float swerveAngleOffset = MathHelper.Lerp(-SwerveAngleOffsetMax, SwerveAngleOffsetMax, (int)RocketType / ((int)PartyCannonExplosionType.Count));
projectile.velocity = projectile.velocity.RotatedBy(swerveAngleOffset + SwerveAngle);
}
private void DoMovement_FlyToTarget(NPC target)
{
float angleToTarget = projectile.AngleTo(target.Center);
float angleOffset = MathHelper.WrapAngle(angleToTarget - projectile.velocity.ToRotation());
projectile.velocity = projectile.velocity.RotatedBy(MathHelper.Clamp(angleOffset, -0.2f, 0.2f));
projectile.velocity = projectile.velocity.SafeNormalize(-Vector2.UnitY) * (projectile.velocity.Length() + HomingAcceleration);
if (Vector2.Dot(projectile.velocity.SafeNormalize(Vector2.Zero), projectile.DirectionTo(target.Center)) < 0.75f)
projectile.velocity *= 0.75f;
}
#endregion
#region Draw Effects
internal Color GetRocketColor()
{
switch (RocketType)
{
case PartyCannonExplosionType.Pink:
return Color.Pink;
case PartyCannonExplosionType.Orange:
return Color.Orange;
case PartyCannonExplosionType.Yellow:
return Color.LightGoldenrodYellow * 0.8f;
case PartyCannonExplosionType.White:
return Color.LightGray;
case PartyCannonExplosionType.SkyBlue:
return Color.LightSkyBlue;
case PartyCannonExplosionType.Purple:
return Color.Magenta;
case PartyCannonExplosionType.PalePink:
return Color.Pink * 0.77f;
}
return Color.White;
}
internal Color ColorFunction(float completionRatio)
{
Color baseColor = Main.hslToRgb((projectile.identity * 0.33f + completionRatio + Main.GlobalTime * 2f) % 1f, 1f, 0.54f);
return Color.Lerp(GetRocketColor(), baseColor, MathHelper.Clamp(completionRatio * 0.8f, 0f, 1f)) * projectile.Opacity;
}
internal float WidthFunction(float completionRatio)
{
float width;
float maxWidthOutwardness = 8f;
if (completionRatio < 0.1f)
width = (float)Math.Sin(completionRatio / 0.1f * MathHelper.PiOver2) * maxWidthOutwardness + 0.1f;
else
width = MathHelper.Lerp(maxWidthOutwardness, 0f, Utils.InverseLerp(0.1f, 1f, completionRatio, true));
return width * projectile.Opacity;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
if (TrailDrawer is null)
TrailDrawer = new PrimitiveTrail(WidthFunction, ColorFunction);
TrailDrawer.Draw(projectile.oldPos, projectile.Size * 0.5f - Main.screenPosition + projectile.velocity, 65);
Texture2D rocketTexture = ModContent.GetTexture(Texture);
spriteBatch.Draw(rocketTexture,
projectile.Center - Main.screenPosition,
rocketTexture.Frame(1, Main.projFrames[projectile.type], 0, projectile.frame),
GetRocketColor(),
projectile.rotation,
rocketTexture.Size() * 0.5f,
projectile.scale,
SpriteEffects.None,
0f);
return false;
}
#endregion
#region Kill Effects
public override void Kill(int timeLeft)
{
if (projectile.owner == Main.myPlayer)
{
for (int i = 1; i < projectile.oldPos.Length; i++)
{
if (Main.rand.NextBool(3))
{
float offsetAngle = MathHelper.Lerp(-MathHelper.PiOver4, MathHelper.PiOver4, i / (float)projectile.oldPos.Length);
Vector2 spawnPosition = projectile.oldPos[i] + projectile.Size * 0.5f;
Vector2 spawnVelocity = (projectile.oldPos[i - 1] - projectile.oldPos[i]).SafeNormalize(Vector2.Zero);
spawnVelocity = spawnVelocity.RotatedBy(offsetAngle);
spawnVelocity *= Main.rand.NextFloat(12f, 18f);
Projectile.NewProjectile(spawnPosition, spawnVelocity, ModContent.ProjectileType<PartySparkle>(), projectile.damage, 2f, projectile.owner);
}
}
}
CalamityGlobalProjectile.ExpandHitboxBy(projectile, 350);
projectile.Damage();
Main.PlaySound(SoundID.Item14, projectile.Center);
// There's no need to spawn dust from the server.
if (Main.dedServ)
return;
switch (RocketType)
{
case PartyCannonExplosionType.Pink:
PinkMarkExplosionDust();
break;
case PartyCannonExplosionType.Orange:
OrangeMarkExplosionDust();
break;
case PartyCannonExplosionType.Yellow:
YellowMarkExplosionDust();
break;
case PartyCannonExplosionType.White:
WhiteMarkExplosionDust();
break;
case PartyCannonExplosionType.SkyBlue:
SkyBlueMarkExplosionDust();
break;
case PartyCannonExplosionType.Purple:
PurpleMarkExplosionDust();
break;
case PartyCannonExplosionType.PalePink:
PalePinkMarkExplosionDust();
break;
}
}
#endregion
#region Pink Mark
public void PinkMarkExplosionDust()
{
// Spawn the main balloon.
BalloonExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 15f), Color.Yellow);
// Spawn the two smaller balloons.
float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f) * -1f;
Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f;
offset += Vector2.UnitX * 40f;
BalloonExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), Color.DeepPink, absoluteOffsetAngle);
absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f);
offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f;
offset -= Vector2.UnitX * 40f;
BalloonExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), Color.DeepPink, absoluteOffsetAngle);
}
public void BalloonExplosionDust(Vector2 center, float petalBurstSpeed, Color balloonColor, float absoluteOffsetAngle = 0)
{
float explosionOffsetAngle = Main.rand.NextFloat(-0.3f, 0.3f) + absoluteOffsetAngle;
// Draw the balloon as a petal.
for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f))
{
Vector2 initialUnitVector = angle.ToRotationVector2();
float unitMultiplier = 2f + (1f + (float)Math.Cos(MathHelper.Pi + angle)); // This value is used to "squash" the circle to make it into a petal shape.
Vector2 velocity = initialUnitVector * unitMultiplier;
velocity.X *= 0.5f;
velocity = velocity.SafeNormalize(Vector2.Zero); // Turn the petal velocity into a unit vector again to make future speed calculations easier.
velocity = velocity.RotatedBy(MathHelper.PiOver2); // Flip the petal velocity. It's tilted to the side normally.
velocity = velocity.RotatedBy(explosionOffsetAngle); // Account for the explosion offset angle that was determined at the start.
Dust dust = Dust.NewDustPerfect(center, 261);
dust.velocity = velocity * petalBurstSpeed;
dust.noGravity = true;
dust.color = balloonColor;
dust.fadeIn = 1.5f;
}
// Draw the string below the petal, giving it the appearance of a balloon.
StringExplosionDust(center, petalBurstSpeed, explosionOffsetAngle);
}
public void StringExplosionDust(Vector2 center, float petalBurstSpeed, float offsetAngle)
{
int evaluationPoints = 40;
// When mapped out, these points give a rough string, which when used with a bezier curve, can be smoothened out to make it look like a real string.
Vector2[] bezierControlPoints = new Vector2[]
{
new Vector2(0f, 40f),
new Vector2(20f, 76f),
new Vector2(-16f, 108f),
new Vector2(-20f, 146f),
new Vector2(-14f, 180f),
new Vector2(10f, 214f)
};
BezierCurve bezierCurve = new BezierCurve(bezierControlPoints);
for (int i = 0; i < evaluationPoints; i++)
{
Dust dust = Dust.NewDustPerfect(center, 261);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle) + Vector2.UnitY * petalBurstSpeed * 2f;
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.color = Color.White;
dust.fadeIn = 1.5f;
}
}
#endregion
#region Orange Mark
public void OrangeMarkExplosionDust()
{
// Spawn the main apple.
AppleExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 15f));
// Spawn two other apples to the side.
float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f) * -1f;
Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f;
offset += Vector2.UnitX * 70f;
AppleExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), absoluteOffsetAngle);
absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f);
offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f;
offset -= Vector2.UnitX * 70f;
AppleExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f), absoluteOffsetAngle);
}
public void AppleExplosionDust(Vector2 center, float appleBurstSpeed, float offsetAngle = 0f)
{
for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f))
{
Vector2 initialUnitVector = angle.ToRotationVector2();
float cosineValue = (float)Math.Cos(angle);
Vector2 velocity = initialUnitVector;
velocity = velocity.SafeNormalize(Vector2.Zero); // Turn the petal velocity into a unit vector again to make future speed calculations easier.
velocity.X *= 1.333f;
// Squash the circle to the shape of an apple.
if (Math.Abs(cosineValue) < 0.35f)
{
velocity.Y *= MathHelper.Lerp(0.9f, 1f, Math.Abs(cosineValue) / 0.35f);
// Squash the upper part slightly more than the lower part.
if (Math.Sign(cosineValue) == 1f)
{
velocity.Y *= 0.85f;
}
}
velocity = velocity.RotatedBy(offsetAngle); // Account for the explosion offset angle that was determined at the start.
Dust dust = Dust.NewDustPerfect(center, 261);
dust.velocity = velocity * appleBurstSpeed;
dust.noGravity = true;
dust.color = Color.Orange;
dust.fadeIn = 1.5f;
}
AppleLeafExplosionDust(center + new Vector2(0f, -54).RotatedBy(offsetAngle), offsetAngle);
}
public void AppleLeafExplosionDust(Vector2 center, float offsetAngle)
{
int evaluationPoints = 40;
// When mapped out, these points give a rough apple stem shape.
Vector2[] bezierControlPoints = new Vector2[]
{
new Vector2(0f, 0f),
new Vector2(-20f, -26f),
new Vector2(-26f, -46f),
new Vector2(-30f, -60f),
new Vector2(-24f, -70f),
new Vector2(-10f, -40f),
new Vector2(0f, 0f),
};
BezierCurve bezierCurve = new BezierCurve(bezierControlPoints);
for (int i = 0; i < evaluationPoints; i++)
{
Dust dust = Dust.NewDustPerfect(center, 261);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.color = Color.Brown;
dust.fadeIn = 1.5f;
}
}
#endregion
#region Yellow Mark
public void YellowMarkExplosionDust()
{
// Spawn three butterflies.
ButterflyExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 12f));
Vector2 offset = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.4f, 0.7f) * -1f) * 120f;
offset += Vector2.UnitX * 84f;
ButterflyExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f));
offset = Vector2.UnitY.RotatedBy(Main.rand.NextFloat(0.4f, 0.7f)) * 120f;
offset -= Vector2.UnitX * 84f;
ButterflyExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f));
}
public void ButterflyExplosionDust(Vector2 center, float butterflyBurstSpeed, float offsetAngle = 0f)
{
int petalCount = 4;
// Draw the butterfly as a petal with 4 sides.
for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(4f))
{
Vector2 initialUnitVector = angle.ToRotationVector2();
float unitMultiplier = 2f + (1f + (float)Math.Cos(angle * petalCount)); // This value is used to "squash" the circle to make it into a petal shape.
Vector2 velocity = initialUnitVector * unitMultiplier;
velocity = velocity.RotatedBy(MathHelper.PiOver4 + MathHelper.PiOver2); // Tilt the vector to make it look like an actual butterfly.
velocity = velocity.RotatedBy(offsetAngle);
velocity *= 0.25f; // Normalization removes the spaces that make the vector petal-like and not circular, so multiplication must be utilized instead.
Dust dust = Dust.NewDustPerfect(center, 262);
dust.velocity = velocity * butterflyBurstSpeed;
dust.noGravity = true;
dust.color = Color.Pink;
dust.fadeIn = 1.5f;
}
ButterflyAntennaExplosionDust(center + new Vector2(0f, -74f).RotatedBy(offsetAngle), offsetAngle);
}
public void ButterflyAntennaExplosionDust(Vector2 center, float offsetAngle = 0f)
{
int evaluationPoints = 40;
// When mapped out, these points give a rough apple stem shape.
Vector2[] bezierControlPoints = new Vector2[]
{
new Vector2(0f, 60f),
new Vector2(0f, 30f),
new Vector2(10f, -28f),
new Vector2(20f, -42f),
new Vector2(30f, -48f),
new Vector2(42f, -40f),
new Vector2(50f, -30f),
new Vector2(52f, -24f),
};
BezierCurve bezierCurve = new BezierCurve(bezierControlPoints);
for (int i = 0; i < evaluationPoints; i++)
{
Dust dust = Dust.NewDustPerfect(center, 263);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.color = Color.SkyBlue;
dust.fadeIn = 1.5f;
dust = Dust.CloneDust(dust);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints).RotatedBy(offsetAngle) * new Vector2(-1f, 1f);
}
}
#endregion
#region White Mark
public void WhiteMarkExplosionDust()
{
// Spawn three diamonds.
DiamondExplosionDust(projectile.Center, Main.rand.NextFloat(8f, 12f));
float absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f);
Vector2 offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle * -1f) * 120f;
offset += Vector2.UnitX * 84f;
DiamondExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f));
absoluteOffsetAngle = Main.rand.NextFloat(0.4f, 0.7f);
offset = Vector2.UnitY.RotatedBy(absoluteOffsetAngle) * 120f;
offset -= Vector2.UnitX * 84f;
DiamondExplosionDust(projectile.Center + offset, Main.rand.NextFloat(6f, 11f));
}
public void DiamondExplosionDust(Vector2 center, float diamondBurstSpeed, float offsetAngle = 0f)
{
int dustCount = 80;
for (int i = 0; i < dustCount; i++)
{
Vector2 startingVelocity = Vector2.Zero;
Vector2 endingVelocity = Vector2.Zero;
switch (i / (dustCount / 4))
{
case 0:
startingVelocity = Vector2.UnitY;
endingVelocity = Vector2.UnitX;
break;
case 1:
startingVelocity = Vector2.UnitX;
endingVelocity = -Vector2.UnitY;
break;
case 2:
startingVelocity = -Vector2.UnitY;
endingVelocity = -Vector2.UnitX;
break;
case 3:
startingVelocity = -Vector2.UnitX;
endingVelocity = Vector2.UnitY;
break;
}
Vector2 velocity = Vector2.Lerp(startingVelocity, endingVelocity, i / (dustCount / 4f) % 1f);
velocity = velocity.RotatedBy(offsetAngle);
velocity *= diamondBurstSpeed;
velocity.X *= 0.667f;
Dust dust = Dust.NewDustPerfect(center, 263);
dust.position = center;
dust.velocity = velocity;
dust.noGravity = true;
dust.color = Color.LightSteelBlue;
dust.fadeIn = 1.5f;
}
}
#endregion
#region Sky Blue Mark
public void SkyBlueMarkExplosionDust()
{
RainbowBoltExplosionDust(projectile.Center, Main.rand.NextFloat(-0.2f, 0.2f));
}
public void RainbowBoltExplosionDust(Vector2 center, float offsetAngle = 0f)
{
// Spawn several clouds.
for (int i = 0; i < 5; i++)
{
CloudExplosionDust(center, offsetAngle);
}
LightningExplosionDust(center, offsetAngle);
}
public void CloudExplosionDust(Vector2 center, float offsetAngle = 0f)
{
center += Main.rand.NextVector2CircularEdge(40f, 40f);
Vector2 offset = Main.rand.NextVector2Square(0.9f, 1.15f);
for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(2f))
{
Vector2 initialUnitVector = angle.ToRotationVector2();
Vector2 spawnOffset = initialUnitVector.RotatedBy(offsetAngle);
spawnOffset = spawnOffset.RotatedByRandom(0.4f);
spawnOffset *= new Vector2(54f, 36f) * offset;
spawnOffset -= Vector2.UnitY.RotatedBy(offsetAngle) * 90f;
Dust dust = Dust.NewDustPerfect(center + spawnOffset, 263);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.scale = 2.7f;
dust.fadeIn = 1.5f;
}
}
public void LightningExplosionDust(Vector2 center, float offsetAngle = 0f)
{
int evaluationPoints = 65;
// When mapped out, these points give a rough (but slightly weird) lightning bolt.
Vector2[] controlPoints = new Vector2[]
{
new Vector2(-38f, -64f),
new Vector2(-42f, -44f),
new Vector2(-26f, -28f),
new Vector2(-24f, -10f),
new Vector2(-34f, -4f),
new Vector2(-48f, -10f),
new Vector2(-40f, 12f),
new Vector2(-30f, 30f),
new Vector2(-20f, 48f),
new Vector2(-8f, 28f),
new Vector2(2f, 6f),
new Vector2(-8f, -4f),
new Vector2(4f, -16f),
new Vector2(8f, -36f),
new Vector2(12f, -56f),
new Vector2(-38f, -64f)
};
for (int i = 0; i < evaluationPoints; i++)
{
int currentIndex = (int)(i / (float)evaluationPoints * controlPoints.Length);
Vector2 currentPosition = controlPoints[currentIndex];
Vector2 nextPosition = controlPoints[(currentIndex + 1) % controlPoints.Length];
Dust dust = Dust.NewDustPerfect(center, 263);
dust.position = center + Vector2.Lerp(currentPosition, nextPosition, i / (float)evaluationPoints * controlPoints.Length % 0.999f).RotatedBy(offsetAngle) * 2f;
dust.position += Vector2.UnitY.RotatedBy(offsetAngle) * 138f;
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.color = Main.hslToRgb(i / (float)evaluationPoints * 3f % 1f, 0.6f, 0.7f);
dust.scale = 1.4f;
dust.fadeIn = 1.5f;
}
center += Main.rand.NextVector2CircularEdge(120f, 120f);
Vector2 offset = Main.rand.NextVector2Square(0.9f, 1.15f);
for (float angle = 0f; angle <= MathHelper.TwoPi; angle += MathHelper.ToRadians(2f))
{
Vector2 initialUnitVector = angle.ToRotationVector2();
Vector2 spawnOffset = initialUnitVector.RotatedBy(offsetAngle);
spawnOffset = spawnOffset.RotatedByRandom(0.4f);
spawnOffset *= new Vector2(130f, 84f) * offset;
spawnOffset += Vector2.UnitY.RotatedBy(offsetAngle) * 30f;
Dust dust = Dust.NewDustPerfect(center + spawnOffset, 263);
dust.velocity = Vector2.Zero;
dust.noGravity = true;
dust.scale = 4f;
dust.fadeIn = 1.5f;
}
}
#endregion
#region Purple Mark
public void PurpleMarkExplosionDust()
{
TwilightStarExplosionDust(projectile.Center, 14f, Color.Magenta);
for (int i = 0; i < 6; i++)
{
float angle = MathHelper.TwoPi * i / 6f;
Vector2 offset = angle.ToRotationVector2() * Main.rand.NextFloat(140f, 180f);
TwilightStarExplosionDust(projectile.Center + offset, 4f, Color.White, Main.rand.NextFloat(-0.2f, 0.2f));
}
}
public void TwilightStarExplosionDust(Vector2 center, float petalBurstSpeed, Color starColor, float absoluteOffsetAngle = 0f)
{
int pointsOnStar = 6;
for (int i = 0; i < pointsOnStar; i++)
{
float angle = MathHelper.Pi * 1.5f - i * MathHelper.TwoPi / pointsOnStar;
float nextAngle = MathHelper.Pi * 1.5f - (i + 2) * MathHelper.TwoPi / pointsOnStar;
Vector2 start = angle.ToRotationVector2();
Vector2 end = nextAngle.ToRotationVector2();
int pointsOnStarSegment = 35;
for (int j = 0; j < pointsOnStarSegment; j++)
{
Dust dust = Dust.NewDustPerfect(center, 263);
dust.scale = 1.8f;
dust.velocity = Vector2.Lerp(start, end, j / (float)pointsOnStarSegment) * petalBurstSpeed;
dust.velocity.X *= 0.7f;
dust.velocity = dust.velocity.RotatedBy(absoluteOffsetAngle);
dust.fadeIn = 1.5f;
dust.color = starColor;
dust.noGravity = true;
}
}
}
#endregion
#region Pale Pink Mark
public void PalePinkMarkExplosionDust()
{
StarlightMarkExplosionDust(projectile.Center);
StarlightStarExplosionDust(projectile.Center + new Vector2(16f, 36f), 2f);
}
public void StarlightMarkExplosionDust(Vector2 center)
{
int evaluationPoints = 60;
// When mapped out, these points give a rough swerving stream shape.
Vector2[] bezierControlPoints = new Vector2[]
{
new Vector2(-38f, -58f),
new Vector2(-22f, -34f),
new Vector2(-10f, -22f),
new Vector2(6f, -11f),
new Vector2(13f, 1f),
new Vector2(-20f, 11f),
new Vector2(16f, 11f),
new Vector2(26f, 6f),
new Vector2(24f, -11f),
new Vector2(8f, -28f),
new Vector2(-10f, -39f),
new Vector2(-38f, -58f)
};
BezierCurve bezierCurve = new BezierCurve(bezierControlPoints);
for (int i = 0; i < evaluationPoints; i++)
{
Dust dust = Dust.NewDustPerfect(center, 263);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints) * new Vector2(3f, 1.7f);
dust.velocity = Vector2.Zero;
dust.color = i >= evaluationPoints / 2 ? Color.Cyan : Color.SkyBlue;
dust.fadeIn = 1.5f;
dust.scale = 1.4f;
dust.noGravity = true;
dust = Dust.CloneDust(dust);
dust.position = center + bezierCurve.Evaluate(i / (float)evaluationPoints) * new Vector2(1f, -1f) + new Vector2(30f, -12f);
}
}
public void StarlightStarExplosionDust(Vector2 center, float starBurstSpeed)
{
int dustCount = 60;
for (int i = 0; i < dustCount; i++)
{
Vector2 startingVelocity = Vector2.Zero;
Vector2 endingVelocity = Vector2.Zero;
switch (i / (dustCount / 4))
{
case 0:
startingVelocity = Vector2.UnitY;
endingVelocity = Vector2.UnitX;
break;
case 1:
startingVelocity = Vector2.UnitX;
endingVelocity = -Vector2.UnitY;
break;
case 2:
startingVelocity = -Vector2.UnitY;
endingVelocity = -Vector2.UnitX;
break;
case 3:
startingVelocity = -Vector2.UnitX;
endingVelocity = Vector2.UnitY;
break;
}
Vector2 velocity = Vector2.Lerp(startingVelocity, endingVelocity, i / (dustCount / 4f) % 1f);
velocity *= starBurstSpeed;
velocity.X *= 0.75f;
Dust dust = Dust.NewDustPerfect(center, 263);
dust.position = center;
dust.velocity = velocity;
dust.noGravity = true;
dust.color = Color.Purple;
dust.fadeIn = 1.5f;
dust = Dust.CloneDust(dust);
dust.velocity = dust.velocity.RotatedBy(MathHelper.PiOver4);
dust.color = Color.White;
}
}
#endregion
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B