add very first basic damage calculation
authorStan_Lewry <stanley.jml@gmail.com>
Mon, 30 Sep 2024 17:40:35 +0000 (18:40 +0100)
committerStan_Lewry <stanley.jml@gmail.com>
Mon, 30 Sep 2024 17:40:35 +0000 (18:40 +0100)
combat.cpp

index 5cb2ec3..3d8caa7 100644 (file)
@@ -33,7 +33,8 @@ struct Character {
        int currentMP;
        int maxMP;
        int attack;
-       float agility; // to determine move order
+       int defense;
+       int agility; // to determine move order
        float moveDist;
 
        // animation stuff?
@@ -346,10 +347,10 @@ void initCombatScene()
        player.agility = 10.0f;
        player.moveDist = 3.0f;
        player.texture = player_forward_texture;
-       player.position = { arenaCenter.x, arenaCenter.y + 2 };
+       player.position = { arenaCenter.x + 0.5f, arenaCenter.y + 2 };
        player.attack = 5;
-
-
+       player.defense = 5;
+       
        Character monica;
        monica.allied = true;
        monica.name = "Monica";
@@ -360,9 +361,10 @@ void initCombatScene()
        monica.agility = 8.0f;
        monica.moveDist = 6.0f;
        monica.texture = monica_texture;
-       monica.position = { player.position.x - 2, player.position.y };
+       monica.position = { arenaCenter.x - 0.5f, arenaCenter.y + 2 };
        monica.attack = 6;
        monica.basicAttackType = SLASH;
+       monica.defense = 5;
 
        Character enemy;
        enemy.allied = false;
@@ -376,6 +378,7 @@ void initCombatScene()
        enemy.texture = bird;
        enemy.position = { arenaCenter.x, arenaCenter.y - 2 };
        enemy.attack = 2;
+       enemy.defense = 2;
 
        Character frog;
        frog.allied = false;
@@ -387,6 +390,7 @@ void initCombatScene()
        frog.texture = frog_texture;
        frog.position = { arenaCenter.x - 1, arenaCenter.y - 2 };
        frog.attack = 2;
+       frog.defense = 2;
 
        combatants.push_back(player);
        combatants.push_back(monica);
@@ -496,9 +500,7 @@ void actionSelectState(double delta) {
                animFrame += 1;
                if (animFrame > 4) animFrame = 0;
        }
-       
-       
-       
+
        SDL_RenderClear(renderer);
        renderCombat();
        renderUIFull();
@@ -540,6 +542,11 @@ void playerMoveActionState(double delta) {
                if (inputState.down) {
                        newY += cursorSpeed;
                }
+               
+               if (inputState.escape) {
+                       inputState.escape = false;
+                       currentCombatState = ACTION_SELECT;
+               }
 
                if (inputState.rtrn) {
                        inputState.rtrn = false;
@@ -710,7 +717,11 @@ void doAttack(double delta) {
                        if (animFrame > anim.numFrames) {
                                // anim is complete, apply damage and move on.
                                // reset timers etc.
-                               target->currentHP -= activeCombatant->attack;
+
+                               // minimum attack of 1
+                               // ((base attack stat + weapon bonus + attack type bonus) / (Def + 100 / 100)) + 1;
+                               int damage = (activeCombatant->attack - (target->defense / 2) / 2);
+                               target->currentHP -= damage;
 
                                if (target->currentHP <= 0) {
                                        target->alive = false;