feat: add pos and rotation saving

This commit is contained in:
2026-03-08 17:55:00 +01:00
parent 341b675fa9
commit 9aac4a8d44
3 changed files with 10 additions and 11 deletions
+2 -1
View File
@@ -42,7 +42,8 @@ typedef enum View { LOGO = 0, MENU = 1, GAMEPLAY = 2 } View;
typedef enum { typedef enum {
STORAGE_POSITION_GOLD = 0, STORAGE_POSITION_GOLD = 0,
STORAGE_POSITION_POSX = 1, STORAGE_POSITION_POSX = 1,
STORAGE_POSITION_POSY = 2 STORAGE_POSITION_POSY = 2,
STORAGE_POSITION_ROTATION = 3
} StorageData; } StorageData;
// STRUCTS// // STRUCTS//
+1 -1
View File
@@ -99,7 +99,7 @@ void RenderGame(App *app) {
(Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE); (Vector2){g->mouse.screenPosition.x, g->mouse.screenPosition.y}, WHITE);
Player *player = GetPlayer(); Player *player = GetPlayer();
DrawText(TextFormat("Gold: %d", player->gold), 0.0f, 0.0f, 12.0f, YELLOW); DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW);
EndTextureMode(); EndTextureMode();
BeginDrawing(); BeginDrawing();
+7 -9
View File
@@ -40,9 +40,8 @@ void CreatePlayer(void)
Texture2D texture = LoadTexture(startShipAsset.path); Texture2D texture = LoadTexture(startShipAsset.path);
float frameWidth = startShipAsset.frameWidth; float frameWidth = startShipAsset.frameWidth;
float rotation = startShipAsset.rotation; float rotation = (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION);
Sprite playerSprite = { Sprite playerSprite = {
.texture = texture, .texture = texture,
.frameSize = {frameWidth, frameWidth}, .frameSize = {frameWidth, frameWidth},
@@ -62,9 +61,8 @@ void CreatePlayer(void)
.animTimer = 0.0f .animTimer = 0.0f
}; };
Physics playerPhysics = { Physics playerPhysics = {
.position = (Vector2){0.0f,0.0f}, .position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)},
.direction = (Vector2){0.0f, 0.0f}, .direction = (Vector2){0.0f, 0.0f},
.speed = playerSpeeds[ANCHOR] .speed = playerSpeeds[ANCHOR]
}; };
@@ -127,12 +125,12 @@ void UpdatePlayer(void)
} }
player->sprite.rotation = player->rotation; player->sprite.rotation = player->rotation;
Vector2 dir = RotationToVector2(player->rotation - 90.0f); Vector2 dir = RotationToVector2(player->rotation - 90.0f);
UpdatePhysics(&player->physics, dir);
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
UpdatePhysics(&player->physics, dir); SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX, (int)player->physics.position.x);
UpdateSpriteDestRec(&player->sprite, &player->physics.position); SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y);
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION, (int)player->rotation);
} }
void RenderPlayer(void){ void RenderPlayer(void){