From: Stan_Lewry Date: Fri, 30 Aug 2024 20:34:54 +0000 (+0100) Subject: do not allow characters to occupy same space as other characters X-Git-Url: https://stanlewry.com/index.cgi?a=commitdiff_plain;h=377b372f7cf1702de8e4c43defdcb1d7c98d3d10;p=dragonsurvivors.git do not allow characters to occupy same space as other characters --- diff --git a/combat.cpp b/combat.cpp index a69026f..6fc0f39 100644 --- a/combat.cpp +++ b/combat.cpp @@ -27,7 +27,7 @@ struct Character { // how to handle "moves" S2DE::Vec2 combatMoveDestination = { 0.0f, 0.0f }; - int basicAttackRange = 1.0f; + int basicAttackRange = 1.5f; bool canMove = true; bool canAttack = true; @@ -278,6 +278,23 @@ void renderCombatants() { S2DE::renderTexture(&renderer, &indicatorSprite, NULL, &arrowDRect); } +bool checkCharacterCollision(S2DE::Vec2 position) { + for (auto c : combatants) { + if (c.name != activeCombatant->name) { // this sucks + float charMinX = c.position.x; + float charMaxX = c.position.x + 1.0; + float charMinY = c.position.y; + float charMaxY = c.position.y + 1.0; + + if (position.x > charMinX && position.x < charMaxX + && position.y > charMinY && position.y < charMaxY) { + return true; + } + } + } + return false; +} + void initCombatScene() { // I think all resources should be initialized and cleaned up in the globals tbh @@ -479,11 +496,13 @@ void playerMoveActionState(double delta) { } if (distance({ moveCursorPos.x, newY }, player.position) <= player.moveDist - && checkCollisionPoint({ moveCursorPos.x + 0.5f, newY + 0.5f }, arena) == false) { + && checkCollisionPoint({ moveCursorPos.x + 0.5f, newY + 0.5f }, arena) == false + && checkCharacterCollision({moveCursorPos.x + 0.5f, newY + 0.5f}) == false) { moveCursorPos.y = newY; } if (distance({ newX, moveCursorPos.y }, player.position) <= player.moveDist - && checkCollisionPoint({ newX + 0.5f, moveCursorPos.y + 0.5f }, arena) == false) { + && checkCollisionPoint({ newX + 0.5f, moveCursorPos.y + 0.5f }, arena) == false + && checkCharacterCollision({ newX + 0.5f, moveCursorPos.y + 0.5f }) == false) { moveCursorPos.x = newX; }