generated from sigonasr2/CPlusPlusProjectTemplate
Map loading
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
5048085192
commit
c1c7cd50b1
@ -34,12 +34,57 @@ public:
|
||||
float elapsedTime=0;
|
||||
const float TARGET_RATE = 1/60.0;
|
||||
std::string CUTSCENE_CONSOLE_TEXT = "";
|
||||
int**MAP=NULL;
|
||||
int MAP_WIDTH=-1;
|
||||
int MAP_HEIGHT=-1;
|
||||
|
||||
void LoadMap(char*mapName) {
|
||||
std::ifstream f("assets/maps/map1");
|
||||
std::string data;
|
||||
MAP_WIDTH=MAP_HEIGHT=-1;
|
||||
if (MAP!=NULL) {
|
||||
for (int y=0;y<MAP_HEIGHT;y++) {
|
||||
free(MAP[y]);
|
||||
}
|
||||
free(MAP);
|
||||
}
|
||||
int y=0;
|
||||
if (f.is_open()) {
|
||||
while (f.good()) {
|
||||
f>>data;
|
||||
if (MAP_WIDTH==-1) {
|
||||
std::stringstream stream(data);
|
||||
stream>>MAP_WIDTH;
|
||||
} else
|
||||
if (MAP_HEIGHT==-1) {
|
||||
std::stringstream stream(data);
|
||||
stream>>MAP_HEIGHT;
|
||||
} else {
|
||||
if (MAP==NULL) {
|
||||
MAP=(int**)malloc(sizeof(int**)*MAP_HEIGHT);
|
||||
}
|
||||
MAP[y]=(int*)malloc(sizeof(int*)*MAP_WIDTH);
|
||||
for (int i=0;i<data.length();i++) {
|
||||
MAP[y][i]=data[i]-'0';
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int y=0;y<MAP_HEIGHT;y++) {
|
||||
for (int x=0;x<MAP_WIDTH;x++) {
|
||||
printf("%d",MAP[y][x]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
SetPixelMode(olc::Pixel::ALPHA);
|
||||
//ConsoleCaptureStdOut(true);
|
||||
// Called once at the start, so create things here
|
||||
LoadMap("map1");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -66,13 +111,31 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
void fadeOutCompleted() {
|
||||
switch (GAME_STATE) {
|
||||
case CUTSCENE_1:{
|
||||
GAME_STATE=GAMEWORLD;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void fadeInCompleted() {
|
||||
|
||||
}
|
||||
|
||||
void updateGame(){
|
||||
frameCount++;
|
||||
if (fade&&transparency<255) {
|
||||
transparency=clamp(transparency+FADE_SPD,0,255);
|
||||
if (transparency==255) {
|
||||
fadeOutCompleted();
|
||||
}
|
||||
} else
|
||||
if (!fade&&transparency>0) {
|
||||
transparency=clamp(transparency-FADE_SPD,0,255);
|
||||
if (transparency==0) {
|
||||
fadeInCompleted();
|
||||
}
|
||||
}
|
||||
switch (GAME_STATE) {
|
||||
case CUTSCENE_1:{
|
||||
|
Binary file not shown.
BIN
assets/dome.png
Normal file
BIN
assets/dome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
41
assets/maps/map1
Normal file
41
assets/maps/map1
Normal file
@ -0,0 +1,41 @@
|
||||
103
|
||||
39
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000111111111111111111111111111111111110000000000000000000000000000000000000000000000
|
||||
000000002222222222222111111111111111111111111111111111110000000000000000000000000000000000000000000000
|
||||
000000002222222222222111111111111111111111111111111111110000000000000000000000000000000000000000000000
|
||||
000000000000000000000111111111111111111111111111111111110000000000000000000000000000000000000000000000
|
||||
000000000000000000000111111111111111111111111111111111110000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
BIN
assets/player.png
Normal file
BIN
assets/player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/tiles.png
Normal file
BIN
assets/tiles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Loading…
x
Reference in New Issue
Block a user