That's some major math for sure.
By the way, this is what I came up with when I was making Abyssal Infants.
[code]
void fire_bullet_to_player(Enemy *e, s16 x, s16 y, fix16 speed) {
Player *p = get_closest_x_player(e);
fix16 vx = fix16Div(fix16Sub(p->obj.x, FIX16(x)), F320);
fix16 vy = fix16Div(fix16Sub(p->obj.y, FIX16(y)), F320);
fix16 length = fix16Add(fix16Mul(vx, vx), fix16Mul(vy,vy));
length = fix16Sqrt(length);
if (length != 0) {
vx = fix16Div(vx, length);
vy = fix16Div(vy, length);
vx = fix16Mul(vx, speed);
vy = fix16Mul(vy, speed);
add_enemy_bullet(x, y, vx, vy);
}
}
[/code]
F320 is just the FIX16(320) I use it so, the numbers do not pass the f16 limits, this probably can be replaced with F16 or bit shifting.
But I think what is really missing from your code is the use of fix16Sqrt that underneath is just indexing an array. Check it out.