Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Boss
- {
- class Rotation
- {
- // updating rotation
- public byte adjust(ushort[] bot, byte oldR, ushort PlayerPosX, ushort PlayerPosY)
- {
- //setting info to variables (i can take this out later)
- ushort play_x = PlayerPosX;
- ushort play_y = PlayerPosY;
- ushort bot_x = bot[0];
- ushort bot_y = bot[1];
- // Formula to extract an angle
- double angle = Math.Atan((double)(play_y - bot_y) / (double)(play_x - 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 (play_x > bot_x)
- {
- if (play_y > bot_y)// Lower Right
- {
- rot = (byte)Math.Floor((angle / 9) + 10);
- }
- else if (play_y < bot_y)// Top Right
- {
- rot = (byte)Math.Floor((90 + angle) / 9);
- }
- }
- else if (play_x < bot_x)
- {
- if (play_y > bot_y)// Lower Left
- {
- rot = (byte)Math.Floor(((90 + angle) / 9) + 19);
- }
- else if (play_y < bot_y)// Top Left
- {
- rot = (byte)Math.Floor((angle / 9) + 29);
- }
- }
- oldR = rot;
- return oldR;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement