quick hack to render based on y order. Only draw enemy hp bars. Allow players to...
authorStan_Lewry <stanley.jml@gmail.com>
Sat, 14 Sep 2024 14:45:06 +0000 (15:45 +0100)
committerStan_Lewry <stanley.jml@gmail.com>
Sat, 14 Sep 2024 14:45:06 +0000 (15:45 +0100)
combat.cpp

index 3b372c0..5cb2ec3 100644 (file)
@@ -72,13 +72,9 @@ enum CombatState {
 
 CombatState currentCombatState = TURN_ORDER;
 
-
-
 static double frameTimer = 0;
 static const double frameTime = 1.0f / 60.0f;
 
-//bool playerTurn = true;
-
 SDL_Texture* arrowSprite = nullptr;
 SDL_Texture* indicatorSprite = nullptr;
 SDL_Texture* indicatorRedSprite = nullptr;
@@ -94,8 +90,6 @@ S2DE::Camera combatCam = { 23.5, 11.5 };
 S2DE::Vec2<float> moveCursorPos;
 S2DE::Vec2<float> arenaCenter = { 23, 11 };
 
-//S2DE::Vec2<float>* currentMoveDest = &moveCursorPos;
-
 static const int numActions = 4;
 static const char* actions[numActions] = {"Move", "Attack", "End", "FLEE"};
 int currentAction = 0;
@@ -248,7 +242,14 @@ void renderCombat() {
 
 void renderCombatants() {
 
-       for (Character c : combatants) {
+       // this fucking sucks:
+       std::vector<Character> combatantsRender = combatants;
+       std::sort(combatantsRender.begin(), combatantsRender.end(),
+               [](const Character& a, const Character& b) {
+                       return a.position.y < b.position.y;
+       });
+
+       for (Character c : combatantsRender) {
 
                if (c.alive) {
                        S2DE::Vec2<float> pos = c.position;
@@ -281,8 +282,10 @@ void renderCombatants() {
                        SDL_Texture* texture = c.texture;
                        S2DE::renderTexture(&renderer, &texture, &charSRect, &charDRect);
 
-                       float hpLvl = (float)c.currentHP / (float)c.maxHP;
-                       renderMeter(charDRect.x + 6, charDRect.y - 6, charDRect.w - 12, 6, hpLvl, hpColour, 1);
+                       if (!c.allied) {
+                               float hpLvl = (float)c.currentHP / (float)c.maxHP;
+                               renderMeter(charDRect.x + 6, charDRect.y - 6, charDRect.w - 12, 6, hpLvl, hpColour, 1);
+                       }
                }
        }
 
@@ -296,7 +299,7 @@ void renderCombatants() {
 
 bool checkCharacterCollision(S2DE::Vec2<float> position) {
        for (auto c : combatants) {
-               if (c.name != activeCombatant->name) { // this sucks
+               if (c.name != activeCombatant->name && c.alive) {
                        float charMinX = c.position.x;
                        float charMaxX = c.position.x + 1.0;
                        float charMinY = c.position.y;