This might be more of a programming question than NES specific, however I can conceive of plenty of ways to do this with higher level functions or if cycles weren't a concern...so I guess I'm looking for a suggested method for something much more efficient -
I'm looking to essentially detect whether a collision with an object happened top,right,bottom or left. Figuring "left or right" or "top or bottom" is incredibly simple - just a quick compare of the x or y values respectively. But out of the four directions is, of course, uglier.
Currently, I've got something very bloated and ugly - gauging the difference between the two objects' x values vs the difference between the y values and using the greater of the two as a determining factor as to whether I should check vertical or horizontal, and using the compare as above. However, without being able to get an absolute value (is there a way to get an absolute value?), this involves the extra step of seeing which object has the larger coordinate value and then make two cases for one or the other...just to determine which value to subtract from which for that coordinate, doing the same for the other coordinate, before doing the compare between x and y coordinates to determine if I should check vert or horizontal...to then do a compare like above.
Not sure if that made any sense at all to anyone, and I'm thinking there might be a much simpler process. I'm sort of staring at it too closely at this point, wondering if anyone had any thoughts.
Thanks!
Joe
I'm looking to essentially detect whether a collision with an object happened top,right,bottom or left. Figuring "left or right" or "top or bottom" is incredibly simple - just a quick compare of the x or y values respectively. But out of the four directions is, of course, uglier.
Currently, I've got something very bloated and ugly - gauging the difference between the two objects' x values vs the difference between the y values and using the greater of the two as a determining factor as to whether I should check vertical or horizontal, and using the compare as above. However, without being able to get an absolute value (is there a way to get an absolute value?), this involves the extra step of seeing which object has the larger coordinate value and then make two cases for one or the other...just to determine which value to subtract from which for that coordinate, doing the same for the other coordinate, before doing the compare between x and y coordinates to determine if I should check vert or horizontal...to then do a compare like above.
Not sure if that made any sense at all to anyone, and I'm thinking there might be a much simpler process. I'm sort of staring at it too closely at this point, wondering if anyone had any thoughts.
Thanks!
Joe