Advertisement
Tkap1

Untitled

Nov 20th, 2022
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1.  
  2.  
  3. if right click
  4. {
  5.     constexpr int priority[] = {
  6.         type_fire, type_ranged, type_flyer, type_boss, type_default
  7.     };
  8.    
  9.     // this is supposed to store entity indices
  10.     int hit[128] = {};
  11.    
  12.     int hit_count = 0;
  13.     for each enemy
  14.     {
  15.         if enemy collides with mouse
  16.         {
  17.             hit[hit_count++] = enemy;
  18.         }
  19.     }
  20.    
  21.     // bubble sort 
  22.     for(int i = 0; i < hit_count; i++)
  23.     {
  24.         b8 swaps = false;
  25.         for(int j = 0; j < hit_count - 1; j++)
  26.         {
  27.             int* a = hit[j];
  28.             int* b = hit[j + 1];
  29.            
  30.             int a_order = 0;
  31.             for(int prio_i = 0; prio_i < array_count(priority); prio_i++)
  32.             {
  33.                 if(enemies[*a].type == priorities[prio_i])
  34.                 {
  35.                     a_order = prio_i;
  36.                     break;
  37.                 }
  38.             }          
  39.            
  40.             int b_order = 0;
  41.             for(int prio_i = 0; prio_i < array_count(priority); prio_i++)
  42.             {
  43.                 if(enemies[*a].type == priorities[prio_i])
  44.                 {
  45.                     b_order = prio_i;
  46.                     break;
  47.                 }
  48.             }          
  49.            
  50.             if(b_order < a_order)
  51.             {
  52.                 swaps = true;
  53.                 int temp = *a;
  54.                 *a = *b;
  55.                 *b = temp;
  56.             }
  57.         }
  58.         if(!swaps) { break; }
  59.     }
  60.    
  61.     target is hit[0];
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement