From: Randy McShandy Date: Wed, 11 Jun 2025 03:40:18 +0000 (-0500) Subject: Loading and saving looks okay X-Git-Url: http://git.mcshandy.xyz/gitweb.cgi?a=commitdiff_plain;h=4ae43560b92cf7078357454f223f044efa7b512e;p=barrow_crawler Loading and saving looks okay --- diff --git a/bin/posix_BC b/bin/posix_BC index 0970764..f485cce 100755 Binary files a/bin/posix_BC and b/bin/posix_BC differ diff --git a/src/render_raylib.c b/src/render_raylib.c index 0aa05d9..1390350 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -307,6 +307,16 @@ void control_game_mode() playtime.cam.position = cam_reset_position; } + if (IsKeyReleased(KEY_F4)) + { + const int success = save_game(playtime); + } + + if (IsKeyReleased(KEY_F5)) + { + const int success = load_game(); + } + if (IsKeyReleased(KEY_ONE)) orb_target_color = SKYBLUE; if (IsKeyReleased(KEY_TWO)) @@ -324,8 +334,9 @@ void control_game_mode() player_collision = GetRayCollisionMesh(player_collide_ray, barrow_model.meshes[0U], barrow_mat); playtime.player_rotation = player_rotation; - if (false && player_collision.hit && player_collision.distance < 1.30f) + if (player_collision.hit && player_collision.distance < 1.30f) { + playtime.player_velocity.x *= -1.05; } else diff --git a/src/shaders/lighting.fs b/src/shaders/lighting.fs index 41357dc..4d0f163 100644 --- a/src/shaders/lighting.fs +++ b/src/shaders/lighting.fs @@ -139,9 +139,9 @@ void main() lumWeights = vec4(1.0f) * lumWeight; lumWeights *= dot(finalColor, lumWeights); - //lighting_color = vec4(mix(orb_color.rgb * candle_weight, lumWeights.rgb, 0.2f), 1.0f); + lighting_color = vec4(mix(orb_color.rgb * candle_weight, lumWeights.rgb, 0.2f), 1.0f); //lighting_color = vec4(mix(candle_color.rgb * candle_weight, lumWeights.rgb, 0.4f), 1.0f); - //finalColor = finalColor * lighting_color; + finalColor = finalColor * lighting_color; float factor = 35.0; finalColor.r = round((finalColor.r) * factor) / factor; @@ -151,6 +151,4 @@ void main() // All single color channel variations with this looks cool as FUCK // turns this into three levels going b-r-g //finalColor.b = 0.0f; - - finalColor.a = 0.5f; } diff --git a/src/structs.h b/src/structs.h index e2420cd..35b5451 100644 --- a/src/structs.h +++ b/src/structs.h @@ -112,5 +112,7 @@ extern int resource_state; //int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size); void* generate_rd(void* args); +int save_game(PlaytimeData playtime); +int load_game(); #endif //__RD_STRUCTS__ diff --git a/src/utils.c b/src/utils.c index 7961a91..cf765c9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -5,6 +5,8 @@ #warning "TODO: I think these are only posix, check for alt platform replacements" #include +#include +#include #include #include "structs.h" @@ -266,3 +268,49 @@ void* generate_rd(void* args) return 0; } +int save_game(PlaytimeData playtime) +{ + int success = -1; + success = mkdir("./save", 0755); + + if ((success == 0) || (errno == EEXIST)) + { + + FILE* save_file = fopen("./save/save.dat", "w"); + char buf[sizeof(PlaytimeData)]; + + memcpy(buf, (char*)&playtime, sizeof(PlaytimeData)); + + if (save_file) + { + success = fwrite(buf, sizeof(PlaytimeData), 1U, save_file); + } + + success = fclose(save_file); + } + + return success; +} + +int load_game() +{ + + int success = -1; + + FILE* save_file = fopen("./save/save.dat", "r"); + + if (save_file) + { + char buf[sizeof(PlaytimeData)]; + const size_t bytes_read = fread(buf, 1U, sizeof(PlaytimeData), save_file); + + if (bytes_read == sizeof(PlaytimeData)) + { + memcpy((char*)&playtime, buf, sizeof(PlaytimeData)); + success = fclose(save_file); + } + } + + return success; +} +