C++ Sort enemies by life

C++ Sort enemies by life

I have a problem with my little game which I have programmed, with the help of a c++ book.

I have a problem with my little game which I have programmed, with the help of a c++ book.

So first I have a class called PlayerObject, and a array with all game objects stored in. When the game starts, I loop through all the objects inside the array.

while (true) {
  for (auto i = 0; i < 100; i++) {
    auto object = FuncObjectId(i);

if (PlayerObject.IsEnemy(object) &amp;&amp;
    PlayerObject.Player.Position.Distance(object.Position) &lt; 1000) {
  // enemies found in range

} }

But what if there are several enemies in the given range? How can i order them ?

sorting by life or distance, for example. So that my player move to the closest target, or to the lowest health target.

Besides, the whole thing has to reset somehow. The player should not stop after killing the target, he should automatically go to the next enemy with the lowest life/closest position.

c++ game-engine

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Top Mobile Game Engines & Development Platforms

Mobile games are liked by one and all. Thus looking at the broader range of user, mobile game develop...

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.

How to Create a 2.5D Platformer Game with Unreal Engine using C++

Learn how to create a 2.5D Platformer game with Unreal Engine in this full tutorial using C++. You will how to create a game with Unreal Engine and Blueprints.

Using isdigit() in C/C++

In this article, we'll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let's look