For angle, try
PHP Code:
angle = (pi * 2) / 4 * (dir + 1);
getAngle(x, y) works with a coordinate plane. For example, getAngle(-2, 1):
So, to get the right result with getAngle(), you'd have to do something like this:
PHP Code:
angle = getAngle(vecx(dir), vecy(dir));
which is far too much work when you can use a simpler solution.