Refactored all entity references to entity pointer references

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 25fbed408d
commit 3106bfb1ce
  1. 87
      SeasonsOfLoneliness.cpp
  2. BIN
      Seasons_of_Loneliness

@ -161,7 +161,7 @@ class Entity{
class Encounter{
public:
int x,y;
std::vector<Entity> entities;
std::vector<Entity*> entities;
std::vector<int> turnOrder;
};
@ -228,7 +228,6 @@ public:
Animation POWER_METEOR_SHOWER_ANIMATION;
Animation POWER_METEOR_STORM_ANIMATION;
Animation POWER_SNOWSTORM_ANIMATION;
std::vector<Entity> entityList;
WEATHER_POWER*HAILSTORM = new WEATHER_POWER("Hailstorm","Causes a flurry of hard cold rocks to be unleashed in target area. 60+30d",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,60,30,160,Pixel(72, 160, 212,255),Pixel(93, 161, 163,255),120);
WEATHER_POWER*HURRICANE = new WEATHER_POWER("Hurricane","Causes heavy winds, scattering seeds, heavy rain. 20+10d",&POWER_HURRICANE_ANIMATION,&POWER_HURRICANE_ANIMATION,20,10,200,Pixel(99, 148, 132,255),Pixel(121, 132, 140,255),120);
WEATHER_POWER*METEOR_RAIN = new WEATHER_POWER("Meteor Rain","Causes space rocks to fall on target area. 50+50d",&POWER_METEOR_SHOWER_ANIMATION,&POWER_METEOR_SHOWER_ANIMATION,50,50,96,Pixel(96, 86, 153,255),Pixel(170, 103, 201,255),120);
@ -257,6 +256,7 @@ public:
int BATTLE_CURRENT_TURN_ENTITY=-1;
int CURRENT_ENCOUNTER_IND=-1;
std::vector<DisplayNumber*> BATTLE_DISPLAY_NUMBERS;
bool PLAYER_TURN_COMPLETE=false;
std::vector<WEATHER_POWER*>MOVESET_SPIDEY;
@ -368,9 +368,9 @@ public:
MOVESET_SPIDEY.push_back(SEED_STORM);
MOVESET_SPIDEY.push_back(AVALANCHE);
ENCOUNTER_SPIDEY_1.entities.push_back(*new Entity(SPIDEY_DECAL,"Spidey",2,3,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.entities.push_back(*new Entity(SPIDEY_DECAL,"Spidey",4,4,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.entities.push_back(*new Entity(SPIDEY_DECAL,"Spidey",6,2,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.entities.push_back(new Entity(SPIDEY_DECAL,"Spidey",2,3,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.entities.push_back(new Entity(SPIDEY_DECAL,"Spidey",4,4,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.entities.push_back(new Entity(SPIDEY_DECAL,"Spidey",6,2,80,80,MOVESET_SPIDEY));
ENCOUNTER_SPIDEY_1.x=79;
ENCOUNTER_SPIDEY_1.y=47;
ENCOUNTERS.push_back(ENCOUNTER_SPIDEY_1);
@ -425,10 +425,10 @@ public:
switch (BATTLE_STATE) {
case battle::PLAYER_SELECTION:{
BATTLE_STATE=battle::PLAYER_TARGET_SELECTION;
if (PLAYER_SELECTED_TARGET==-1||CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].hp<=0) {
if (PLAYER_SELECTED_TARGET==-1||CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp<=0) {
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity ent = CURRENT_ENCOUNTER.entities[i];
if (!ent.ally&&ent.hp>0) {
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (!ent->ally&&ent->hp>0) {
PLAYER_SELECTED_TARGET=i;
break;
}
@ -440,40 +440,41 @@ public:
BATTLE_CARD_SELECTION->playerOwnCount--;
BATTLE_STATE=battle::ENEMY_SELECTION;
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
if (CURRENT_ENCOUNTER.entities[i].hp>0) {
CURRENT_ENCOUNTER.entities[i].selectedMove=CURRENT_ENCOUNTER.entities[i].moveSet[rand()%CURRENT_ENCOUNTER.entities[i].moveSet.size()];
CURRENT_ENCOUNTER.entities[i].turnComplete=false;
if (CURRENT_ENCOUNTER.entities[i]->hp>0) {
CURRENT_ENCOUNTER.entities[i]->selectedMove=CURRENT_ENCOUNTER.entities[i]->moveSet[rand()%CURRENT_ENCOUNTER.entities[i]->moveSet.size()];
CURRENT_ENCOUNTER.entities[i]->turnComplete=false;
}
}
PLAYER_TURN_COMPLETE=false;
BATTLE_STATE=battle::MOVE_RESOLUTION;
//Seed Storm has prio.
if (BATTLE_CARD_SELECTION_IND!=-1&&BATTLE_CARD_SELECTION->name.compare("Seed Storm")==0) {
if (!PLAYER_TURN_COMPLETE&&BATTLE_CARD_SELECTION->name.compare("Seed Storm")==0) {
turnOrder.push(-1);
BATTLE_CARD_SELECTION_IND=-1;
PLAYER_TURN_COMPLETE=true;
}
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
if (CURRENT_ENCOUNTER.entities[i].hp>0&&!CURRENT_ENCOUNTER.entities[i].turnComplete&&
CURRENT_ENCOUNTER.entities[i].selectedMove->name.compare("Seed Storm")==0) {
if (CURRENT_ENCOUNTER.entities[i]->hp>0&&!CURRENT_ENCOUNTER.entities[i]->turnComplete&&
CURRENT_ENCOUNTER.entities[i]->selectedMove->name.compare("Seed Storm")==0) {
turnOrder.push(i);
CURRENT_ENCOUNTER.entities[i].turnComplete=true;
CURRENT_ENCOUNTER.entities[i]->turnComplete=true;
}
}
//Otherwise, every enemy has a chance to go before the player unless they are slowed, then they always go after.
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent = &CURRENT_ENCOUNTER.entities[i];
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (ent->hp>0&&!ent->turnComplete&&
!ent->slowed&&rand()%2==0) {
turnOrder.push(i);
ent->turnComplete=true;
}
}
if (BATTLE_CARD_SELECTION_IND!=-1) {
if (!PLAYER_TURN_COMPLETE) {
turnOrder.push(-1);
BATTLE_CARD_SELECTION_IND=-1;
PLAYER_TURN_COMPLETE=true;
}
//Finally, any enemies that haven't gone will now go.
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent = &CURRENT_ENCOUNTER.entities[i];
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (ent->hp>0&&!ent->turnComplete) {
turnOrder.push(i);
ent->turnComplete=true;
@ -547,7 +548,7 @@ public:
if (GetKey(D).bPressed||GetKey(RIGHT).bPressed||GetKey(NP6).bPressed) {
while (true) {
PLAYER_SELECTED_TARGET=(PLAYER_SELECTED_TARGET+1)%CURRENT_ENCOUNTER.entities.size();
if (CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].hp>0) {
if (CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp>0) {
break;
}
}
@ -561,7 +562,7 @@ public:
if (--PLAYER_SELECTED_TARGET<0) {
PLAYER_SELECTED_TARGET=CURRENT_ENCOUNTER.entities.size()-1;
}
if (CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].hp>0) {
if (CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp>0) {
break;
}
}
@ -815,18 +816,18 @@ public:
if (BATTLE_CURRENT_TURN_ENTITY==-1) {
ref=BATTLE_CARD_SELECTION;
} else {
ref=CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].selectedMove;
ref=CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->selectedMove;
}
if (EFFECT_TIMER==30&&ref->name.compare("Seed Storm")==0) {
if (BATTLE_CURRENT_TURN_ENTITY==-1) {
effectRadius({PLAYER_COORDS[0],PLAYER_COORDS[1]},ref,true);
} else {
effectRadius({CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].x+CURRENT_ENCOUNTER.x,CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].y+CURRENT_ENCOUNTER.y},ref,false);
effectRadius({CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->x+CURRENT_ENCOUNTER.x,CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->y+CURRENT_ENCOUNTER.y},ref,false);
}
} else
if (EFFECT_TIMER==ref->effectTime-10){
if (BATTLE_CURRENT_TURN_ENTITY==-1) {
effectRadius({CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].x+CURRENT_ENCOUNTER.x,CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].y+CURRENT_ENCOUNTER.y},ref,true);
effectRadius({CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->x+CURRENT_ENCOUNTER.x,CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->y+CURRENT_ENCOUNTER.y},ref,true);
} else {
effectRadius({PLAYER_COORDS[0],PLAYER_COORDS[1]},ref,false);
}
@ -843,7 +844,7 @@ public:
if (turnOrder.empty()) {
bool allDead=true;
for (auto&ent:CURRENT_ENCOUNTER.entities) {
if (ent.hp>0) {
if (ent->hp>0) {
allDead=false;
break;
}
@ -867,7 +868,7 @@ public:
break;
}
} else {
if (CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].hp<=0) {
if (CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->hp<=0) {
break;
}
}
@ -1053,8 +1054,8 @@ public:
}break;
case battle::PLAYER_TARGET_SELECTION:{
if (PLAYER_SELECTED_TARGET>=0) {
DrawWrappedText({5,5},"Target "+CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].name+" "+(char)('A'+PLAYER_SELECTED_TARGET)+" with "+BATTLE_CARD_SELECTION->name,WIDTH-8,BLACK,{2,2});
DrawWrappedText({4,4},"Target "+CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].name+" "+(char)('A'+PLAYER_SELECTED_TARGET)+" with "+BATTLE_CARD_SELECTION->name,WIDTH-8,WHITE,{2,2});
DrawWrappedText({5,5},"Target "+CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->name+" "+(char)('A'+PLAYER_SELECTED_TARGET)+" with "+BATTLE_CARD_SELECTION->name,WIDTH-8,BLACK,{2,2});
DrawWrappedText({4,4},"Target "+CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->name+" "+(char)('A'+PLAYER_SELECTED_TARGET)+" with "+BATTLE_CARD_SELECTION->name,WIDTH-8,WHITE,{2,2});
DrawStringDecal({WIDTH-GetTextSize("<UP> Back").x-1,HEIGHT-GetTextSize("<UP> Back").y-1},"<UP> Back",BLACK,{1,1});
DrawStringDecal({WIDTH-GetTextSize("<UP> Back").x-2,HEIGHT-GetTextSize("<UP> Back").y-2},"<UP> Back",GREEN,{1,1});
}
@ -1063,24 +1064,24 @@ public:
if (BATTLE_CURRENT_TURN_ENTITY==-1) {
DrawWrappedText({4,4},"Player uses "+BATTLE_CARD_SELECTION->name,WIDTH-8,WHITE,{2,2});
} else {
DrawWrappedText({4,4},CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].name+" "+(char)('A'+BATTLE_CURRENT_TURN_ENTITY)+" with "+CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].selectedMove->name,WIDTH-8,WHITE,{2,2});
DrawWrappedText({4,4},CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->name+" "+(char)('A'+BATTLE_CURRENT_TURN_ENTITY)+" with "+CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY]->selectedMove->name,WIDTH-8,WHITE,{2,2});
}
}break;
}
if (IN_BATTLE_ENCOUNTER||(!CUTSCENE_ACTIVE&&PLAYER_HP!=PLAYER_MAXHP)) {
DrawStringDecal({4+1,HEIGHT-10-GetTextSize("HP:").y+1},"HP: "+std::to_string(PLAYER_HP),BLACK);
DrawStringDecal({4,HEIGHT-10-GetTextSize("HP:").y},"HP: "+std::to_string(PLAYER_HP));
DrawHealthbar({2,HEIGHT-10},WIDTH/2,PLAYER_HP/PLAYER_MAXHP,BLACK);
DrawHealthbar({2,HEIGHT-10},WIDTH/2,(float)PLAYER_HP/PLAYER_MAXHP,BLACK);
for (auto&numb:BATTLE_DISPLAY_NUMBERS) {
std::string display=((numb->number>0)?"-"+std::to_string(numb->number):"+"+std::to_string(numb->number*-1));
for (int x=-1;x<=1;x++) {
for (int y=-1;y<=1;y++) {
if (x!=0&&y!=0) {
DrawStringDecal({((numb->x-PLAYER_COORDS[0])*32+WIDTH/2)-GetTextSize(display).x/2+x,((numb->y-PLAYER_COORDS[1])*32+HEIGHT/2)-8-GetTextSize(display).y/2+y},display,(numb->number>0)?Pixel(255,0,0,numb->alpha):Pixel(0,255,0,numb->alpha),{2,2});
DrawStringDecal({((numb->x-PLAYER_COORDS[0])*32+WIDTH/2)-GetTextSize(display).x/2+x-8,((numb->y-PLAYER_COORDS[1])*32+HEIGHT/2)-12-GetTextSize(display).y/2+y},display,(numb->number>0)?Pixel(255,0,0,numb->alpha):Pixel(0,255,0,numb->alpha),{2,2});
}
}
}
DrawStringDecal({((numb->x-PLAYER_COORDS[0])*32+WIDTH/2)-GetTextSize(display).x/2,((numb->y-PLAYER_COORDS[1])*32+HEIGHT/2)-8-GetTextSize(display).y/2},display,Pixel(255,255,255,numb->alpha),{2,2});
DrawStringDecal({((numb->x-PLAYER_COORDS[0])*32+WIDTH/2)-GetTextSize(display).x/2-8,((numb->y-PLAYER_COORDS[1])*32+HEIGHT/2)-12-GetTextSize(display).y/2},display,Pixel(255,255,255,numb->alpha),{2,2});
//std::cout<<numb->x<<"/"<<numb->y<<" "<<(((numb->x-PLAYER_COORDS[0])*32+WIDTH/2)-GetTextSize(display).x/2)<<","<<(((numb->y-PLAYER_COORDS[1])*32+HEIGHT/2)-8-GetTextSize(display).y/2)<<": ("<<numb->alpha<<")"<<display<<"\n";
}
}
@ -1139,14 +1140,18 @@ public:
for (auto&enc:ENCOUNTERS) {
int targetX=-1,targetY=-1;
for (auto&ent:enc.entities) {
if (BATTLE_STATE==battle::PLAYER_TARGET_SELECTION&&PLAYER_SELECTED_TARGET>=0&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].hp>0&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].x==ent.x&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET].y==ent.y) {
DrawDecal({(enc.x+ent.x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent.y-PLAYER_COORDS[1])*32+HEIGHT/2},TARGETING_CIRCLE,{ent.spr->sprite->width/32,ent.spr->sprite->height/32},{255,210,0,255});
DrawDecal({(enc.x+ent.x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent.y-PLAYER_COORDS[1])*32+HEIGHT/2},ent.spr,{1,1},{(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,255});
targetX=ent.x;targetY=ent.y;
if (BATTLE_STATE==battle::PLAYER_TARGET_SELECTION&&PLAYER_SELECTED_TARGET>=0&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp>0&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->x==ent->x&&CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->y==ent->y) {
DrawDecal({(enc.x+ent->x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent->y-PLAYER_COORDS[1])*32+HEIGHT/2},TARGETING_CIRCLE,{ent->spr->sprite->width/32,ent->spr->sprite->height/32},{255,210,0,255});
DrawDecal({(enc.x+ent->x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent->y-PLAYER_COORDS[1])*32+HEIGHT/2},ent->spr,{1,1},{(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,(0.5*(float)sin(frameCount*4/60.0)+0.5)*80+175,255});
targetX=ent->x;targetY=ent->y;
} else {
DrawDecal({(enc.x+ent.x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent.y-PLAYER_COORDS[1])*32+HEIGHT/2},ent.spr);
if (ent->hp>0) {
DrawDecal({(enc.x+ent->x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent->y-PLAYER_COORDS[1])*32+HEIGHT/2},ent->spr);
}
}
if (ent->hp>0) {
DrawHealthbar({(enc.x+ent->x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent->y-PLAYER_COORDS[1])*32+HEIGHT/2+ent->spr->sprite->height+2},ent->spr->sprite->width,(float)ent->hp/ent->maxhp,BLACK);
}
DrawHealthbar({(enc.x+ent.x-PLAYER_COORDS[0])*32+WIDTH/2,(enc.y+ent.y-PLAYER_COORDS[1])*32+HEIGHT/2+ent.spr->sprite->height+2},ent.spr->sprite->width,ent.hp/ent.maxhp,BLACK);
}
if (targetX!=-1&&targetY!=-1) {
DrawDecal({(enc.x+targetX-PLAYER_COORDS[0])*32+WIDTH/2-BATTLE_CARD_SELECTION->range+16,(enc.y+targetY-PLAYER_COORDS[1])*32+HEIGHT/2-BATTLE_CARD_SELECTION->range+16},TARGETING_RANGE_CIRCLE,{BATTLE_CARD_SELECTION->range*2/32.0,BATTLE_CARD_SELECTION->range*2/32.0},{255,60,0,(0.5*(float)sin(frameCount*4/60.0)+0.5)*100});
@ -1383,7 +1388,7 @@ public:
BATTLE_DISPLAY_NUMBERS.push_back(numb);
} else {
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent=&CURRENT_ENCOUNTER.entities[i];
Entity*ent=CURRENT_ENCOUNTER.entities[i];
if (distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
ent->hp=std::clamp(ent->hp-finalDamage,0,ent->maxhp);
DisplayNumber*numb = new DisplayNumber(finalDamage,ent->x+CURRENT_ENCOUNTER.x,ent->y+CURRENT_ENCOUNTER.y,frameCount);
@ -1396,7 +1401,7 @@ public:
//Damaging effect.
if (playerForce) {
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent=&CURRENT_ENCOUNTER.entities[i];
Entity*ent=CURRENT_ENCOUNTER.entities[i];
std::cout<<"Distance was "<<distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<<"\n";
if (distancetoCoords({(ent->x+CURRENT_ENCOUNTER.x)*32,(ent->y+CURRENT_ENCOUNTER.y)*32},coords*32)<=power->range) {
ent->hp=std::clamp(ent->hp-finalDamage,0,ent->maxhp);

Binary file not shown.
Loading…
Cancel
Save