Refactored encounter list so it's a global database instead of just being a reference.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 913d1683f5
commit 0289b2e87f
  1. BIN
      C++ProjectTemplate
  2. 18
      animation.h
  3. 64
      gameinit.h
  4. 14
      layers.h
  5. 147
      main.cpp
  6. 26
      map.h

Binary file not shown.

@ -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

@ -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::vector<Object*>OBJECTS;
static vd2d cameraPos;
static std::vector<Encounter*>ENCOUNTER_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<Object*,4> PARTY_MEMBER_OBJ;
static std::array<Entity*,7> 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<int,vi2d> additionalChars;
static Cutscene*TestCutscene;
static Cutscene*CurrentCutscene=nullptr;
static ActionType CurrentAction=ActionType::NONE;
static double CUTSCENE_FADE_VALUE=0;
static std::vector<CutsceneAction*>CUTSCENE_QUEUE;
static std::map<BattleMoveName,Battle::Move*>MOVELIST;
static std::array<vd2d,PARTY_TRAIL_LENGTH> 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<std::vector<TILE*>> MAP; //The foreground layer.
static std::vector<std::vector<TILE*>> MAP2;
static std::vector<std::vector<TILE*>> MAP3;
static std::vector<std::vector<TILE*>> MAP4;
static std::vector<std::vector<TILE*>> MAP5; //Collision Layer
static std::map<std::string,Decal*> SPRITES;
static std::map<std::string,Animation*> ANIMATIONS;
static std::map<int,Object*> OBJ_INFO;
#endif

@ -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.
};
}

@ -260,7 +260,7 @@ class Entity{
int HP=0;
int targetHP=0;
int maxHP=0;
int resistances[4]={0,0,0,0};
std::array<int,4>resistances={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::vector<Encounter*>ENCOUNTER_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,4>{vd2d
{+10,+24},{+30,+24},{+50,+24},{+70,+24}},
std::vector<Entity*>{
new Entity(new Object(
NPC1_4,"Test Obj",{+20,+48},ANIMATIONS["player.png"]),
70,70,14,std::array<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
}));//ENCOUNTER_1
ENCOUNTER_LIST.push_back(new Encounter({0,0},std::array<vd2d,4>{vd2d
{10,24},{30,24},{50,24},{70,24}},
std::vector<Entity*>{
new Entity(new Object(
NPC1_4,"Test Obj",{20,48},ANIMATIONS["player.png"],{2,2},GREEN),
70,70,14,std::array<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
}));//ENCOUNTER_2
ENCOUNTER_LIST.push_back(new Encounter({0,0},std::array<vd2d,4>{vd2d
{10,24},{30,24},{50,24},{70,24}},
std::vector<Entity*>{
new Entity(new Object(
NPC1_4,"Test Obj",{20,48},ANIMATIONS["player.png"],{1,1},MAGENTA),
70,70,14,std::array<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
}));//ENCOUNTER_3
}
Object* AddObjectToWorld(Object*obj) {
std::vector<Object*>::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,4>{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<Entity*>{
new Entity(new Object(
NPC1_4,"Test Obj",{pos.x+20,pos.y+48},ANIMATIONS["player.png"]),
70,70,14,std::array<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
});
}break;
case encounter::ENCOUNTER_2:{
data=new Encounter(pos,std::array<vd2d,4>{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<Entity*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
});
}break;
case encounter::ENCOUNTER_3:{
data=new Encounter(pos,std::array<vd2d,4>{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<Entity*>{
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<int,4>{0,0,0,0},0,std::vector<Battle::Move*>{
MOVELIST[BattleMoveName::TESTMOVE1],
MOVELIST[BattleMoveName::TESTMOVE2],
MOVELIST[BattleMoveName::TESTMOVE3],
}),
});
}break;
default:{
printf("WARNING! Dead encounter found! THIS SHOULD NOT BE HAPPENING!");
}
std::vector<Entity*>ents;
for (int i=0;i<ENCOUNTER_LIST[id]->objs.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;i<data->objs.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);
}
}

26
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<Encounter*> 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
Loading…
Cancel
Save