From f47d6e89402bef594766c7c6ed94d1fc363764dc Mon Sep 17 00:00:00 2001 From: Stan_Lewry Date: Sat, 14 Sep 2024 15:45:06 +0100 Subject: [PATCH] quick hack to render based on y order. Only draw enemy hp bars. Allow players to move through dead characters --- combat.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/combat.cpp b/combat.cpp index 3b372c0..5cb2ec3 100644 --- a/combat.cpp +++ b/combat.cpp @@ -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 moveCursorPos; S2DE::Vec2 arenaCenter = { 23, 11 }; -//S2DE::Vec2* 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 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 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 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; -- 2.20.1