From a7b0a2249c8293ee40a64a856f9c5407b8dab59a Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 28 Aug 2022 20:07:07 -0500 Subject: [PATCH] Turn resolution/finishing Co-authored-by: sigonasr2 --- SeasonsOfLoneliness.cpp | 100 +++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 21 deletions(-) diff --git a/SeasonsOfLoneliness.cpp b/SeasonsOfLoneliness.cpp index 21c21a2..5368999 100644 --- a/SeasonsOfLoneliness.cpp +++ b/SeasonsOfLoneliness.cpp @@ -3,6 +3,7 @@ #include "data.h" #define OLC_PGEX_SPLASHSCREEN #include "splash.h" +#include using namespace olc; @@ -12,6 +13,7 @@ enum GAMESTATE{ CUTSCENE_3, GAMEWORLD, WAITING_FOR_CUTSCENE_3, + GAME_OVER, }; namespace cutscene{ @@ -33,7 +35,8 @@ namespace battle{ ENEMY_SELECTION, MOVE_RESOLUTION, PERFORM_TURN, - WAIT_TURN_ANIMATION + WAIT_TURN_ANIMATION, + DAMAGE_RESOLUTION, }; } @@ -100,7 +103,8 @@ class WEATHER_POWER{ int playerOwnCount; Pixel bgcol; Pixel textcol; - WEATHER_POWER(std::string name,std::string desc,Animation*icon,Animation*effect,int dmg,int dmgRoll,int range,Pixel bgcol,Pixel textcol) { + int effectTime; + WEATHER_POWER(std::string name,std::string desc,Animation*icon,Animation*effect,int dmg,int dmgRoll,int range,Pixel bgcol,Pixel textcol,int effectTime) { this->description=desc; this->name=name; this->anim=icon; @@ -209,14 +213,14 @@ public: Animation POWER_METEOR_STORM_ANIMATION; Animation POWER_SNOWSTORM_ANIMATION; std::vector 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)); - 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)); - 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)); - WEATHER_POWER*METEOR_STORM = new WEATHER_POWER("Meteor Storm","Larger space rocks. 120+60d",&POWER_METEOR_STORM_ANIMATION,&POWER_METEOR_STORM_ANIMATION,120,60,140,Pixel(89, 4, 33,255),Pixel(130, 56, 1,255)); - WEATHER_POWER*SNOWSTORM = new WEATHER_POWER("Snowstorm","Slows down targets and causes rapid temperature drops. 15+10d",&POWER_SNOWSTORM_ANIMATION,&POWER_SNOWSTORM_ANIMATION,15,10,140,Pixel(183, 196, 194,255),Pixel(222, 255, 254,255)); - WEATHER_POWER*SANDSTORM = new WEATHER_POWER("Sandstorm","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,5,10,64,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255)); - WEATHER_POWER*SEED_STORM = new WEATHER_POWER("Seed Storm","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,8,20,164,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255)); - WEATHER_POWER*AVALANCHE = new WEATHER_POWER("Avalanche","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,15,10,200,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255)); + 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); + WEATHER_POWER*METEOR_STORM = new WEATHER_POWER("Meteor Storm","Larger space rocks. 120+60d",&POWER_METEOR_STORM_ANIMATION,&POWER_METEOR_STORM_ANIMATION,120,60,140,Pixel(89, 4, 33,255),Pixel(130, 56, 1,255),120); + WEATHER_POWER*SNOWSTORM = new WEATHER_POWER("Snowstorm","Slows down targets and causes rapid temperature drops. 15+10d",&POWER_SNOWSTORM_ANIMATION,&POWER_SNOWSTORM_ANIMATION,15,10,140,Pixel(183, 196, 194,255),Pixel(222, 255, 254,255),120); + WEATHER_POWER*SANDSTORM = new WEATHER_POWER("Sandstorm","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,5,10,64,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255),120); + WEATHER_POWER*SEED_STORM = new WEATHER_POWER("Seed Storm","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,8,20,164,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255),120); + WEATHER_POWER*AVALANCHE = new WEATHER_POWER("Avalanche","",&POWER_HAILSTORM_ANIMATION,&POWER_HAILSTORM_ANIMATION,15,10,200,Pixel(93, 161, 163,255),Pixel(72, 160, 212,255),120); bool IN_BATTLE_ENCOUNTER = false; int BATTLE_ENTRY_TIMER = 0; int EFFECT_TIMER = 0; @@ -234,6 +238,8 @@ public: int PLAYER_SELECTED_TARGET=-1; int PLAYER_MAXHP=60; int PLAYER_HP=PLAYER_MAXHP; + int BATTLE_CURRENT_TURN_ENTITY=-1; + int CURRENT_ENCOUNTER_IND=-1; std::vectorMOVESET_SPIDEY; @@ -246,7 +252,7 @@ public: std::vector ENCOUNTERS; Encounter ENCOUNTER_SPIDEY_1; Encounter CURRENT_ENCOUNTER; - std::vector turnOrder; + std::stack turnOrder; bool OnUserCreate() override { @@ -413,6 +419,8 @@ public: } }break; case battle::PLAYER_TARGET_SELECTION:{ + //Remove the card from inventory. + BATTLE_CARD_SELECTION->playerOwnCount--; BATTLE_STATE=battle::ENEMY_SELECTION; for (int i=0;i0) { @@ -423,13 +431,13 @@ public: BATTLE_STATE=battle::MOVE_RESOLUTION; //Seed Storm has prio. if (BATTLE_CARD_SELECTION_IND!=-1&&BATTLE_CARD_SELECTION->name.compare("Seed Storm")==0) { - turnOrder.push_back(-1); + turnOrder.push(-1); BATTLE_CARD_SELECTION_IND=-1; } for (int i=0;i0&&!CURRENT_ENCOUNTER.entities[i].turnComplete&& CURRENT_ENCOUNTER.entities[i].selectedMove->name.compare("Seed Storm")==0) { - turnOrder.push_back(i); + turnOrder.push(i); CURRENT_ENCOUNTER.entities[i].turnComplete=true; } } @@ -438,27 +446,27 @@ public: Entity*ent = &CURRENT_ENCOUNTER.entities[i]; if (ent->hp>0&&!ent->turnComplete&& !ent->slowed&&rand()%2==0) { - turnOrder.push_back(i); + turnOrder.push(i); ent->turnComplete=true; } } if (BATTLE_CARD_SELECTION_IND!=-1) { - turnOrder.push_back(-1); + turnOrder.push(-1); BATTLE_CARD_SELECTION_IND=-1; } //Finally, any enemies that haven't gone will now go. for (int i=0;ihp>0&&!ent->turnComplete) { - turnOrder.push_back(i); + turnOrder.push(i); ent->turnComplete=true; } } - std::cout<<"Turn order:"; - for (auto&order:turnOrder) { - std::cout<ref->effectTime) { + BATTLE_STATE=battle::DAMAGE_RESOLUTION; + EFFECT_TIMER=0; + } + }break; + case battle::DAMAGE_RESOLUTION:{ + EFFECT_TIMER++; + if (EFFECT_TIMER>60) { + if (turnOrder.empty()) { + bool allDead=true; + for (auto&ent:CURRENT_ENCOUNTER.entities) { + if (ent.hp>0) { + allDead=false; + break; + } + } + if (allDead) { + IN_BATTLE_ENCOUNTER=false; + ENCOUNTERS.erase(ENCOUNTERS.begin()+CURRENT_ENCOUNTER_IND); + BATTLE_CARD_SELECTION_IND=0; + PLAYER_SELECTED_TARGET=-1; + BATTLE_STATE=battle::NONE; + } + } else { + BATTLE_CURRENT_TURN_ENTITY=turnOrder.top(); + turnOrder.pop(); + if (BATTLE_CURRENT_TURN_ENTITY==-1) { + if (PLAYER_HP<=0) { + GAME_STATE=GAME_OVER; + break; + } + } else { + if (CURRENT_ENCOUNTER.entities[BATTLE_CURRENT_TURN_ENTITY].hp<=0) { + break; + } + } + BATTLE_STATE=battle::WAIT_TURN_ANIMATION; + EFFECT_TIMER=0; + } + } + }break; } } @@ -956,7 +1014,7 @@ public: } }break; } - if (IN_BATTLE_ENCOUNTER) { + 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);