added character position saving
This commit is contained in:
+19
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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