improved combat ui. temporarily disable enemy turn for debug
authorStan_Lewry <stanley.jml@gmail.com>
Fri, 30 Aug 2024 17:35:35 +0000 (18:35 +0100)
committerStan_Lewry <stanley.jml@gmail.com>
Fri, 30 Aug 2024 17:35:35 +0000 (18:35 +0100)
combat.cpp

index c2611d6..755988d 100644 (file)
@@ -410,7 +410,7 @@ void actionSelectState(double delta) {
                        break;\r
                case 1: // attack selected\r
                        if (activeCombatant->canAttack) {\r
-                               // filter the targets\r
+                               // filter the targets - Have to do it here too in case the player attacks without moving?\r
                                targets.clear();\r
                                for (auto& c : combatants) {\r
                                        if (!c.allied && c.alive) {\r
@@ -489,6 +489,19 @@ void playerMoveActionState(double delta) {
 \r
        }\r
 \r
+\r
+       // compute characters in melee range\r
+       targets.clear();\r
+       for (auto& c : combatants) {\r
+               if (!c.allied && c.alive) {\r
+                       float dist = distance(moveCursorPos, c.position);\r
+                       if (dist <= activeCombatant->basicAttackRange) {\r
+                               targets.push_back(&c);\r
+                       }\r
+               }\r
+       }\r
+\r
+\r
        SDL_RenderClear(renderer);\r
 \r
        renderTilemap(arena, arenaWidth, arenaHeight, combatCam);\r
@@ -506,9 +519,18 @@ void playerMoveActionState(double delta) {
        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);\r
        SDL_RenderDrawLine(renderer, playerCenterScreen.x, playerCenterScreen.y, lineEndPos.x, lineEndPos.y);\r
 \r
+       // render lines to targets in range\r
+       SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);\r
+       for (auto t : targets) {\r
+               S2DE::Vec2<float> targetCenter = { t->position.x + 0.5, t->position.y + 0.5 };\r
+               S2DE::Vec2<int> targetCenterScreen = S2DE::worldToScreenPoint(&combatCam, &targetCenter, 64, WINDOW_WIDTH, WINDOW_HEIGHT);\r
+               SDL_RenderDrawLine(renderer, lineEndPos.x, lineEndPos.y, targetCenterScreen.x, targetCenterScreen.y);\r
+       }\r
+\r
+\r
        renderCombatants();\r
 \r
-       S2DE::Rect cursorDRect = S2DE::worldToScreenRect(&combatCam, &moveCursorPos, 4, WINDOW_WIDTH, WINDOW_HEIGHT, 16, 16);\r
+       S2DE::Rect cursorDRect = S2DE::worldToScreenRect(&combatCam, &moveCursorPos, 2, WINDOW_WIDTH, WINDOW_HEIGHT, 32, 32);\r
        S2DE::renderTexture(&renderer, &arrowSprite, NULL, &cursorDRect);\r
 \r
        renderTilemap(fogLayer, arenaWidth, arenaHeight, combatCam); // draw the fog layer\r
@@ -557,18 +579,9 @@ void selectAttackTarget(double delta) {
 \r
        renderTilemap(arena, arenaWidth, arenaHeight, combatCam);\r
 \r
-\r
-       S2DE::Vec2<float> playerCenterWorld = { activeCombatant->position.x + 0.5, activeCombatant->position.y + 0.5 };\r
-       S2DE::Vec2<int> playerCenterScreen = S2DE::worldToScreenPoint(&combatCam, &playerCenterWorld, 64, WINDOW_WIDTH, WINDOW_HEIGHT);\r
-\r
-       S2DE::renderCircle(&renderer, playerCenterScreen, (activeCombatant->basicAttackRange) * 64, { 255, 0, 0, 125 });\r
-\r
-\r
        renderCombatants();\r
-       \r
 \r
        // render the little red arrow above all valid targets\r
-       //for (auto target : targets) {\r
        if (targets.size() > 0) {\r
                S2DE::Vec2<float> arrowPos = targets.at(currentTargetIdx)->position;\r
 \r
@@ -576,7 +589,6 @@ void selectAttackTarget(double delta) {
                S2DE::Rect arrowDRect = S2DE::worldToScreenRect(&combatCam, &arrowPos, 2, WINDOW_WIDTH, WINDOW_HEIGHT, 32, 32);\r
                S2DE::renderTexture(&renderer, &indicatorRedSprite, NULL, &arrowDRect);\r
        }\r
-       //}\r
        \r
 \r
        renderTilemap(fogLayer, arenaWidth, arenaHeight, combatCam); // draw the fog layer\r
@@ -703,7 +715,7 @@ void determineNextTurnState(double delta) {
                        currentCombatState = ACTION_SELECT;\r
                }\r
                else {\r
-                       currentCombatState = ENEMY_MOVE;\r
+                       //currentCombatState = ENEMY_MOVE;\r
                }\r
        }\r
 \r