generated from sigonasr2/CPlusPlusProjectTemplate
Damage numbers implemented
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
06418582fb
commit
fba1aba9e9
Binary file not shown.
62
main.cpp
62
main.cpp
@ -448,6 +448,15 @@ class Map{
|
||||
}
|
||||
};
|
||||
|
||||
class DamageNumber{
|
||||
public:
|
||||
int damage; //If it's negative then it's a healing number.
|
||||
vd2d pos;
|
||||
int timer;
|
||||
DamageNumber(int damage,vd2d pos,int timer=90)
|
||||
:damage(damage),pos(pos),timer(timer){}
|
||||
};
|
||||
|
||||
class SeasonI : public PixelGameEngine
|
||||
{
|
||||
public:
|
||||
@ -535,6 +544,7 @@ public:
|
||||
std::map<int,Object*> OBJ_INFO;
|
||||
|
||||
std::vector<Particle*> PARTICLES;
|
||||
std::vector<DamageNumber*> DAMAGE_NUMBERS;
|
||||
|
||||
Effect*CURRENT_EFFECT=nullptr;
|
||||
|
||||
@ -661,13 +671,25 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
|
||||
void updateGame(){
|
||||
frameCount++;
|
||||
for (auto&obj:OBJECTS) {
|
||||
for (auto obj:OBJECTS) {
|
||||
if (obj->animationSpd!=0&&obj->frameCount++>obj->animationSpd) {
|
||||
obj->frameCount=0;
|
||||
obj->frameIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<DAMAGE_NUMBERS.size();i++) {
|
||||
DamageNumber*numb=DAMAGE_NUMBERS[i];
|
||||
if (numb->timer>0) {
|
||||
numb->pos.y-=(numb->timer/180.0F);
|
||||
numb->timer--;
|
||||
} else {
|
||||
delete numb;
|
||||
DAMAGE_NUMBERS.erase(DAMAGE_NUMBERS.begin()+i--);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<PARTICLES.size();i++) {
|
||||
if (!PARTICLES[i]->update()) {
|
||||
delete PARTICLES[i];
|
||||
@ -1589,6 +1611,13 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto numb:DAMAGE_NUMBERS) {
|
||||
vd2d textSize = GetTextSizeProp((numb->damage>=0)?"-"+std::to_string(numb->damage):"+"+std::to_string(-numb->damage));
|
||||
DrawStringPropDecal(numb->pos-cameraPos-textSize/2,(numb->damage>=0)?"-"+std::to_string(numb->damage):"+"+std::to_string(-numb->damage),(numb->damage>=0)?RED:GREEN,{1,2});
|
||||
vd2d shadowOffset={1,1};
|
||||
DrawStringPropDecal(numb->pos+shadowOffset-cameraPos-textSize/2,(numb->damage>=0)?"-"+std::to_string(numb->damage):"+"+std::to_string(-numb->damage),(numb->damage>=0)?RED:GREEN,{1,2});
|
||||
DrawStringPropDecal(numb->pos-cameraPos-textSize/2,(numb->damage>=0)?"-"+std::to_string(numb->damage):"+"+std::to_string(-numb->damage),Pixel(255,255,255,sin((M_PI*frameCount)/30)*128),{1,2});
|
||||
}
|
||||
if (messageBoxVisible) {
|
||||
SetDrawTarget(layer::INTERFACE);
|
||||
DrawDialogBox({1,1},{WIDTH/2,HEIGHT/4},Pixel(70, 33, 105,128),Pixel(62, 54, 69,128),Pixel(185, 148, 255,128));
|
||||
@ -2897,7 +2926,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
StartEffect(eff);
|
||||
}
|
||||
}
|
||||
if (CURRENT_EFFECT==nullptr&&BATTLE_ANIMATION_TIMER==90||CURRENT_EFFECT!=nullptr&&BATTLE_ANIMATION_TIMER>CURRENT_EFFECT->maxLifeTime-30) {
|
||||
if (CURRENT_EFFECT==nullptr&&BATTLE_ANIMATION_TIMER==90||CURRENT_EFFECT!=nullptr&&BATTLE_ANIMATION_TIMER>CURRENT_EFFECT->maxLifeTime) {
|
||||
if (CURRENT_TURN<0) {
|
||||
if (PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->friendly) {
|
||||
if (PARTY_MEMBER_STATS[-PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget-1]->GetHP()>0) {
|
||||
@ -2905,8 +2934,13 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
((PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->randomDmg>0)?rand()%PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->randomDmg:0)
|
||||
+PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->baseAtk;
|
||||
for (auto&ent:GetEntitiesInRange(PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove)) {
|
||||
if (ent->GetHP()>0) {
|
||||
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << ent->obj->name << " recovering " << healAmt << " health.\n";
|
||||
ent->AddHP(healAmt);
|
||||
int memberID = getMemberIDComparingObject(ent->obj);
|
||||
vi2d box = {(128-32*PARTY_MEMBER_COUNT)+memberID*64+29,170};
|
||||
DAMAGE_NUMBERS.push_back(new DamageNumber(-healAmt,box+cameraPos));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << PARTY_MEMBER_OBJ[-PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget-1]->name << " but it failed.\n";
|
||||
@ -2918,12 +2952,15 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
+PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->baseAtk;
|
||||
//Enemies have their health directly set.
|
||||
for (auto&ent:GetEntitiesInRange(PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget,PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove)) {
|
||||
if (ent->GetHP()>0) {
|
||||
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
||||
ent->_SetDirectHP(ent->GetHP()-dmgAmt);
|
||||
ent->obj->blinkFrames=35;
|
||||
if (ent->GetHP()<=0) {
|
||||
ent->obj->dead=true;
|
||||
}
|
||||
DAMAGE_NUMBERS.push_back(new DamageNumber(dmgAmt,ent->obj->GetPosWithOrigin()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << PARTY_MEMBER_OBJ[-CURRENT_TURN-1]->name << " uses " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->name << " " << PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove->grade << " on " << BATTLE_ENCOUNTER->objs[PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedTarget]->obj->name << " but it failed.\n";
|
||||
@ -2936,8 +2973,11 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
((rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg>0)?rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg:0)
|
||||
+BATTLE_ENCOUNTER->objs[CURRENT_TURN]->baseAtk;
|
||||
for (auto&ent:GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove)) {
|
||||
if (ent->GetHP()>0) {
|
||||
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << ent->obj->name << " recovering " << healAmt << " health.\n";
|
||||
ent->AddHP(healAmt);
|
||||
DAMAGE_NUMBERS.push_back(new DamageNumber(-healAmt,ent->obj->GetPosWithOrigin()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << BATTLE_ENCOUNTER->objs[BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget]->obj->name << " but it failed.\n";
|
||||
@ -2948,6 +2988,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
((rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg>0)?rand()%BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->randomDmg:0)
|
||||
+BATTLE_ENCOUNTER->objs[CURRENT_TURN]->baseAtk;
|
||||
for (auto&ent:GetEntitiesInRange(BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget,BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove)) {
|
||||
if (ent->GetHP()>0) {
|
||||
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << ent->obj->name << " dealing " << dmgAmt << " health.\n";
|
||||
ent->SubtractHP(dmgAmt);
|
||||
if (ent->GetTargetHP()<0) {
|
||||
@ -2955,6 +2996,10 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
} else {
|
||||
BATTLE_HIT_SCREENSHAKE=25;
|
||||
}
|
||||
int memberID = getMemberIDComparingObject(ent->obj);
|
||||
vi2d box = {(128-32*PARTY_MEMBER_COUNT)+memberID*64+29,170};
|
||||
DAMAGE_NUMBERS.push_back(new DamageNumber(dmgAmt,box+cameraPos));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::cout << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->obj->name << " uses " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->name << " " << BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedMove->grade << " on " << PARTY_MEMBER_OBJ[-BATTLE_ENCOUNTER->objs[CURRENT_TURN]->selectedTarget-1]->name << " but it failed.\n";
|
||||
@ -2962,7 +3007,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
}
|
||||
}
|
||||
} else
|
||||
if (CURRENT_EFFECT==nullptr&&BATTLE_ANIMATION_TIMER>120||CURRENT_EFFECT!=nullptr&&BATTLE_ANIMATION_TIMER>CURRENT_EFFECT->maxLifeTime) {
|
||||
if (CURRENT_EFFECT==nullptr&&BATTLE_ANIMATION_TIMER>120||CURRENT_EFFECT!=nullptr&&BATTLE_ANIMATION_TIMER>CURRENT_EFFECT->maxLifeTime+30) {
|
||||
//Turn's done!
|
||||
if (CURRENT_TURN<0) {
|
||||
PARTY_MEMBER_STATS[PARTY_MEMBER_ID[-CURRENT_TURN-1]]->selectedMove=nullptr;
|
||||
@ -3202,6 +3247,17 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
CURRENT_EFFECT=eff;
|
||||
eff->create(PARTICLES);
|
||||
}
|
||||
|
||||
int getMemberIDComparingObject(Object*obj) {
|
||||
int memberID=0;
|
||||
for (int i=0;i<PARTY_MEMBER_COUNT;i++) {
|
||||
if (obj==PARTY_MEMBER_STATS[PARTY_MEMBER_ID[i]]->obj) {
|
||||
memberID=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return memberID;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user