generated from sigonasr2/CPlusPlusProjectTemplate
Implement multiple layers
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
bf437e0317
commit
3e6ce41b08
Binary file not shown.
64
assets/maps/map0_2
Normal file
64
assets/maps/map0_2
Normal file
@ -0,0 +1,64 @@
|
||||
0000R00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
66
main.cpp
66
main.cpp
@ -21,9 +21,11 @@ using namespace olc;
|
||||
class Map{
|
||||
public:
|
||||
std::string filename;
|
||||
std::string l2filename;
|
||||
Decal*tileset;
|
||||
Map(std::string fname,Decal*tileset) {
|
||||
Map(std::string fname,std::string layer2_fname,Decal*tileset) {
|
||||
this->filename=fname;
|
||||
this->l2filename=layer2_fname;
|
||||
this->tileset=tileset;
|
||||
}
|
||||
};
|
||||
@ -86,6 +88,7 @@ public:
|
||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||
|
||||
std::vector<std::vector<TILE*>> MAP;
|
||||
std::vector<std::vector<TILE*>> MAP2; //The foreground layer.
|
||||
std::map<Reference,Decal*> SPRITES;
|
||||
std::map<Reference,Animation*> ANIMATIONS;
|
||||
std::map<int,Object*> OBJ_INFO;
|
||||
@ -93,6 +96,10 @@ public:
|
||||
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
for (int i=1;i<4;i++) {
|
||||
CreateLayer();
|
||||
EnableLayer(i,true);
|
||||
}
|
||||
SetPixelMode(Pixel::ALPHA);
|
||||
ConsoleCaptureStdOut(true);
|
||||
// Called once at the start, so create things here
|
||||
@ -100,7 +107,7 @@ public:
|
||||
SetupAnimations();
|
||||
SetupObjectInfo();
|
||||
|
||||
MAP_ONETT=new Map("map0",SPRITES[TILESET1]);
|
||||
MAP_ONETT=new Map("map0","map0_2",SPRITES[TILESET1]);
|
||||
|
||||
//OBJ_INFO["PLAYER"]=PLAYER_ANIMATION;
|
||||
|
||||
@ -117,6 +124,14 @@ public:
|
||||
updateGame();
|
||||
}
|
||||
keyUpdates();
|
||||
SetDrawTarget(nullptr);
|
||||
Clear(BLANK);
|
||||
SetDrawTarget(1);
|
||||
Clear(BLANK);
|
||||
SetDrawTarget(2);
|
||||
Clear(BLANK);
|
||||
SetDrawTarget(3);
|
||||
Clear(BLANK);
|
||||
drawGame();
|
||||
return true;
|
||||
}
|
||||
@ -209,7 +224,10 @@ public:
|
||||
int yTileOffset = cameraPos.y/32;
|
||||
int xTileOffset = cameraPos.x/32;
|
||||
if (x+xTileOffset>=0&&x+xTileOffset<MAP_WIDTH&&y+yTileOffset>=0&&y+yTileOffset<MAP_HEIGHT) {
|
||||
SetDrawTarget(2);
|
||||
DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES[TILESET1],{MAP[y+yTileOffset][x+xTileOffset]->tileX*32,MAP[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32});
|
||||
SetDrawTarget(3);
|
||||
DrawPartialDecal({x*32-fmod(cameraPos.x,32),y*32-fmod(cameraPos.y,32)},SPRITES[TILESET1],{MAP2[y+yTileOffset][x+xTileOffset]->tileX*32,MAP2[y+yTileOffset][x+xTileOffset]->tileY*32},{32,32});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,12 +243,19 @@ public:
|
||||
|
||||
void LoadMap(Map*map) {
|
||||
std::ifstream f("assets/maps/"+map->filename);
|
||||
std::ifstream f2("assets/maps/"+map->l2filename);
|
||||
for (int i=0;i<MAP.size();i++) {
|
||||
for (int j=0;j<MAP[i].size();j++) {
|
||||
delete MAP[i][j];
|
||||
}
|
||||
MAP[i].clear();
|
||||
}
|
||||
for (int i=0;i<MAP2.size();i++) {
|
||||
for (int j=0;j<MAP2[i].size();j++) {
|
||||
delete MAP2[i][j];
|
||||
}
|
||||
MAP2[i].clear();
|
||||
}
|
||||
MAP_WIDTH=-1;
|
||||
MAP_HEIGHT=-1;
|
||||
MAP.clear();
|
||||
@ -275,7 +300,44 @@ public:
|
||||
MAP_HEIGHT++;
|
||||
}
|
||||
}
|
||||
while (f2.good()) {
|
||||
f2>>data;
|
||||
if (data.find("OBJECT")!=std::string::npos) {
|
||||
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 {
|
||||
std::vector<TILE*> tiles;
|
||||
for (int i=0;i<data.length();i++) {
|
||||
unsigned char tileX,tileY;
|
||||
tileX=data[i]&0x0F;
|
||||
tileY=(data[i]&0xF0)>>4;
|
||||
tiles.push_back(new TILE(tileX,tileY));
|
||||
}
|
||||
MAP2.push_back(tiles);
|
||||
}
|
||||
}
|
||||
printf("Loaded map %s.\n",map->filename.c_str());
|
||||
f.close();
|
||||
f2.close();
|
||||
}
|
||||
|
||||
Decal*CreateSprite(std::string spriteName) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user