diff --git a/C++ProjectTemplate b/C++ProjectTemplate index e06b0f1..12d1547 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 4856f31..a94610a 100644 --- a/main.cpp +++ b/main.cpp @@ -347,9 +347,10 @@ namespace Battle{ } class Entity{ - public: + private: int HP=0; int targetHP=0; + public: int maxHP=0; int PP=0; int targetPP=0; @@ -378,6 +379,30 @@ class Entity{ this->targetHP=HP; this->targetPP=PP; } + //Get the HP that the rolling counter is moving towards. + int GetTargetHP() { + return targetHP; + } + //Gets the current actual health of the target. + int GetHP() { + return HP; + } + //Sets the rolling counter target to this health value. + void SetTargetHP(int hp) { + targetHP=hp; + } + //Subtracts from the rolling counter target from this health value. + void SubtractHP(int hp) { + targetHP-=hp; + } + //Adds to the rolling counter target from this health value. + void AddHP(int hp) { + targetHP=std::clamp(HP+hp,0,maxHP); + } + //THIS IS FOR SPECIAL USE CASES ONLY! Normally you want to touch the rolling counter amount instead using SetTargetHP()! + void _SetDirectHP(int hp) { + HP=hp; + } }; class Encounter{ @@ -391,7 +416,7 @@ class Encounter{ :id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){} bool IsEncounterAlive() { for (int i=0;iHP>0) { + if (objs[i]->GetHP()>0) { return true; } } @@ -661,15 +686,15 @@ goes on a very long time, I hope you can understand this is only for testing pur for (int j=0;j<3;j++) { switch (j) { case 0:{ - player_rollhp_display[i][j]=member->HP%10; + player_rollhp_display[i][j]=member->GetHP()%10; player_rollpp_display[i][j]=member->PP%10; }break; case 1:{ - player_rollhp_display[i][j]=member->HP/10%10; + player_rollhp_display[i][j]=member->GetHP()/10%10; player_rollpp_display[i][j]=member->PP/10%10; }break; case 2:{ - player_rollhp_display[i][j]=member->HP/100%10; + player_rollhp_display[i][j]=member->GetHP()/100%10; player_rollpp_display[i][j]=member->PP/100%10; }break; } @@ -682,11 +707,11 @@ goes on a very long time, I hope you can understand this is only for testing pur case BattleState::WAIT:{ for (int i=0;iHP>std::clamp(member->targetHP,0,member->targetHP)) { + if (member->GetHP()>std::clamp(member->GetTargetHP(),0,member->GetTargetHP())) { if (player_rollhp_counter[i][0]<=0) { player_rollhp_display[i][0]--; player_rollhp_counter[i][0]=13; - member->HP--; + member->_SetDirectHP(member->GetHP()-1); if (player_rollhp_display[i][0]<0) { player_rollhp_display[i][0]=9; player_rollhp_counter[i][0]=13; @@ -701,11 +726,11 @@ goes on a very long time, I hope you can understand this is only for testing pur } } if (player_rollhp_counter[i][0]>0) { - if (member->targetHP<-member->maxHP) { - player_rollhp_counter[i][0]-=HEALTH_ROLLING_SPEED+(member->maxHP-member->targetHP)/10; + if (member->GetTargetHP()<-member->maxHP) { + player_rollhp_counter[i][0]-=HEALTH_ROLLING_SPEED+(member->maxHP-member->GetTargetHP())/10; } else - if (member->targetHP<0) { - player_rollhp_counter[i][0]-=HEALTH_ROLLING_SPEED+(member->maxHP-member->targetHP)/20; + if (member->GetTargetHP()<0) { + player_rollhp_counter[i][0]-=HEALTH_ROLLING_SPEED+(member->maxHP-member->GetTargetHP())/20; } else { player_rollhp_counter[i][0]-=HEALTH_ROLLING_SPEED; } @@ -717,11 +742,11 @@ goes on a very long time, I hope you can understand this is only for testing pur player_rollhp_counter[i][2]--; } } else - if (member->HPtargetHP) { + if (member->GetHP()GetTargetHP()) { if (player_rollhp_counter[i][0]>=0) { player_rollhp_display[i][0]++; player_rollhp_counter[i][0]=-13; - member->HP++; + member->_SetDirectHP(member->GetHP()+1); if (player_rollhp_display[i][0]>9) { player_rollhp_display[i][0]=0; player_rollhp_counter[i][0]=-13; @@ -825,6 +850,9 @@ goes on a very long time, I hope you can understand this is only for testing pur //Enemy picks a random move from the movelist. And a random target. BATTLE_ENCOUNTER->objs[i]->selectedMove=BATTLE_ENCOUNTER->objs[i]->moveSet[rand()%BATTLE_ENCOUNTER->objs[i]->moveSet.size()]; BATTLE_ENCOUNTER->objs[i]->channelTimeRemaining=BATTLE_ENCOUNTER->objs[i]->selectedMove->channelTime; + do { + BATTLE_ENCOUNTER->objs[i]->selectedTarget=-rand()%PARTY_MEMBER_COUNT-1; + } while (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-BATTLE_ENCOUNTER->objs[i]->selectedTarget-1]]->GetHP()<=0); printf(" %s chose move %s.\n",BATTLE_ENCOUNTER->objs[i]->obj->name.c_str(),BATTLE_ENCOUNTER->objs[i]->selectedMove->name.c_str()); BATTLE_STATE=BattleState::WAIT; BATTLE_SELECTION_CURSOR=0; @@ -1355,14 +1383,14 @@ goes on a very long time, I hope you can understand this is only for testing pur //Set Default Target. if (BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]]->friendly) { for (int i=0;iHP>0||getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])) { + if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[i]]->GetHP()>0||getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])) { SELECTED_TARGET=-i-1; break; } } } else { for (int i=0;iobjs.size();i++) { - if (BATTLE_ENCOUNTER->objs[i]->HP>0) { + if (BATTLE_ENCOUNTER->objs[i]->GetHP()>0) { SELECTED_TARGET=i; break; } @@ -1379,14 +1407,14 @@ goes on a very long time, I hope you can understand this is only for testing pur if (SELECTED_TARGET==0) { SELECTED_TARGET=-4; } - } while (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-SELECTED_TARGET-1]]->HP<=0&&!getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])); + } while (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-SELECTED_TARGET-1]]->GetHP()<=0&&!getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])); } else { do { SELECTED_TARGET--; if (SELECTED_TARGET<0) { SELECTED_TARGET=BATTLE_ENCOUNTER->objs.size()-1; } - } while (BATTLE_ENCOUNTER->objs[SELECTED_TARGET]->HP<=0); + } while (BATTLE_ENCOUNTER->objs[SELECTED_TARGET]->GetHP()<=0); } } if (RightPressed()) { @@ -1396,11 +1424,11 @@ goes on a very long time, I hope you can understand this is only for testing pur if (SELECTED_TARGET<-PARTY_MEMBER_COUNT) { SELECTED_TARGET=-1; } - } while (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-SELECTED_TARGET-1]]->HP<=0&&!getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])); + } while (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-SELECTED_TARGET-1]]->GetHP()<=0&&!getProperty(Property::REVIVE,BATTLE_MOVELIST_DISPLAY[POWER_SELECTION_CURSOR[-CURRENT_TURN-1]][POWER_GRADE_CURSOR[-CURRENT_TURN-1]])); } else { do { SELECTED_TARGET=(SELECTED_TARGET+1)%BATTLE_ENCOUNTER->objs.size(); - } while (BATTLE_ENCOUNTER->objs[SELECTED_TARGET]->HP<=0); + } while (BATTLE_ENCOUNTER->objs[SELECTED_TARGET]->GetHP()<=0); } } if (UpPressed()) { @@ -1793,7 +1821,7 @@ goes on a very long time, I hope you can understand this is only for testing pur } } DrawStringDecal(hpTextPos,"HP",olc::BLACK); - DrawRollingCounter(hpTextPos,member->HP,player_rollhp_display[i],player_rollhp_counter[i]); + DrawRollingCounter(hpTextPos,member->GetHP(),player_rollhp_display[i],player_rollhp_counter[i]); const olc::vi2d mpTextPos = {box.x+5,hpTextPos.y+17}; for (int x=-1;x<=1;x++) { for (int y=-1;y<=1;y++) { @@ -2694,7 +2722,7 @@ goes on a very long time, I hope you can understand this is only for testing pur for (int i=0;iobjs.size();i++) { Entity*ent=ENCOUNTER_LIST[id]->objs[i]; Object*newObj=new Object(ent->obj->id,ent->obj->name,ent->obj->GetPos(),ent->obj->spr,ent->obj->GetScale(),ent->obj->color,ent->obj->animationSpd,ent->obj->temp); - ents.push_back(new Entity(newObj,ent->HP,ent->maxHP,ent->PP,ent->maxPP,ent->baseAtk,ent->resistances,ent->speed,ent->moveSet,ent->damageReduction,ent->smart,ent->dumb)); + ents.push_back(new Entity(newObj,ent->GetHP(),ent->maxHP,ent->PP,ent->maxPP,ent->baseAtk,ent->resistances,ent->speed,ent->moveSet,ent->damageReduction,ent->smart,ent->dumb)); } Encounter*data=new Encounter(id,pos,ENCOUNTER_LIST[id]->playerPos,ents,chance); data->chance=chance; @@ -2702,7 +2730,7 @@ goes on a very long time, I hope you can understand this is only for testing pur for (int i=0;iobjs.size();i++) { data->objs[i]->obj->enc=true; if (!successful) { - data->objs[i]->HP=0; + data->objs[i]->_SetDirectHP(0); data->objs[i]->obj->dead=true; } }