91 lines
4.3 KiB
C#
91 lines
4.3 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Terraria;
|
|
using Terraria.DataStructures;
|
|
using Terraria.GameContent;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
using ForgottenWawiTech.Content.Rarities;
|
|
|
|
namespace ForgottenWawiTech.Content.Items.Materials
|
|
{
|
|
public class MiniSingularity : ModItem
|
|
{
|
|
private const int FrameCount = 8;
|
|
private const int TicksPerFrame = 5;
|
|
private const int AfterimageCount = 12;
|
|
private const float AfterimageRadiusMultiplier = 0.58f;
|
|
private const float AfterimageOpacity = 0.22f;
|
|
private const float AfterimageScaleJitter = 0.12f;
|
|
private const float AfterimageOrbitSpeed = 2.1f;
|
|
private const float AfterimageDriftAmplitude = 0.35f;
|
|
private const float AfterimageDriftFrequency = 0.85f;
|
|
private const float AfterimageRotationJitter = 0.35f;
|
|
private const float AfterimageNoiseRadiusMultiplier = 0.08f;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.RegisterItemAnimation(Type, new DrawAnimationVertical(TicksPerFrame, FrameCount));
|
|
ItemID.Sets.AnimatesAsSoul[Type] = true;
|
|
ItemID.Sets.ItemNoGravity[Type] = true;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Item.width = 32;
|
|
Item.height = 32;
|
|
Item.maxStack = 9999;
|
|
Item.rare = ModContent.RarityType<SingularityItem>();
|
|
Item.value = Item.buyPrice(gold: 50);
|
|
}
|
|
|
|
public override void AddRecipes()
|
|
{
|
|
CreateRecipe()
|
|
.AddIngredient(ItemID.FragmentNebula, 5)
|
|
.AddIngredient(ItemID.FragmentSolar, 5)
|
|
.AddIngredient(ItemID.FragmentVortex, 5)
|
|
.AddIngredient(ItemID.FragmentStardust, 5)
|
|
.AddIngredient(ItemID.WormholePotion, 1)
|
|
.AddTile(TileID.LunarCraftingStation)
|
|
.Register();
|
|
}
|
|
|
|
public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
|
|
{
|
|
Texture2D texture = TextureAssets.Item[Type].Value;
|
|
int frameHeight = texture.Height / Math.Max(1, FrameCount);
|
|
int frameIndex = (int)((Main.GameUpdateCount / (ulong)Math.Max(1, TicksPerFrame)) % (ulong)Math.Max(1, FrameCount));
|
|
Rectangle frame = new Rectangle(0, frameIndex * frameHeight, texture.Width, frameHeight);
|
|
|
|
Vector2 drawPosition = Item.Center - Main.screenPosition;
|
|
Vector2 origin = frame.Size() / 2f;
|
|
float baseRadius = frame.Width * scale * AfterimageRadiusMultiplier;
|
|
float time = (float)Main.GlobalTimeWrappedHourly;
|
|
float seededOffset = whoAmI * 0.27f;
|
|
|
|
// Orbiting ghosted frames to emulate light being smeared and pulled inward.
|
|
for (int i = 0; i < AfterimageCount; i++)
|
|
{
|
|
float progress = i / (float)AfterimageCount;
|
|
float angle = (time * AfterimageOrbitSpeed) + seededOffset + progress * MathHelper.TwoPi;
|
|
float drift = (float)Math.Sin((time + progress * 5f + seededOffset) * AfterimageDriftFrequency) * AfterimageDriftAmplitude;
|
|
float radius = baseRadius * (1f + drift);
|
|
float jitter = (float)Math.Sin((time * 1.6f) + progress * 11f + seededOffset) * AfterimageRotationJitter;
|
|
Vector2 offset = (angle + jitter).ToRotationVector2() * radius;
|
|
Vector2 noise = new Vector2(
|
|
(float)Math.Sin((time * 2.4f) + progress * 13f + seededOffset),
|
|
(float)Math.Cos((time * 2.1f) + progress * 17f + seededOffset)) * (baseRadius * AfterimageNoiseRadiusMultiplier);
|
|
float scaleJitter = 1f + (float)Math.Sin((time * 3.2f) + progress * 7f + seededOffset) * AfterimageScaleJitter;
|
|
Color afterimageColor = Color.Lerp(lightColor, Color.Black, 0.6f) * AfterimageOpacity;
|
|
|
|
spriteBatch.Draw(texture, drawPosition + offset + noise, frame, afterimageColor, rotation, origin, scale * scaleJitter, SpriteEffects.None, 0f);
|
|
}
|
|
|
|
spriteBatch.Draw(texture, drawPosition, frame, lightColor, rotation, origin, scale, SpriteEffects.None, 0f);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |