I found what might be another issue due to moving archetypes.
world.Query(in enemyQuery, (in Entity entity, ref EntityStatus entityStatus, ref SpriteSheet spriteSheet, ref Animation animation) =>
{
if (entityStatus.State == State.ReadyToDie)
{
entityStatus.State = State.Dying;
if (entity.Has<Burn>())
{
entity.Remove<Burn>();
}
if (entity.Has<Slow>())
{
entity.Remove<Slow>();
}
if (entity.Has<Shock>())
{
entity.Remove<Shock>();
}
if (spriteSheet.Width == 16)
{
if(entity.Get<Health>().Current > 0)
{
Console.WriteLine("hello");
}
int bloodToUse = random.Next(1, 9);
spriteSheet = new SpriteSheet(textures["MiniBlood" + bloodToUse], "MiniBlood" + bloodToUse, getMiniBloodNumFrames(bloodToUse), 1, 0, .5f);
animation = new Animation(0, getMiniBloodNumFrames(bloodToUse) - 1, 1 / 60f, 1, false);
}
else
{
int bloodToUse = random.Next(1, 5);
spriteSheet = new SpriteSheet(textures["Blood" + bloodToUse], "Blood" + bloodToUse, 30, 1, 0, .5f);
animation = new Animation(0, 29, 1 / 60f, 1, false);
}
if (entityStatus.State == State.Alive)
{
Console.WriteLine("Hello");
}
}
else if (entityStatus.State == State.Dying && animation.CurrentFrame == animation.LastFrame)
{
entityStatus.State = State.Dead;
}
});
My solution for now will be to move the removal to a separate query because the sprite/animation change later in the loop is affecting enemies that haven't been killed yet. Oddly enough, I already had to do this to fix some issues in removing the physics component.
world.Query(in enemyQuery, (ref EntityStatus entityStatus, ref SpriteSheet spriteSheet, ref Animation animation) =>
{
if (entityStatus.State == State.ReadyToDie)
{
entityStatus.State = State.Dying;
if (spriteSheet.Width == 16)
{
int bloodToUse = random.Next(1, 9);
spriteSheet = new SpriteSheet(textures["MiniBlood" + bloodToUse], "MiniBlood" + bloodToUse, getMiniBloodNumFrames(bloodToUse), 1, 0, .5f);
animation = new Animation(0, getMiniBloodNumFrames(bloodToUse) - 1, 1 / 60f, 1, false);
}
else
{
int bloodToUse = random.Next(1, 5);
spriteSheet = new SpriteSheet(textures["Blood" + bloodToUse], "Blood" + bloodToUse, 30, 1, 0, .5f);
animation = new Animation(0, 29, 1 / 60f, 1, false);
}
}
else if (entityStatus.State == State.Dying && animation.CurrentFrame == animation.LastFrame)
{
entityStatus.State = State.Dead;
}
});
world.Query(in query, (in Entity entity, ref EntityStatus entityStatus, ref Body body) =>
{
if(entityStatus.State != State.Alive)
{
physicsWorld.DestroyBody(body);
entity.RemoveRange(typeof(Body), typeof(Burn), typeof(Slow), typeof(Shock));
}
});
I may also just be trying to do too much in my loops, so feel free to tell me I'm doing things a dumb way ๐