Added better support for animated projectiles
This commit is contained in:
parent
ec4585bed5
commit
483f094f9c
@ -6,19 +6,26 @@ namespace Decimation.Content.Projectiles
|
|||||||
{
|
{
|
||||||
public abstract class DecimationProjectile : ModProjectile
|
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 DecimationWeapon.DamageType DamageType { get; set; } = DecimationWeapon.DamageType.Melee;
|
||||||
protected virtual int AnimationFrames { get; } = -1;
|
protected virtual int AnimationFrames { get; } = -1;
|
||||||
|
protected virtual int AnimationFps { get; } = 5;
|
||||||
|
|
||||||
|
private int _frameTime;
|
||||||
|
|
||||||
protected abstract void Init();
|
protected abstract void Init();
|
||||||
|
|
||||||
// public override void SetStaticDefaults()
|
public override void SetStaticDefaults()
|
||||||
// {
|
{
|
||||||
// if (AnimationFrames >= 0) Main.projFrames[projectile.type] = AnimationFrames;
|
if (AnimationFrames >= 0) Main.projFrames[projectile.type] = AnimationFrames;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public sealed override void SetDefaults()
|
public sealed override void SetDefaults()
|
||||||
{
|
{
|
||||||
|
_frameTime = FramesPerSeconds / AnimationFps;
|
||||||
|
|
||||||
this.projectile.aiStyle = 1;
|
this.projectile.aiStyle = 1;
|
||||||
this.projectile.height = 16;
|
this.projectile.height = 16;
|
||||||
this.projectile.width = 16;
|
this.projectile.width = 16;
|
||||||
@ -29,7 +36,7 @@ namespace Decimation.Content.Projectiles
|
|||||||
this.projectile.penetrate = 0;
|
this.projectile.penetrate = 0;
|
||||||
this.projectile.tileCollide = true;
|
this.projectile.tileCollide = true;
|
||||||
this.projectile.timeLeft = 180;
|
this.projectile.timeLeft = 180;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
this.projectile.damage = Damages;
|
this.projectile.damage = Damages;
|
||||||
@ -53,5 +60,17 @@ namespace Decimation.Content.Projectiles
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool PreAI()
|
||||||
|
{
|
||||||
|
if (++projectile.frameCounter >= _frameTime)
|
||||||
|
{
|
||||||
|
projectile.frameCounter = 0;
|
||||||
|
|
||||||
|
if (++projectile.frame >= AnimationFrames) projectile.frame = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.PreAI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,11 +9,6 @@ namespace Decimation.Content.Projectiles
|
|||||||
protected override DecimationWeapon.DamageType DamageType => DecimationWeapon.DamageType.Ranged;
|
protected override DecimationWeapon.DamageType DamageType => DecimationWeapon.DamageType.Ranged;
|
||||||
protected override int Damages => 45;
|
protected override int Damages => 45;
|
||||||
|
|
||||||
public override void SetStaticDefaults()
|
|
||||||
{
|
|
||||||
Main.projFrames[projectile.type] = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Init()
|
protected override void Init()
|
||||||
{
|
{
|
||||||
projectile.width = 10;
|
projectile.width = 10;
|
||||||
@ -26,20 +21,10 @@ namespace Decimation.Content.Projectiles
|
|||||||
|
|
||||||
public override bool PreAI()
|
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);
|
Lighting.AddLight(projectile.Center, 0f, 0f, 1f);
|
||||||
projectile.rotation = projectile.velocity.ToRotation();
|
projectile.rotation = projectile.velocity.ToRotation();
|
||||||
|
|
||||||
return true;
|
return base.PreAI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11,10 +11,7 @@ namespace Decimation.Content.Projectiles
|
|||||||
{
|
{
|
||||||
internal class LightningSphere : DecimationProjectile
|
internal class LightningSphere : DecimationProjectile
|
||||||
{
|
{
|
||||||
public override void SetStaticDefaults()
|
protected override int AnimationFrames => 5;
|
||||||
{
|
|
||||||
Main.projFrames[projectile.type] = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Init()
|
protected override void Init()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,15 +12,12 @@ using Terraria.ModLoader;
|
|||||||
namespace Decimation.Content.Projectiles
|
namespace Decimation.Content.Projectiles
|
||||||
{
|
{
|
||||||
internal class Scarab : DecimationProjectile
|
internal class Scarab : DecimationProjectile
|
||||||
{
|
{
|
||||||
public override void SetStaticDefaults()
|
protected override int Damages => 0;
|
||||||
{
|
protected override int AnimationFrames => 2;
|
||||||
Main.projFrames[projectile.type] = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Init()
|
protected override void Init()
|
||||||
{
|
{
|
||||||
Damages = 0;
|
|
||||||
projectile.width = 22;
|
projectile.width = 22;
|
||||||
projectile.height = 22;
|
projectile.height = 22;
|
||||||
projectile.aiStyle = -1;
|
projectile.aiStyle = -1;
|
||||||
@ -36,18 +33,8 @@ namespace Decimation.Content.Projectiles
|
|||||||
if (!player.HasBuff(ModContent.BuffType<ScarabEndurance>()))
|
if (!player.HasBuff(ModContent.BuffType<ScarabEndurance>()))
|
||||||
projectile.Kill();
|
projectile.Kill();
|
||||||
|
|
||||||
// Loop through the 2 animation frames, spending 5 ticks on each.
|
projectile.velocity.X += Main.rand.Next(-75, 76) * 0.005f;
|
||||||
if (++projectile.frameCounter >= 5)
|
projectile.velocity.Y += Main.rand.Next(-75, 76) * 0.005f;
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (projectile.velocity.X > 0.5f)
|
if (projectile.velocity.X > 0.5f)
|
||||||
projectile.velocity.X = 0.5f;
|
projectile.velocity.X = 0.5f;
|
||||||
@ -63,7 +50,6 @@ namespace Decimation.Content.Projectiles
|
|||||||
projectile.velocity.Y *= -1;
|
projectile.velocity.Y *= -1;
|
||||||
|
|
||||||
// Follow the player
|
// Follow the player
|
||||||
Vector2 velocity = projectile.velocity;
|
|
||||||
float diffX = projectile.Center.X - player.Center.X;
|
float diffX = projectile.Center.X - player.Center.X;
|
||||||
float diffY = projectile.Center.Y - player.Center.Y;
|
float diffY = projectile.Center.Y - player.Center.Y;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user