Decimation_Mod/Content/Projectiles/Scarab.cs

68 lines
2.1 KiB
C#

using Decimation.Content.Buffs.Buffs;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Decimation.Content.Projectiles
{
internal class Scarab : DecimationProjectile
{
protected override int Damages => 0;
protected override int AnimationFrames => 2;
protected override void Init()
{
projectile.width = 22;
projectile.height = 22;
projectile.aiStyle = -1;
projectile.ignoreWater = true;
projectile.tileCollide = false;
projectile.penetrate = -1;
projectile.timeLeft = int.MaxValue;
}
public override void AI()
{
Player player = Main.player[(int)(projectile.ai[0])];
if (!player.HasBuff(ModContent.BuffType<ScarabEndurance>()))
projectile.Kill();
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;
if (projectile.velocity.Y > 0.5f)
projectile.velocity.Y = 0.5f;
float x = projectile.position.X;
float y = projectile.position.Y;
if (x < player.Center.X - 60 || x > player.Center.X + 60)
projectile.velocity.X *= -1;
if (y < player.Center.Y - 60 || y > player.Center.Y + 60)
projectile.velocity.Y *= -1;
// Follow the player
float diffX = projectile.Center.X - player.Center.X;
float diffY = projectile.Center.Y - player.Center.Y;
if (diffX > 70)
projectile.position.X -= diffX / 60;
else if (diffX < -70)
projectile.position.X -= diffX / 60;
if (diffY > 70)
projectile.position.Y -= diffY / 60;
else if (diffY < -70)
projectile.position.Y -= diffY / 60;
}
}
}