diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 05d32ee..ff7fb7e 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/battle.h b/battle.h new file mode 100644 index 0000000..0758184 --- /dev/null +++ b/battle.h @@ -0,0 +1,55 @@ +#ifndef BATTLE_H +#define BATTLE_H + +#include "effect.h" +#include "pixelGameEngine.h" +using namespace olc; + +enum class Resistance{ + WET, + DRY, + COLD, + HEAT, +}; + +enum class Property{ + PETRIFY, + PARALYZE, + DIAMONDIZE, + CRYING, + SLOW, + MUSHROOMIZED, + CONFUSE, + POISON, + REGEN, + DEFENSE_UP, + REVIVE, +}; + +namespace Battle{ + class Move{ + public: + std::string name; + std::string desc; + std::arraycomposition; + int baseDmg; //The base damage of the attack. + int randomDmg; //Additional random roll damage to add onto the base damage. + bool pctDamage; //Uses % damage for the base damage instead of flat damage. + std::vector> properties; //The int is used to determine the chance of something occurring. + //Properties order is WET, DRY, COLD, HEAT + int PPCost=0; + int grade=0; //If the name of a move name match, then the grade helps sort it into the same category on menus. + int range=1; //The range of this ability in tiles. + int channelTime=0; //The amount of frames to channel the spell. + bool friendly=false; //Target allies instead. + Effect*eff=nullptr; + //Assumes friendly is false. + Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) + :Move(name,desc,0,baseDmg,randomDmg,PPCost,range,0,false,composition,eff,pctDamage,properties){}; + Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) + :Move(name,desc,0,baseDmg,randomDmg,PPCost,range,channelTime,friendly,composition,eff,pctDamage,properties){}; + Move(std::string name,std::string desc,int grade,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) + :name(name),grade(grade),PPCost(PPCost),desc(desc),randomDmg(randomDmg),baseDmg(baseDmg),range(range),friendly(friendly),eff(eff),channelTime(channelTime),composition(composition),pctDamage(pctDamage),properties(properties){} + }; +} +#endif \ No newline at end of file diff --git a/defines.h b/defines.h index ddcff4f..b77fab5 100644 --- a/defines.h +++ b/defines.h @@ -1,3 +1,8 @@ +#ifndef DEFINES_H +#define DEFINES_H +#include "pixelGameEngine.h" +using namespace olc; + #define WIDTH 256 #define HEIGHT 224 @@ -7,4 +12,27 @@ #define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT) #define PARTY_TRAIL_LENGTH 48 #define CAMERA_WAIT_TIME 60 -#define HEALTH_ROLLING_SPEED 2 \ No newline at end of file +#define HEALTH_ROLLING_SPEED 2 + +#define ㅎ +#define ㅍ +#define 아 + +#define α 0x391 +#define β 0x392 +#define γ 0x3b3 +#define Ω 0x3a3 +#define Σ 0x3a9 + +#define AddAsyncCutsceneAction(AsyncClass) \ + if (!((AsyncClass*)CurrentCutscene->GetAction())->InQueue()) { \ + CUTSCENE_QUEUE.push_back(CurrentCutscene->GetAction()); \ + } \ + ((AsyncClass*)CurrentCutscene->GetAction())->SetQueued(); \ + CurrentCutscene->AdvanceAction(); \ + +#define 액션 (CutsceneAction*)new + +extern PixelGameEngine*GAME; +extern vd2d cameraPos; +#endif \ No newline at end of file diff --git a/effect.h b/effect.h index b38fd06..99033c9 100644 --- a/effect.h +++ b/effect.h @@ -1,3 +1,9 @@ +#ifndef EFFECT_H +#define EFFECT_H +#include "particle.h" +#include "pixelGameEngine.h" +using namespace olc; + class Effect{ public: std::vector particles; @@ -32,4 +38,5 @@ class FountainEffect:public Effect{ } }; -FountainEffect*FOUNTAIN_EFFECT; \ No newline at end of file +FountainEffect*FOUNTAIN_EFFECT; +#endif \ No newline at end of file diff --git a/encounters.h b/encounters.h index 2f08f92..6a87d37 100644 --- a/encounters.h +++ b/encounters.h @@ -1,3 +1,12 @@ +#ifndef ENCOUNTERS_H +#define ENCOUNTERS_H +#include "pixelGameEngine.h" +using namespace olc; +#include "defines.h" +#include "object.h" +#include "battle.h" +#include "item.h" + namespace encounter{ enum{ ENCOUNTER_1, @@ -5,4 +14,90 @@ namespace encounter{ ENCOUNTER_3, ENCOUNTER_4, }; -} \ No newline at end of file +} + +class Entity{ + private: + int HP=0; + int targetHP=0; + public: + int maxHP=0; + int PP=0; + int targetPP=0; + int maxPP=0; + std::arrayresistances={0,0,0,0}; + int speed=0; + int baseAtk=0; + int damageReduction=0; //A percentage of how much damage to reduce. + bool smart=false; + bool dumb=false; + int atb=0; //When this value reaches 1000, it's this entity's turn. + Object* obj; + std::vector moveSet; + int selectedTarget = 0; + Battle::Move*selectedMove = nullptr; //The index of the selected move. + int channelTimeRemaining = 0; //The amount of channel time left until move can be performed. + vd2d channelPos = {0,0}; //Where our channel is happening. + std::vector inventory; //Used mostly for enemy spoils. + std::array equipment; //Equipment this character is using. + //Used for initializing players. + Entity(int HP,int maxHP,int PP,int maxPP,int baseAtk,std::arrayresistances,int speed,std::vectormoveSet,std::vectoritems={},std::arrayequipment={},int damageReduction=0,bool smart=false,bool dumb=false) + :Entity(nullptr,HP,maxHP,PP,maxPP,baseAtk,resistances,speed,moveSet,items,equipment,damageReduction,smart,dumb){} + //Use this for initializing enemies as it lets you specify an object. + Entity(Object*obj,int HP,int maxHP,int PP,int maxPP,int baseAtk,std::arrayresistances,int speed,std::vectormoveSet,std::vectoritems={},std::arrayequipment={},int damageReduction=0,bool smart=false,bool dumb=false) + :obj(obj),HP(HP),maxHP(maxHP),PP(PP),maxPP(maxPP),baseAtk(baseAtk),speed(speed),equipment(equipment),moveSet(moveSet),damageReduction(damageReduction),inventory(items),smart(smart),dumb(dumb){ + for (int i=0;i<4;i++) { + this->resistances[i]=resistances[i]; + } + 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(targetHP+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{ + public: + vd2d pos; + int chance; //Chance of the encounter existing. + std::vectorobjs; + std::array playerPos; + int id; + Encounter(int id,vd2d pos,std::array playerPos,std::vectorobjs,int chance=25) + :id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){} + bool IsEncounterAlive() { + for (int i=0;iGetHP()>0) { + return true; + } + } + return false; + } + bool IsInRange(vd2d pos) { + vd2d diff=pos-this->pos; + return diff.x>=0&&diff.x<=WIDTH&&diff.y>=0&&diff.y<=HEIGHT; + } +}; +#endif \ No newline at end of file diff --git a/flags.h b/flags.h index 4357a03..d512fda 100644 --- a/flags.h +++ b/flags.h @@ -1,3 +1,5 @@ +#ifndef FLAGS_H +#define FLAGS_H enum class Flag:int{ NONE, TEST_FLAG1, @@ -18,4 +20,5 @@ template auto toint(Enumeration const value) -> typename std::underlying_type::type { return static_cast::type>(value); -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/gameinit.h b/gameinit.h deleted file mode 100644 index 0256c44..0000000 --- a/gameinit.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef GAME_INIT_H -#define GAME_INIT_H -#define PARTY_TRAIL_LENGTH 48 -#include "pixelGameEngine.h" -#include "encounters.h" -#include "map.h" -#include "states.h" -#include "references.h" -#include "cutscene.h" -#include "tiles.h" -using namespace olc; - - -static PixelGameEngine*GAME; -static std::vectorOBJECTS; -static vd2d cameraPos; -static std::vectorENCOUNTER_LIST; -static int frameCount=0; -static float elapsedTime=0; -static const float TARGET_RATE = 1/60.0; -static int MAP_WIDTH=-1; -static int MAP_HEIGHT=-1; -static Map*CURRENT_MAP; -static Map*MAP_ONETT; -static int GAME_STATE = GameState::EDITOR; -static vi2d SELECTED_TILE={0,0}; -static vi2d HIGHLIGHTED_TILE={0,0}; -static int EDITING_LAYER=layer::DYNAMIC; -static int SELECTED_OBJ_ID = PLAYER; -static int OBJ_DISPLAY_OFFSET = 0; -static bool GAME_FLAGS[128]={}; -static std::array PARTY_MEMBER_OBJ; -static std::array PARTY_MEMBER_STATS; -static bool messageBoxVisible=false; -static std::string messageBoxText=""; -static std::string messageBoxTargetText=""; -static std::string messageBoxFinalText=""; -static int messageBoxMarker=0; -static int messageBoxStartMarker=0; //Start of text display. -static int messageBoxStopMarker=0; //End of text display for current printout. -static int messageBoxFrameWaitTime=1; -static bool messageBoxLoad=false; //Set to true when ready to load a message in. -static std::map additionalChars; -static Cutscene*TestCutscene; -static Cutscene*CurrentCutscene=nullptr; -static ActionType CurrentAction=ActionType::NONE; -static double CUTSCENE_FADE_VALUE=0; -static std::vectorCUTSCENE_QUEUE; -static std::mapMOVELIST; -static std::array partyTrail={vd2d{0,0}}; -static int PARTY_MEMBER_COUNT = 1; -static int ENCOUNTER_SELECTED = 0; -static int ENCOUNTER_OFFSET = 0; - -static bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.static -static std::vector> MAP; //The foreground layer. -static std::vector> MAP2; -static std::vector> MAP3; -static std::vector> MAP4; -static std::vector> MAP5; //Collision Layer -static std::map SPRITES; -static std::map ANIMATIONS; -static std::map OBJ_INFO; -#endif \ No newline at end of file diff --git a/item.h b/item.h new file mode 100644 index 0000000..ccf57a3 --- /dev/null +++ b/item.h @@ -0,0 +1,43 @@ +#ifndef ITEM_H +#define ITEM_H +#include "pixelGameEngine.h" +using namespace olc; +#include "battle.h" +enum class ItemName{ + COOKIE, + EGG, + PIZZA, + CRACKED_BAT, + LIGHT_JACKET, + KEY_TO_THE_PALACE, +}; + +namespace EquipSlot{ + enum Equip{ + WEAPON, + ARMOR, + ACCESSORY, + NONE + }; +} + +struct ItemStatsStruct{ + int hpRecovery=0; + int ppRecovery=0; + int attack=0; + int defense=0; + EquipSlot::Equip equip=EquipSlot::NONE; //Whether or not this is equipment. + bool important=false; //If an item's important it can't be discarded. + bool consumable=false; //Whether or not this item is consumed when used. +}; + +class Item{ + public: + std::string name; + std::string description; + Battle::Move*battlemove=nullptr; + ItemStatsStruct stats; + Item(std::string name,std::string desc,ItemStatsStruct stats={0,0,0,0,EquipSlot::NONE,false,false},Battle::Move*battlemove=nullptr) + :name(name),description(desc),stats(stats),battlemove(battlemove){} +}; +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index c3d3327..310fa51 100644 --- a/main.cpp +++ b/main.cpp @@ -15,28 +15,13 @@ #include "particle.h" #include "effect.h" -#define ㅎ -#define ㅍ -#define 아 - -#define α 0x391 -#define β 0x392 -#define γ 0x3b3 -#define Ω 0x3a3 -#define Σ 0x3a9 - -#define AddAsyncCutsceneAction(AsyncClass) \ - if (!((AsyncClass*)CurrentCutscene->GetAction())->InQueue()) { \ - CUTSCENE_QUEUE.push_back(CurrentCutscene->GetAction()); \ - } \ - ((AsyncClass*)CurrentCutscene->GetAction())->SetQueued(); \ - CurrentCutscene->AdvanceAction(); \ - -#define 액션 (CutsceneAction*)new +using namespace olc; + std::vector OBJECTS; const vd2d NO_NEIGHBOR = {-999,-999}; -using namespace olc; +vd2d cameraPos={0,0}; +PixelGameEngine*GAME; enum{ ALPHA=α, @@ -59,215 +44,6 @@ namespace layer{ }; } -class Animation{ - public: - Decal*spr; - int frames=1; - int width=0; - Animation(Decal*spr,int width){ - this->frames=spr->sprite->width/width; - this->width=width; - this->spr=spr; - } -}; - -vd2d cameraPos = {0,0}; -PixelGameEngine*GAME; - -class Object{ - private: - vd2d scale={1,1}; - vd2d pos; - public: - int id; - Animation*spr; - int frameIndex=0; - int frameCount=0; - int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation. - std::string name; - Pixel color=WHITE; - vd2d originPoint={0,0}; - bool drawn=false; - Flag disableFlag=Flag::NONE; - Flag enableFlag=Flag::NONE; - int objArrElement; //Which element in the object array this object is located in. For sorting purposes. - bool temp=false; //If set to true, it's marked for deletion after cutscene handling. - bool enc=false; //If set to true, it's not included in the main list of entities for map saving because it's from an encounter. - bool dead=false; //If set to true, this object was properly part of an Entity and got declared as dead. - int blinkFrames=0; //Frame count of how much time is left for the image to be blinking. Used when enemies take damage. - //animationSpd is how long to wait before switching frames. - bool highlighted=false; //Whether or not this object has been declared as highlighted by a target range selector. - bool Collision(vd2d pos) { - GAME->SetDrawTarget(layer::COLLISION); - Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y); - return collisionData!=MAGENTA; - } - //A grid version of the constructor. used ONLY for battle setups. - Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) - :Object(id,name,{gridx*32-(spr->width*0.5)*(scale.x-1),gridy*32-(spr->spr->sprite->height-4)*(scale.y-1)},spr,scale,color,animationSpd,temp) {} - Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) { - this->spr=spr; - this->pos=pos; - this->id=id; - this->name=name; - this->color=color; - this->animationSpd=animationSpd; - SetScale(scale); - this->temp=temp; - } - void SetScale(vd2d scale) { - this->scale=scale; - this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y}; - } - vd2d GetScale() { - return scale; - } - vd2d GetPos() { - return pos; - } - void Move(vd2d move) { - if (move.y==0) { - pos+=move; - return; - } else { - if (move.y<0) { - while (objArrElement>0&&OBJECTS[objArrElement-1]->pos.y+OBJECTS[objArrElement-1]->originPoint.y>pos.y+originPoint.y+move.y) { - //printf("%p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); - OBJECTS[objArrElement]=OBJECTS[objArrElement-1]; - //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); - OBJECTS[objArrElement-1]=this; - //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); - OBJECTS[objArrElement]->objArrElement=objArrElement; - //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str(),objArrElement-1); - objArrElement--; - } - } else { - while (objArrElementpos.y+OBJECTS[objArrElement+1]->originPoint.y%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); - OBJECTS[objArrElement]=OBJECTS[objArrElement+1]; - //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); - OBJECTS[objArrElement+1]=this; - //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); - OBJECTS[objArrElement]->objArrElement=objArrElement; - //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str(),objArrElement+1); - objArrElement++; - } - } - pos+=move; - } - } - void SetPos(vd2d pos) { - Move(pos-this->pos); - } - vd2d GetPosWithOrigin() { - return GetPos()+originPoint; - } - bool SmoothMove(vd2d move) { - const int wiggleRoom=5; - vd2d originPos = {pos.x+originPoint.x,pos.y-1+originPoint.y}; - if (!Collision(originPos+move)) { - Move(move); - return true; - } else - if (move.x!=0&&!Collision({originPos.x+move.x,originPos.y})) { - Move({move.x,0}); - return true; - } else - if (move.y!=0&&!Collision({originPos.x,originPos.y+move.y})) { - Move({0,move.y}); - return true; - } - else - if (move.x>0) { - for (int i=0;i0) { - for (int i=0;i inline T transform_to( F str ) noexcept{if (str.empty()) return {}; return { std::begin(str), std::end(str) };}; -namespace Battle{ - class Move{ - public: - std::string name; - std::string desc; - std::arraycomposition; - int baseDmg; //The base damage of the attack. - int randomDmg; //Additional random roll damage to add onto the base damage. - bool pctDamage; //Uses % damage for the base damage instead of flat damage. - std::vector> properties; //The int is used to determine the chance of something occurring. - //Properties order is WET, DRY, COLD, HEAT - int PPCost=0; - int grade=0; //If the name of a move name match, then the grade helps sort it into the same category on menus. - int range=1; //The range of this ability in tiles. - int channelTime=0; //The amount of frames to channel the spell. - bool friendly=false; //Target allies instead. - Effect*eff=nullptr; - //Assumes friendly is false. - Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) - :Move(name,desc,0,baseDmg,randomDmg,PPCost,range,0,false,composition,eff,pctDamage,properties){}; - Move(std::string name,std::string desc,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) - :Move(name,desc,0,baseDmg,randomDmg,PPCost,range,channelTime,friendly,composition,eff,pctDamage,properties){}; - Move(std::string name,std::string desc,int grade,int baseDmg,int randomDmg,int PPCost,int range,int channelTime,bool friendly,std::arraycomposition,Effect*eff=nullptr,bool pctDamage=false,std::vector> properties={}) - :name(name),grade(grade),PPCost(PPCost),desc(desc),randomDmg(randomDmg),baseDmg(baseDmg),range(range),friendly(friendly),eff(eff),channelTime(channelTime),composition(composition),pctDamage(pctDamage),properties(properties){} - }; -} - -namespace EquipSlot{ - enum Equip{ - WEAPON, - ARMOR, - ACCESSORY, - NONE - }; -} - -struct ItemStatsStruct{ - int hpRecovery=0; - int ppRecovery=0; - int attack=0; - int defense=0; - EquipSlot::Equip equip=EquipSlot::NONE; //Whether or not this is equipment. - bool important=false; //If an item's important it can't be discarded. - bool consumable=false; //Whether or not this item is consumed when used. -}; - -class Item{ - public: - std::string name; - std::string description; - Battle::Move*battlemove=nullptr; - ItemStatsStruct stats; - Item(std::string name,std::string desc,ItemStatsStruct stats={0,0,0,0,EquipSlot::NONE,false,false},Battle::Move*battlemove=nullptr) - :name(name),description(desc),stats(stats),battlemove(battlemove){} -}; - -class Entity{ - private: - int HP=0; - int targetHP=0; - public: - int maxHP=0; - int PP=0; - int targetPP=0; - int maxPP=0; - std::arrayresistances={0,0,0,0}; - int speed=0; - int baseAtk=0; - int damageReduction=0; //A percentage of how much damage to reduce. - bool smart=false; - bool dumb=false; - int atb=0; //When this value reaches 1000, it's this entity's turn. - Object* obj; - std::vector moveSet; - int selectedTarget = 0; - Battle::Move*selectedMove = nullptr; //The index of the selected move. - int channelTimeRemaining = 0; //The amount of channel time left until move can be performed. - vd2d channelPos = {0,0}; //Where our channel is happening. - std::vector inventory; //Used mostly for enemy spoils. - std::array equipment; //Equipment this character is using. - //Used for initializing players. - Entity(int HP,int maxHP,int PP,int maxPP,int baseAtk,std::arrayresistances,int speed,std::vectormoveSet,std::vectoritems={},std::arrayequipment={},int damageReduction=0,bool smart=false,bool dumb=false) - :Entity(nullptr,HP,maxHP,PP,maxPP,baseAtk,resistances,speed,moveSet,items,equipment,damageReduction,smart,dumb){} - //Use this for initializing enemies as it lets you specify an object. - Entity(Object*obj,int HP,int maxHP,int PP,int maxPP,int baseAtk,std::arrayresistances,int speed,std::vectormoveSet,std::vectoritems={},std::arrayequipment={},int damageReduction=0,bool smart=false,bool dumb=false) - :obj(obj),HP(HP),maxHP(maxHP),PP(PP),maxPP(maxPP),baseAtk(baseAtk),speed(speed),equipment(equipment),moveSet(moveSet),damageReduction(damageReduction),inventory(items),smart(smart),dumb(dumb){ - for (int i=0;i<4;i++) { - this->resistances[i]=resistances[i]; - } - 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(targetHP+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{ - public: - vd2d pos; - int chance; //Chance of the encounter existing. - std::vectorobjs; - std::array playerPos; - int id; - Encounter(int id,vd2d pos,std::array playerPos,std::vectorobjs,int chance=25) - :id(id),pos(pos),objs(objs),chance(chance),playerPos(playerPos){} - bool IsEncounterAlive() { - for (int i=0;iGetHP()>0) { - return true; - } - } - return false; - } - bool IsInRange(vd2d pos) { - vd2d diff=pos-this->pos; - return diff.x>=0&&diff.x<=WIDTH&&diff.y>=0&&diff.y<=HEIGHT; - } -}; - - class Map{ public: std::string filename; @@ -587,6 +212,7 @@ public: bool OnUserCreate() override { + srand(time(NULL)); GAME=this; for (int i=1;i<6;i++) { @@ -2049,7 +1675,7 @@ This is a test message that lets us trigger straight from a cutscene! Cool!)"), LoadEncounter(map,{x,y},pct,id,rand()%100 tiles; diff --git a/object.cpp b/object.cpp new file mode 100644 index 0000000..04bf881 --- /dev/null +++ b/object.cpp @@ -0,0 +1,42 @@ +#include "object.h" +#include "layers.h" +#include "defines.h" + +extern std::vector OBJECTS; + +bool Object::Collision(vd2d pos){ + GAME->SetDrawTarget(layer::COLLISION); + Pixel collisionData = GAME->GetDrawTarget()->GetPixel((int)pos.x-cameraPos.x,(int)pos.y-cameraPos.y); + return collisionData!=MAGENTA; +} +void Object::Move(vd2d move) { + if (move.y==0) { + pos+=move; + return; + } else { + if (move.y<0) { + while (objArrElement>0&&OBJECTS[objArrElement-1]->pos.y+OBJECTS[objArrElement-1]->originPoint.y>pos.y+originPoint.y+move.y) { + //printf("%p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); + OBJECTS[objArrElement]=OBJECTS[objArrElement-1]; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); + OBJECTS[objArrElement-1]=this; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str()); + OBJECTS[objArrElement]->objArrElement=objArrElement; + //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement-1],OBJECTS[objArrElement-1]->name.c_str(),objArrElement-1); + objArrElement--; + } + } else { + while (objArrElementpos.y+OBJECTS[objArrElement+1]->originPoint.y%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); + OBJECTS[objArrElement]=OBJECTS[objArrElement+1]; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); + OBJECTS[objArrElement+1]=this; + //printf(" %p(%s)<->%p(%s)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str()); + OBJECTS[objArrElement]->objArrElement=objArrElement; + //printf(" %p(%s)(%d)<->%p(%s)(%d)\n",OBJECTS[objArrElement],OBJECTS[objArrElement]->name.c_str(),OBJECTS[objArrElement]->objArrElement,OBJECTS[objArrElement+1],OBJECTS[objArrElement+1]->name.c_str(),objArrElement+1); + objArrElement++; + } + } + pos+=move; + } +} \ No newline at end of file diff --git a/object.h b/object.h new file mode 100644 index 0000000..c26a012 --- /dev/null +++ b/object.h @@ -0,0 +1,146 @@ +#ifndef OBJECT_H +#define OBJECT_H +#include "pixelGameEngine.h" +#include "flags.h" +#include "animation.h" +using namespace olc; + +class Object{ + private: + vd2d scale={1,1}; + vd2d pos; + public: + int id; + Animation*spr; + int frameIndex=0; + int frameCount=0; + int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation. + std::string name; + Pixel color=WHITE; + vd2d originPoint={0,0}; + bool drawn=false; + Flag disableFlag=Flag::NONE; + Flag enableFlag=Flag::NONE; + int objArrElement; //Which element in the object array this object is located in. For sorting purposes. + bool temp=false; //If set to true, it's marked for deletion after cutscene handling. + bool enc=false; //If set to true, it's not included in the main list of entities for map saving because it's from an encounter. + bool dead=false; //If set to true, this object was properly part of an Entity and got declared as dead. + int blinkFrames=0; //Frame count of how much time is left for the image to be blinking. Used when enemies take damage. + //animationSpd is how long to wait before switching frames. + bool highlighted=false; //Whether or not this object has been declared as highlighted by a target range selector. + bool Collision(vd2d pos); + //A grid version of the constructor. used ONLY for battle setups. + Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) + :Object(id,name,{gridx*32-(spr->width*0.5)*(scale.x-1),gridy*32-(spr->spr->sprite->height-4)*(scale.y-1)},spr,scale,color,animationSpd,temp) {} + Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) { + this->spr=spr; + this->pos=pos; + this->id=id; + this->name=name; + this->color=color; + this->animationSpd=animationSpd; + SetScale(scale); + this->temp=temp; + } + void SetScale(vd2d scale) { + this->scale=scale; + this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y}; + } + vd2d GetScale() { + return scale; + } + vd2d GetPos() { + return pos; + } + void Move(vd2d move); + void SetPos(vd2d pos) { + Move(pos-this->pos); + } + vd2d GetPosWithOrigin() { + return GetPos()+originPoint; + } + bool SmoothMove(vd2d move) { + const int wiggleRoom=5; + vd2d originPos = {pos.x+originPoint.x,pos.y-1+originPoint.y}; + if (!Collision(originPos+move)) { + Move(move); + return true; + } else + if (move.x!=0&&!Collision({originPos.x+move.x,originPos.y})) { + Move({move.x,0}); + return true; + } else + if (move.y!=0&&!Collision({originPos.x,originPos.y+move.y})) { + Move({0,move.y}); + return true; + } + else + if (move.x>0) { + for (int i=0;i0) { + for (int i=0;iFillRectDecal(pos,size,col); } -}; \ No newline at end of file +}; +#endif \ No newline at end of file