diff --git a/C++ProjectTemplate b/C++ProjectTemplate index d3bcc0d..33e4777 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/animation.h b/animation.h new file mode 100644 index 0000000..6c53dda --- /dev/null +++ b/animation.h @@ -0,0 +1,18 @@ +#ifndef ANIMATION_H +#define ANIMATION_H +#include "pixelGameEngine.h" + +using namespace olc; + +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; + } +}; +#endif \ No newline at end of file diff --git a/gameinit.h b/gameinit.h new file mode 100644 index 0000000..0256c44 --- /dev/null +++ b/gameinit.h @@ -0,0 +1,64 @@ +#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/layers.h b/layers.h new file mode 100644 index 0000000..1a0626b --- /dev/null +++ b/layers.h @@ -0,0 +1,14 @@ + + +namespace layer{ + enum layer{ + INTERFACE, //Interface items should be on this layer. On top of everything. + COLLISION, //Collision checking layer. This layer is + HIGH, + DYNAMIC, + GROUND, + BACKGROUND, + OBJECT, //The object layer doesn't actually exist, it's used to tell the editor we are adding an object instead. + ENCOUNTER, //The encounter layer doesn't actually exist, it's used to tell the editor we are adding encounters instead. + }; +} \ No newline at end of file diff --git a/main.cpp b/main.cpp index b6b1d4d..05b6f29 100644 --- a/main.cpp +++ b/main.cpp @@ -260,7 +260,7 @@ class Entity{ int HP=0; int targetHP=0; int maxHP=0; - int resistances[4]={0,0,0,0}; + std::arrayresistances={0,0,0,0}; int speed=0; int baseAtk=0; int damageReduction=0; //A percentage of how much damage to reduce. @@ -366,6 +366,7 @@ public: int PARTY_MEMBER_COUNT = 1; int ENCOUNTER_SELECTED = 0; int ENCOUNTER_OFFSET = 0; + std::vectorENCOUNTER_LIST; bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. @@ -397,6 +398,7 @@ public: SetupMoveList(); SetupAnimations(); SetupObjectInfo(); + SetupEncounters(); SetGameFlag(Flag::TEST_FLAG1,false); SetGameFlag(Flag::TEST_FLAG2,false); @@ -1509,6 +1511,70 @@ goes on a very long time, I hope you can understand this is only for testing pur CreateObjectInfo(NPC19_8,"npc20_8",{0,0},"player.png",32,{2,2},BLUE,Flag::NONE,Flag::NONE,0); } + void SetupEncounters() { + ENCOUNTER_LIST.push_back(new Encounter({0,0},std::array{vd2d + {+10,+24},{+30,+24},{+50,+24},{+70,+24}}, + std::vector{ + new Entity(new Object( + NPC1_4,"Test Obj",{+20,+48},ANIMATIONS["player.png"]), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + new Entity(new Object( + NPC1_4,"Test Obj 2",{+40,+64},ANIMATIONS["player.png"]), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + new Entity(new Object( + NPC1_4,"Test Obj 3",{+60,+24},ANIMATIONS["player.png"]), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + }));//ENCOUNTER_1 + ENCOUNTER_LIST.push_back(new Encounter({0,0},std::array{vd2d + {10,24},{30,24},{50,24},{70,24}}, + std::vector{ + new Entity(new Object( + NPC1_4,"Test Obj",{20,48},ANIMATIONS["player.png"],{2,2},GREEN), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + new Entity(new Object( + NPC1_4,"Test Obj 2",{40,64},ANIMATIONS["player.png"],{2,2},GREEN), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + new Entity(new Object( + NPC1_4,"Test Obj 3",{60,24},ANIMATIONS["player.png"],{2,2},GREEN), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + }));//ENCOUNTER_2 + ENCOUNTER_LIST.push_back(new Encounter({0,0},std::array{vd2d + {10,24},{30,24},{50,24},{70,24}}, + std::vector{ + new Entity(new Object( + NPC1_4,"Test Obj",{20,48},ANIMATIONS["player.png"],{1,1},MAGENTA), + 70,70,14,std::array{0,0,0,0},0,std::vector{ + MOVELIST[BattleMoveName::TESTMOVE1], + MOVELIST[BattleMoveName::TESTMOVE2], + MOVELIST[BattleMoveName::TESTMOVE3], + }), + }));//ENCOUNTER_3 + } + Object* AddObjectToWorld(Object*obj) { std::vector::const_iterator it = OBJECTS.begin(); if (obj->id==PLAYER&&!obj->temp) { @@ -1725,79 +1791,13 @@ goes on a very long time, I hope you can understand this is only for testing pur } void LoadEncounter(Map*map,vd2d pos,int chance,int id,bool successful) { - Encounter*data; - switch (id) { - case encounter::ENCOUNTER_1:{ - data=new Encounter(pos,std::array{vd2d - {pos.x+10,pos.y+24},{pos.x+30,pos.y+24},{pos.x+50,pos.y+24},{pos.x+70,pos.y+24}}, - std::vector{ - new Entity(new Object( - NPC1_4,"Test Obj",{pos.x+20,pos.y+48},ANIMATIONS["player.png"]), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - new Entity(new Object( - NPC1_4,"Test Obj 2",{pos.x+40,pos.y+64},ANIMATIONS["player.png"]), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - new Entity(new Object( - NPC1_4,"Test Obj 3",{pos.x+60,pos.y+24},ANIMATIONS["player.png"]), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - }); - }break; - case encounter::ENCOUNTER_2:{ - data=new Encounter(pos,std::array{vd2d - {pos.x+10,pos.y+24},{pos.x+30,pos.y+24},{pos.x+50,pos.y+24},{pos.x+70,pos.y+24}}, - std::vector{ - new Entity(new Object( - NPC1_4,"Test Obj",{pos.x+20,pos.y+48},ANIMATIONS["player.png"],{2,2},GREEN), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - new Entity(new Object( - NPC1_4,"Test Obj 2",{pos.x+40,pos.y+64},ANIMATIONS["player.png"],{2,2},GREEN), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - new Entity(new Object( - NPC1_4,"Test Obj 3",{pos.x+60,pos.y+24},ANIMATIONS["player.png"],{2,2},GREEN), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - }); - }break; - case encounter::ENCOUNTER_3:{ - data=new Encounter(pos,std::array{vd2d - {pos.x+10,pos.y+24},{pos.x+30,pos.y+24},{pos.x+50,pos.y+24},{pos.x+70,pos.y+24}}, - std::vector{ - new Entity(new Object( - NPC1_4,"Test Obj",{pos.x+20,pos.y+48},ANIMATIONS["player.png"],{1,1},MAGENTA), - 70,70,14,std::array{0,0,0,0},0,std::vector{ - MOVELIST[BattleMoveName::TESTMOVE1], - MOVELIST[BattleMoveName::TESTMOVE2], - MOVELIST[BattleMoveName::TESTMOVE3], - }), - }); - }break; - default:{ - printf("WARNING! Dead encounter found! THIS SHOULD NOT BE HAPPENING!"); - } + std::vectorents; + 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->baseAtk,ent->resistances,ent->speed,ent->moveSet,ent->damageReduction,ent->smart,ent->dumb)); } + Encounter*data=new Encounter(pos,ENCOUNTER_LIST[id]->playerPos,ents,chance); data->chance=chance; data->id=id; for (int i=0;iobjs.size();i++) { @@ -1811,6 +1811,7 @@ goes on a very long time, I hope you can understand this is only for testing pur if (successful) { AddObjectToWorld(data->objs[i]->obj); } + data->objs[i]->obj->SetPos(data->objs[i]->obj->GetPos()+pos); } } diff --git a/map.h b/map.h new file mode 100644 index 0000000..b01e085 --- /dev/null +++ b/map.h @@ -0,0 +1,26 @@ +#ifndef MAP_H +#define MAP_H +#include "pixelGameEngine.h" +#include "encounters.h" + +using namespace olc; + +class Map{ + public: + std::string filename; + std::string l2filename; + std::string l3filename; + std::string l4filename; + std::string l5filename; + Decal*tileset; + std::vector encounters; + Map(std::string fname,std::string layer2_fname,std::string layer3_fname,std::string layer4_fname,std::string layer5_fname,Decal*tileset) { + this->filename=fname; + this->l2filename=layer2_fname; + this->l3filename=layer3_fname; + this->l4filename=layer4_fname; + this->l5filename=layer5_fname; + this->tileset=tileset; + } +}; +#endif \ No newline at end of file