wch
Terrarian
What is happening is the sound is restarting every frame, so you never hear it until it dies (since it doesn't restart the next frame)
You forgot the code that prevents it from triggering more than once:
Code:
public override void AI()
{
Lighting.AddLight(projectile.Center, 0.1f, 0.4f, 1f);
if (projectile.ai[1] == 0f)
{
projectile.ai[1] = 0f;
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 28);
}
Vector2 vector13;
float num138;
float num139;
float num140;
float num141;
float num142;
bool flag4;
int num143;
int num144;
float num145;
float num146;
float num147;
int num148;
float num149;
float num150;
float num151;
float num152;
float num153;
float num154;
float num155;
int num156;
{
for (int num136 = 0; num136 < 1; num136++)
{
float x2 = projectile.position.X - projectile.velocity.X / 10f * (float)num136;
float y2 = projectile.position.Y - projectile.velocity.Y / 10f * (float)num136;
int dust1 = Dust.NewDust(new Vector2(x2, y2), 20, 20, 15, 0f, 0f, 200, default(Color), 2f);
Main.dust[dust1].velocity *= 0f;
Main.dust[dust1].noGravity = true;
int dust2= Dust.NewDust(new Vector2(x2, y2), 20, 20, 15, 0f, 0f, 200, default(Color), 1f);
Main.dust[dust2].velocity *= 0f;
Main.dust[dust2].noGravity = true;
}
}
num138 = (float)Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y));
num139 = projectile.localAI[0];
if (num139 == 0f)
{
projectile.localAI[0] = num138;
num139 = num138;
}
num140 = projectile.position.X;
num141 = projectile.position.Y;
num142 = 300f;
flag4 = false;
num143 = 0;
if (projectile.ai[1] == 0f)
{
for (num144 = 0; num144 < 200; num144++)
{
if (Main.npc[num144].CanBeChasedBy(projectile, false) && (projectile.ai[1] == 0f || projectile.ai[1] == (float)(num144 + 1)))
{
num145 = Main.npc[num144].position.X + (float)(Main.npc[num144].width / 2);
num146 = Main.npc[num144].position.Y + (float)(Main.npc[num144].height / 2);
num147 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num145) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num146);
if (num147 < num142 && Collision.CanHit(new Vector2(projectile.position.X + (float)(projectile.width / 2), projectile.position.Y + (float)(projectile.height / 2)), 1, 1, Main.npc[num144].position, Main.npc[num144].width, Main.npc[num144].height))
{
num142 = num147;
num140 = num145;
num141 = num146;
flag4 = true;
num143 = num144;
}
}
}
if (flag4)
{
projectile.ai[1] = (float)(num143 + 1);
}
flag4 = false;
}
if (projectile.ai[1] > 0f)
{
num148 = (int)(projectile.ai[1] - 1f);
if (Main.npc[num148].active && Main.npc[num148].CanBeChasedBy(projectile, true) && !Main.npc[num148].dontTakeDamage)
{
num149 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
num150 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
num151 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num149) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num150);
if (num151 < 1000f)
{
flag4 = true;
num140 = Main.npc[num148].position.X + (float)(Main.npc[num148].width / 2);
num141 = Main.npc[num148].position.Y + (float)(Main.npc[num148].height / 2);
}
}
else
{
projectile.ai[1] = 0f;
}
}
if (!projectile.friendly)
{
flag4 = false;
}
if (flag4)
{
num152 = num139;
vector13 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
num153 = num140 - vector13.X;
num154 = num141 - vector13.Y;
num155 = (float)Math.Sqrt((double)(num153 * num153 + num154 * num154));
num155 = num152 / num155;
num153 *= num155;
num154 *= num155;
num156 = 8;
projectile.velocity.X = (projectile.velocity.X * (float)(num156 - 1) + num153) / (float)num156;
projectile.velocity.Y = (projectile.velocity.Y * (float)(num156 - 1) + num154) / (float)num156;
}
}
Code:
if (projectile.ai[1] == 0f)
{
projectile.ai[1] = 0f;
Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 28);
}
Once I throw them in this chlorophyte bullet hooming projectile, it went wrong. By "wrong", I mean the sound will only be played when the projectile hits the tile. Based on this, I guess there may be some kinds of conflictions. But... what's wrong anyways?