Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if right click
- {
- constexpr int priority[] = {
- type_fire, type_ranged, type_flyer, type_boss, type_default
- };
- // this is supposed to store entity indices
- int hit[128] = {};
- int hit_count = 0;
- for each enemy
- {
- if enemy collides with mouse
- {
- hit[hit_count++] = enemy;
- }
- }
- // bubble sort
- for(int i = 0; i < hit_count; i++)
- {
- b8 swaps = false;
- for(int j = 0; j < hit_count - 1; j++)
- {
- int* a = hit[j];
- int* b = hit[j + 1];
- int a_order = 0;
- for(int prio_i = 0; prio_i < array_count(priority); prio_i++)
- {
- if(enemies[*a].type == priorities[prio_i])
- {
- a_order = prio_i;
- break;
- }
- }
- int b_order = 0;
- for(int prio_i = 0; prio_i < array_count(priority); prio_i++)
- {
- if(enemies[*a].type == priorities[prio_i])
- {
- b_order = prio_i;
- break;
- }
- }
- if(b_order < a_order)
- {
- swaps = true;
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- }
- if(!swaps) { break; }
- }
- target is hit[0];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement