added character position saving

This commit is contained in:
2025-09-03 17:03:39 +02:00
parent 7a7d0ad6d7
commit d21606a3b5
3 changed files with 37 additions and 1 deletions
+19 -1
View File
@@ -2,6 +2,7 @@
#include "entities/entitybase.hpp"
#include "render/textures.hpp"
#include "tiles/tilebase.hpp"
#include "saving/saving.hpp"
#include <cmath>
#include <cstdlib>
@@ -19,6 +20,12 @@ void PlayerController(Entity &e, float deltatime) {
e.rect.y += acceleration.y * 100 * deltatime;
}
struct Tiles {
int chunkx;
int chunky;
int tileindex;
};
int main() {
int screenWidth = 1200;
int screenHeight = 800;
@@ -97,6 +104,7 @@ int main() {
gamemap.layers[1].chunks[Coordinate{chunkx, chunky}].tiles[tileindex].spriteid = 1;
}
@@ -111,12 +119,22 @@ int main() {
player.Draw();
EndMode2D();
EndDrawing();
}
// 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;
}
+11
View File
@@ -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();
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef SAVES_HPP
#define SAVES_HPP
void SaveGame(int x, int y);
void LoadGame(int &x, int &y);
#endif