generated from sigonasr2/CPlusPlusProjectTemplate
Object system implemented
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
9ff1b99ac9
commit
20613f37c3
@ -22,6 +22,12 @@ enum TILES{
|
|||||||
#define FADE_SPD 6
|
#define FADE_SPD 6
|
||||||
#define MOVE_SPD 0.01
|
#define MOVE_SPD 0.01
|
||||||
|
|
||||||
|
class Object{
|
||||||
|
public:
|
||||||
|
float x,y;
|
||||||
|
olc::Decal*spr;
|
||||||
|
};
|
||||||
|
|
||||||
class SeasonsOfLoneliness : public olc::PixelGameEngine
|
class SeasonsOfLoneliness : public olc::PixelGameEngine
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -46,6 +52,10 @@ public:
|
|||||||
int MAP_HEIGHT=-1;
|
int MAP_HEIGHT=-1;
|
||||||
olc::Decal*TILES;
|
olc::Decal*TILES;
|
||||||
float PLAYER_COORDS[2] = {};
|
float PLAYER_COORDS[2] = {};
|
||||||
|
std::vector<Object> OBJECTS;
|
||||||
|
|
||||||
|
olc::Decal*DOME_DECAL;
|
||||||
|
std::map<std::string,olc::Decal*> BASE_OBJECTS;
|
||||||
|
|
||||||
void LoadMap(char*mapName) {
|
void LoadMap(char*mapName) {
|
||||||
std::ifstream f("assets/maps/map1");
|
std::ifstream f("assets/maps/map1");
|
||||||
@ -57,6 +67,7 @@ public:
|
|||||||
}
|
}
|
||||||
free(MAP);
|
free(MAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int y=0;
|
int y=0;
|
||||||
if (f.is_open()) {
|
if (f.is_open()) {
|
||||||
while (f.good()) {
|
while (f.good()) {
|
||||||
@ -68,7 +79,8 @@ public:
|
|||||||
if (MAP_HEIGHT==-1) {
|
if (MAP_HEIGHT==-1) {
|
||||||
std::stringstream stream(data);
|
std::stringstream stream(data);
|
||||||
stream>>MAP_HEIGHT;
|
stream>>MAP_HEIGHT;
|
||||||
} else {
|
} else
|
||||||
|
if (y<MAP_HEIGHT) {
|
||||||
if (MAP==NULL) {
|
if (MAP==NULL) {
|
||||||
MAP=(int**)malloc(sizeof(int**)*MAP_HEIGHT);
|
MAP=(int**)malloc(sizeof(int**)*MAP_HEIGHT);
|
||||||
}
|
}
|
||||||
@ -77,6 +89,16 @@ public:
|
|||||||
MAP[y][i]=data[i]-'0';
|
MAP[y][i]=data[i]-'0';
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
} else {
|
||||||
|
Object obj;
|
||||||
|
std::stringstream split1(data.substr(0,data.find(';')));
|
||||||
|
split1>>obj.x;
|
||||||
|
std::stringstream split2(data.substr(data.find(';')+1,data.find(';',data.find(";")+1)-(data.find(';')+1)));
|
||||||
|
split2>>obj.y;
|
||||||
|
std::string split3 = data.substr(data.find(';',data.find(";")+1)+1,data.length()-(data.find(';',data.find(";")+1)+1));
|
||||||
|
obj.spr=BASE_OBJECTS[split3];
|
||||||
|
printf("Loaded object %s: (%f,%f)\n",split3.c_str(),obj.x,obj.y);
|
||||||
|
OBJECTS.push_back(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,6 +117,8 @@ public:
|
|||||||
//ConsoleCaptureStdOut(true);
|
//ConsoleCaptureStdOut(true);
|
||||||
// Called once at the start, so create things here
|
// Called once at the start, so create things here
|
||||||
TILES=new olc::Decal(new olc::Sprite("assets/tiles.png"));
|
TILES=new olc::Decal(new olc::Sprite("assets/tiles.png"));
|
||||||
|
DOME_DECAL=new olc::Decal(new olc::Sprite("assets/dome.png"));
|
||||||
|
BASE_OBJECTS["DOME"]=DOME_DECAL;
|
||||||
LoadMap("map1");
|
LoadMap("map1");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -217,6 +241,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (auto&obj:OBJECTS) {
|
||||||
|
DrawDecal({(obj.x-PLAYER_COORDS[0])*32+WIDTH/2,(obj.y-PLAYER_COORDS[1])*32+HEIGHT/2},obj.spr);
|
||||||
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
|
FillRectDecal({0,0},{WIDTH,HEIGHT},olc::Pixel(0,0,0,transparency));
|
||||||
|
|||||||
Binary file not shown.
@ -38,4 +38,5 @@
|
|||||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
38;18;DOME
|
||||||
Loading…
x
Reference in New Issue
Block a user