Level loading modularized. Levels auto-load/cache tilesets that are already loaded and shared between maps.

pull/28/head
sigonasr2 1 year ago
parent 9247ecb528
commit 8d5d509c7c
  1. 23
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.h
  3. 1
      Crawler/Map.h
  4. 2
      Crawler/Version.h

@ -26,10 +26,9 @@ Crawler::Crawler()
}
bool Crawler::OnUserCreate(){
TMXParser level1("assets/maps/Level1.tmx");
MAP_DATA[LEVEL1]=level1.GetData();
TMXParser level2("assets/maps/Level2.tmx");
MAP_DATA[LEVEL2]=level2.GetData();
InitializeLevel("assets/maps/Level1.tmx",LEVEL1);
InitializeLevel("assets/maps/Level2.tmx",LEVEL2);
InitializeLevel("assets/Campaigns/1_1.tmx",CAMPAIGN_1_1);
//Initialize Camera.
camera=Camera2D{WINDOW_SIZE};
@ -796,6 +795,22 @@ void Crawler::SetupWorldShake(float duration){
camera.SetTarget(worldShake);
}
void Crawler::InitializeLevel(std::string mapFile,MapName map){
TMXParser level(mapFile);
size_t slashMarker = mapFile.find_last_of('/');
std::string baseDir=mapFile.substr(0,slashMarker+1);
MAP_DATA[map]=level.GetData();
for(XMLTag&tag:MAP_DATA[map].TilesetData){
if(tag.tag=="tileset"&&MAP_TILESETS.find(tag.data["source"])==MAP_TILESETS.end()){
Renderable*r=new Renderable();
MAP_TILESETS[tag.data["source"]]=r;
r->Load(baseDir+tag.data["source"]);
std::cout<<"Missing tileset:"<<baseDir+tag.data["source"]<<". Loaded from source."<<std::endl;
}
}
}
int main()
{
Crawler demo;

@ -21,6 +21,7 @@ class Crawler : public olc::PixelGameEngine
GFX_Battlecry_Effect,GFX_Mana,GFX_SonicSlash;
std::vector<Effect>foregroundEffects,backgroundEffects;
std::map<MapName,Map>MAP_DATA;
std::map<std::string,Renderable*>MAP_TILESETS;
vf2d worldShake={};
float worldShakeTime=0;
float lastWorldShakeAdjust=0;
@ -36,6 +37,7 @@ public:
bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override;
void InitializeAnimations();
void InitializeLevel(std::string mapFile,MapName map);
void HandleUserInput(float fElapsedTime);
void UpdateCamera(float fElapsedTime);
void UpdateEffects(float fElapsedTime);

@ -2,4 +2,5 @@
enum MapName{
LEVEL1,
LEVEL2,
CAMPAIGN_1_1,
};

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 121
#define VERSION_BUILD 125
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save