-
AngleDir8() and weapons
The AngleDir8() function is commonly used to set weapon->Dir, but it is inconsistent with unscripted eweapons when it comes to which directions Link can be facing in order to block them when the weapon's angle is close to a multiple of 90 degrees. A more consistent function would be something like this (-180 <= angle <= 180):
Code:
int AngleDir8W(float angle) {
if(angle == 0) return DIR_RIGHT;
else if(angle == 90) return DIR_DOWN;
else if(angle == -90) return DIR_UP;
else if(angle == 180 || angle == -180) return DIR_LEFT;
else if(angle < -90) return DIR_LEFTUP;
else if(angle < 0) return DIR_RIGHTUP;
else if(angle < 90) return DIR_RIGHTDOWN;
else return DIR_LEFTDOWN;
}
int RadianAngleDir8W(float angle) {
return AngleDir8W(angle*57.2958);
}
I think it would make a good addition to std.zh, though other functions that use AngleDir8() with weapon->Dir would need to be updated to fix the inconsistency.
EDIT: Maybe this could be improved. I'll do some testing with radian values.
EDIT 2: There are going to be roundoff errors when using radians, so I think there should be some tolerance for that with the non-diagonal directions. I'm not sure how much though.
-
I think this thread belongs in the scripting section.
-
Yeah, I guess you're right about that. I must have been tired when I posted that here.
Anyway, another std.zh question: what's up with SpinDir()? It doesn't do what it claims at all, or anything seemingly useful right now, for that matter.
Code:
//Converts directions to go round in a circle rather than U, D, L, R
int SpinDir(int dir) {
if(dir == DIR_DOWN || dir == DIR_RIGHT)
return dir;
else if(dir == DIR_LEFT)
return DIR_UP;
else if(dir == DIR_UP)
return DIR_LEFT;
return -1;
}
-
I don't know either. Why does it start from left = 0? :spin:
-
I noticed this function when I was making my Spark script. I really needed a way to easily get the next direction clockwise or counterclockwise, and the functions using it should not have to care which direction it was, so I wrote my "Turn" function for that purpose. Of course, that was all just to help me learn, so I didn't intend it to be used by anyone else, but it does seem like such a function should be possible without converting into angles.
-
This is what I came up with when I tackled that issue:
Code:
// Constants to use as arguments for spin
const int SPIN_CCW = 10b;
const int SPIN_CW = 11b;
int SpinDir(int dir, int spin) {
return dir ^ spin ^ (dir >> 1);
}
I've been having way too much fun with bitwise operators lately.
-
That's much more concise and perfect for my application. Do you mind if I use it?
-
Go ahead. I don't mind at all.