From d0db8231fb62834262275e72dfec2a151ca61fd9 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 29 Nov 2020 18:43:09 +1000 Subject: [PATCH] level seed tweak --- src/basic-lib.c | 1 - src/draw.c | 20 ++++++++++---------- src/game.c | 21 +++++++++++++-------- src/main.c | 5 ++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/basic-lib.c b/src/basic-lib.c index 25380e1..e46df59 100644 --- a/src/basic-lib.c +++ b/src/basic-lib.c @@ -93,6 +93,5 @@ void get_time(void) { replace_char(&(newstr[0]), "\n"); printf("%s", newstr); - } diff --git a/src/draw.c b/src/draw.c index f936e54..d6cc13d 100644 --- a/src/draw.c +++ b/src/draw.c @@ -547,28 +547,28 @@ int draw_end_screen(SDL_Renderer *ren) { Vect position = {.x = width/3, .y = height / 4}; draw_text(ren, position, colour, end_str); - position.y += 40; + position.y += 60; char level_string[250]; snprintf(level_string, 250,"course: %d", level); draw_text(ren, position, colour, level_string); position.y += 40; - char qual_str[250]; - snprintf(qual_str, 250, "physics quality: %d", quality); - draw_text(ren, position, colour, qual_str); - position.y += 40; - - - char fastest_time[250]; minutes = fastest / 60000; seconds = fastest * 0.001; if (fastest > 0) { - position.y += 40; snprintf(fastest_time, 250, "old best time: %d:%.4f", minutes, seconds); draw_text(ren, position, colour, fastest_time); + position.y += 40; } + + char qual_str[250]; + snprintf(qual_str, 250, "physics quality: %d", quality); + draw_text(ren, position, colour, qual_str); + position.y += 40; + + minutes = level_time / 60000; seconds = level_time * 0.001; if (level_time > fastest) { @@ -578,7 +578,7 @@ int draw_end_screen(SDL_Renderer *ren) { snprintf(time_string, 250, "NEW BEST TIME: %d:%.4f", minutes, seconds); } - Vect position2 = {.x = 3 * width/5, .y = 40 + height / 4}; + Vect position2 = {.x = 3 * width/5, .y = 60 + height / 4}; if (fastest > 0) { //position.y += 40; diff --git a/src/game.c b/src/game.c index 0b1a485..0c8ee42 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,5 @@ #include "game.h" +#include "draw.h" #include #include #include @@ -101,7 +102,7 @@ int load_score_times(char *filename) { fn = malloc(fnlen); snprintf(fn, fnlen, "%s-%s", filename, lvl_str); - printf("%d, lvl_str %s fn %s\n", level, lvl_str, fn); + //printf("%d, lvl_str %s fn %s\n", level, lvl_str, fn); FILE *f = fopen(fn, "r"); // unload existing score times @@ -116,7 +117,7 @@ int load_score_times(char *filename) { fseek(f, 0L, SEEK_END); long sz = ftell(f); fseek(f, 0L, SEEK_SET); - char *text = malloc((sz + 1) * (sizeof(char))); + char *text = calloc((sz + 1), (sizeof(char))); // read file fread(text,sizeof(char),sz, f); @@ -697,7 +698,7 @@ void next_level() { destroy_physics_collection(&world.uniques_index[ROOM_W]->room->floor); destroy_environment(&world.uniques_index[ROOM_W]->room->env); - level *= 7;; + level += 1;; get_floor_ceiling(); load_score_times("saves/times"); @@ -709,8 +710,11 @@ void next_level() { quality = 100; level_timer_update(true); - SDL_UnlockMutex(player.physics->lock); + viewport_pos.x = player.physics->position.x - width / 2; + viewport_pos.y = player.physics->position.y - height / 2; + + SDL_UnlockMutex(player.physics->lock); } int get_floor_ceiling() { @@ -1532,8 +1536,8 @@ void get_room(void) { FloorPoly *ceil = generate_floor_simple(floorsize, false, 1000); - printf("floor: %f %f\n", polys[2].left.x, polys[2].left.y); - printf("ceil: %f %f\n", ceil[2].left.x, ceil[2].left.y); +// printf("floor: %f %f\n", polys[2].left.x, polys[2].left.y); +// printf("ceil: %f %f\n", ceil[2].left.x, ceil[2].left.y); Floor* ceiling = calloc(1, sizeof(Floor)); ceiling->polys = ceil; @@ -1563,7 +1567,7 @@ void startgame(SDL_Renderer * ren) { debug_ren = ren; - level = 31; + level = 0; save_times_lst = (struct sg_times_list){}; load_score_times("saves/times"); @@ -1591,6 +1595,8 @@ void startgame(SDL_Renderer * ren) { level_timer_update(true); game_paused = 0; + viewport_pos.x = player.physics->position.x - width / 2; + viewport_pos.y = player.physics->position.y - height / 2; //get_room(); } @@ -1669,7 +1675,6 @@ int get_rand(int seed) { const unsigned m = (1 << 31) - 1; const unsigned initial_n = 1; const unsigned a = 48271; - static unsigned n = initial_n; if (seed != 0) { diff --git a/src/main.c b/src/main.c index b21a0e1..51adbbb 100644 --- a/src/main.c +++ b/src/main.c @@ -58,8 +58,8 @@ int physics_loop(void *ptr) { SDL_LockMutex(player.physics->lock); game_paused = true; - in_game = true; next_level(); + in_game = true; SDL_UnlockMutex(player.physics->lock); SDL_Delay(1000); game_paused = 0; @@ -103,7 +103,7 @@ int game(void) { startgame(ren); - physics_thread = SDL_CreateThread(physics_loop, "Physics", (void *)ren); + physics_thread = SDL_CreateThread(physics_loop, "physics", (void *)ren); while (!close) { @@ -138,7 +138,6 @@ int game(void) { } - int main (int argc, char** argv) { int err = mkdirat(AT_FDCWD, "saves", 0777);