Added better support for animated projectiles

This commit is contained in:
FyloZ 2020-03-21 00:44:09 -04:00
parent ec4585bed5
commit 483f094f9c
4 changed files with 33 additions and 46 deletions

View File

@ -6,19 +6,26 @@ namespace Decimation.Content.Projectiles
{
public abstract class DecimationProjectile : ModProjectile
{
protected virtual int Damages { get; set; } = 0;
private static readonly int FramesPerSeconds = 60;
protected virtual int Damages { get; set; }
protected virtual DecimationWeapon.DamageType DamageType { get; set; } = DecimationWeapon.DamageType.Melee;
protected virtual int AnimationFrames { get; } = -1;
protected virtual int AnimationFps { get; } = 5;
private int _frameTime;
protected abstract void Init();
// public override void SetStaticDefaults()
// {
// if (AnimationFrames >= 0) Main.projFrames[projectile.type] = AnimationFrames;
// }
public override void SetStaticDefaults()
{
if (AnimationFrames >= 0) Main.projFrames[projectile.type] = AnimationFrames;
}
public sealed override void SetDefaults()
{
_frameTime = FramesPerSeconds / AnimationFps;
this.projectile.aiStyle = 1;
this.projectile.height = 16;
this.projectile.width = 16;
@ -29,7 +36,7 @@ namespace Decimation.Content.Projectiles
this.projectile.penetrate = 0;
this.projectile.tileCollide = true;
this.projectile.timeLeft = 180;
Init();
this.projectile.damage = Damages;
@ -53,5 +60,17 @@ namespace Decimation.Content.Projectiles
break;
}
}
public override bool PreAI()
{
if (++projectile.frameCounter >= _frameTime)
{
projectile.frameCounter = 0;
if (++projectile.frame >= AnimationFrames) projectile.frame = 0;
}
return base.PreAI();
}
}
}

View File

@ -9,11 +9,6 @@ namespace Decimation.Content.Projectiles
protected override DecimationWeapon.DamageType DamageType => DecimationWeapon.DamageType.Ranged;
protected override int Damages => 45;
public override void SetStaticDefaults()
{
Main.projFrames[projectile.type] = 4;
}
protected override void Init()
{
projectile.width = 10;
@ -26,20 +21,10 @@ namespace Decimation.Content.Projectiles
public override bool PreAI()
{
if (++projectile.frameCounter >= 5)
{
projectile.frameCounter = 0;
if (++projectile.frame >= 4)
{
projectile.frame = 0;
}
}
Lighting.AddLight(projectile.Center, 0f, 0f, 1f);
projectile.rotation = projectile.velocity.ToRotation();
return true;
return base.PreAI();
}
}
}

View File

@ -11,10 +11,7 @@ namespace Decimation.Content.Projectiles
{
internal class LightningSphere : DecimationProjectile
{
public override void SetStaticDefaults()
{
Main.projFrames[projectile.type] = 5;
}
protected override int AnimationFrames => 5;
protected override void Init()
{

View File

@ -12,15 +12,12 @@ using Terraria.ModLoader;
namespace Decimation.Content.Projectiles
{
internal class Scarab : DecimationProjectile
{
public override void SetStaticDefaults()
{
Main.projFrames[projectile.type] = 2;
}
{
protected override int Damages => 0;
protected override int AnimationFrames => 2;
protected override void Init()
{
Damages = 0;
projectile.width = 22;
projectile.height = 22;
projectile.aiStyle = -1;
@ -36,18 +33,8 @@ namespace Decimation.Content.Projectiles
if (!player.HasBuff(ModContent.BuffType<ScarabEndurance>()))
projectile.Kill();
// Loop through the 2 animation frames, spending 5 ticks on each.
if (++projectile.frameCounter >= 5)
{
projectile.frameCounter = 0;
if (++projectile.frame >= 2)
{
projectile.frame = 0;
}
}
projectile.velocity.X += (float)Main.rand.Next(-75, 76) * 0.005f;
projectile.velocity.Y += (float)Main.rand.Next(-75, 76) * 0.005f;
projectile.velocity.X += Main.rand.Next(-75, 76) * 0.005f;
projectile.velocity.Y += Main.rand.Next(-75, 76) * 0.005f;
if (projectile.velocity.X > 0.5f)
projectile.velocity.X = 0.5f;
@ -63,7 +50,6 @@ namespace Decimation.Content.Projectiles
projectile.velocity.Y *= -1;
// Follow the player
Vector2 velocity = projectile.velocity;
float diffX = projectile.Center.X - player.Center.X;
float diffY = projectile.Center.Y - player.Center.Y;