Basic map reading

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 1cb932c151
commit 258134bbac
  1. BIN
      C++ProjectTemplate
  2. 3
      assets/maps/map0
  3. 32
      main.cpp

Binary file not shown.

@ -62,4 +62,5 @@
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
OBJECT17;30; OBJECT17;30;0
OBJECT7;4;0

@ -71,7 +71,7 @@ public:
std::vector<std::vector<TILE*>> MAP; std::vector<std::vector<TILE*>> MAP;
std::map<Reference,Decal*> SPRITES; std::map<Reference,Decal*> SPRITES;
std::map<Reference,Animation*> ANIMATIONS; std::map<Reference,Animation*> ANIMATIONS;
std::map<Reference,Object*> OBJ_INFO; std::map<int,Object*> OBJ_INFO;
std::vector<Object*> OBJECTS; std::vector<Object*> OBJECTS;
bool OnUserCreate() override bool OnUserCreate() override
@ -87,7 +87,7 @@ public:
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION; //OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
//LoadMap(MAP_ONETT); LoadMap(MAP_ONETT);
return true; return true;
} }
@ -136,9 +136,33 @@ public:
MAP_WIDTH=data.length(); MAP_WIDTH=data.length();
printf("Map Width: %d\n",MAP_WIDTH); printf("Map Width: %d\n",MAP_WIDTH);
} }
if (data.find("OBJECT")!=std::string::npos) {
MAP_HEIGHT++; int marker=data.find_first_of(';');
int lastMarker=marker;
std::stringstream split1(data.substr(6,marker-6));
marker=data.find_first_of(';',marker+1);
std::stringstream split2(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
marker=data.find_first_of(';',marker+1);
std::stringstream split3(data.substr(lastMarker+1,marker-lastMarker-1));
lastMarker=marker;
double x,y;
split1>>x;
split2>>y;
int id;
split3>>id;
Object*newObj = new Object(OBJ_INFO[id]->name,{x,y},OBJ_INFO[id]->spr);
OBJECTS.push_back(newObj);
//printf("Object: %s %s %s\n",split1.c_str(),split2.c_str(),split3.c_str());
} else {
MAP_HEIGHT++;
}
} }
printf("Loaded map %s.\n",map->filename.c_str());
} }
void SetupAnimations() { void SetupAnimations() {

Loading…
Cancel
Save