Advertisement
PsyOps

Rotation

May 31st, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Boss
  7. {
  8.     class Rotation
  9.     {
  10.         // updating rotation
  11.         public byte adjust(ushort[] bot, byte oldR, ushort PlayerPosX, ushort PlayerPosY)
  12.         {
  13.  
  14.             //setting info to variables (i can take this out later)
  15.             ushort play_x = PlayerPosX;
  16.             ushort play_y = PlayerPosY;
  17.             ushort bot_x = bot[0];
  18.             ushort bot_y = bot[1];
  19.  
  20.             // Formula to extract an angle
  21.             double angle = Math.Atan((double)(play_y - bot_y) / (double)(play_x - bot_x)) * (180.0 / 3.14159);
  22.             byte rot = 0;
  23.  
  24.             // with formula we get 0-90 degrees for each quadrant
  25.             // here we simply find out which quadrant it is and add the proper increment to make it rotation 0-39
  26.             if (play_x > bot_x)
  27.             {
  28.                 if (play_y > bot_y)// Lower Right
  29.                 {
  30.                     rot = (byte)Math.Floor((angle / 9) + 10);
  31.                 }
  32.                 else if (play_y < bot_y)// Top Right
  33.                 {
  34.                     rot = (byte)Math.Floor((90 + angle) / 9);
  35.                 }
  36.             }
  37.             else if (play_x < bot_x)
  38.             {
  39.                 if (play_y > bot_y)// Lower Left
  40.                 {
  41.                     rot = (byte)Math.Floor(((90 + angle) / 9) + 19);
  42.                 }
  43.                 else if (play_y < bot_y)// Top Left
  44.                 {
  45.                     rot = (byte)Math.Floor((angle / 9) + 29);
  46.                 }
  47.             }
  48.  
  49.             oldR = rot;
  50.             return oldR;
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement