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
\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
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
\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
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
currentCombatState = ACTION_SELECT;\r
}\r
else {\r
- currentCombatState = ENEMY_MOVE;\r
+ //currentCombatState = ENEMY_MOVE;\r
}\r
}\r
\r