Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private byte adjust(PlayerPositionEvent OldBotPos, ushort newX, ushort newY)
- {
- //setting info to variables (i can take this out later)
- ushort new_bot_x = newX;
- ushort new_bot_y = newY;
- ushort old_bot_x = OldBotPos.MapPositionX;
- ushort old_bot_y = OldBotPos.MapPositionY;
- // Formula to extract an angle
- double angle = Math.Atan((double)(new_bot_y - old_bot_y) / (double)(new_bot_x - old_bot_x)) * (180.0 / 3.14159);
- byte rot = 0;
- // with formula we get 0-90 degrees for each quadrant
- // here we simply find out which quadrant it is and add the proper increment to make it rotation 0-39
- if (new_bot_x > old_bot_x)
- {
- if (new_bot_y > old_bot_y)// Lower Right
- rot = (byte)Math.Floor((angle / 9) + 10);
- else if (new_bot_y < old_bot_y)// Top Right
- rot = (byte)Math.Floor((90 + angle) / 9);
- }
- else if (new_bot_x < old_bot_x)
- {
- if (new_bot_y > old_bot_y)// Lower Left
- rot = (byte)Math.Floor(((90 + angle) / 9) + 20);
- else if (new_bot_y < old_bot_y)// Top Left
- rot = (byte)Math.Floor((angle / 9) + 30);
- }
- return rot;
- }
Advertisement
Add Comment
Please, Sign In to add comment