added character position saving
This commit is contained in:
+19
-1
@@ -2,6 +2,7 @@
|
|||||||
#include "entities/entitybase.hpp"
|
#include "entities/entitybase.hpp"
|
||||||
#include "render/textures.hpp"
|
#include "render/textures.hpp"
|
||||||
#include "tiles/tilebase.hpp"
|
#include "tiles/tilebase.hpp"
|
||||||
|
#include "saving/saving.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
@@ -19,6 +20,12 @@ void PlayerController(Entity &e, float deltatime) {
|
|||||||
e.rect.y += acceleration.y * 100 * deltatime;
|
e.rect.y += acceleration.y * 100 * deltatime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Tiles {
|
||||||
|
int chunkx;
|
||||||
|
int chunky;
|
||||||
|
int tileindex;
|
||||||
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int screenWidth = 1200;
|
int screenWidth = 1200;
|
||||||
int screenHeight = 800;
|
int screenHeight = 800;
|
||||||
@@ -97,6 +104,7 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
gamemap.layers[1].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
|
gamemap.layers[1].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,12 +119,22 @@ int main() {
|
|||||||
|
|
||||||
player.Draw();
|
player.Draw();
|
||||||
|
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnloadTexture() and CloseWindow() are called automatically.
|
// UnloadTexture() and CloseWindow() are called automatically.
|
||||||
|
|
||||||
|
std::cout << "Saving Data...\n";
|
||||||
|
|
||||||
|
std::cout << "Player is at: " << player.rect.x << ", " << player.rect.y << "\n";
|
||||||
|
std::cout << "chunkx: " << chunkx << "\n";
|
||||||
|
std::cout << "chunky: " << chunky << "\n";
|
||||||
|
// std::cout << "tileindex: " << tileindex << "\n";
|
||||||
|
|
||||||
|
SaveGame(player.rect.x, player.rect.y);
|
||||||
|
|
||||||
|
std::cout << "Data Saved!\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void SaveGame(int x, int y) {
|
||||||
|
ofstream outfile("save.json");
|
||||||
|
|
||||||
|
outfile << x << " " << y << std::endl;
|
||||||
|
|
||||||
|
outfile.close();
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef SAVES_HPP
|
||||||
|
#define SAVES_HPP
|
||||||
|
|
||||||
|
void SaveGame(int x, int y);
|
||||||
|
void LoadGame(int &x, int &y);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user