From 135a64e178292d348bc31d72e1bf800d80e9bdef Mon Sep 17 00:00:00 2001 From: Layla Marchant Date: Sat, 26 Dec 2020 00:07:51 -0500 Subject: [PATCH] Reposition stars on resize --- src/game.c | 21 +++++++++++++++------ src/game.h | 1 + src/player.c | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/game.c b/src/game.c index a237987..df51ef4 100644 --- a/src/game.c +++ b/src/game.c @@ -175,12 +175,7 @@ void game_init() player.weaponType[0] = W_PLAYER_WEAPON; player.weaponType[1] = W_ROCKETS; - for (int i = 0 ; i < STARS_NUM ; i++) - { - stars[i].x = rand() % screen->w; - stars[i].y = rand() % screen->h; - stars[i].speed = 1 + (rand() % 3); - } + game_setStars(); weapons_init(); mission_init(); @@ -228,6 +223,19 @@ static void game_addDebris(int x, int y, int amount) } } +/* +Sets star positions. Must do this any time the window size changes. +*/ +void game_setStars() +{ + for (int i = 0 ; i < STARS_NUM ; i++) + { + stars[i].x = rand() % screen->w; + stars[i].y = rand() % screen->h; + stars[i].speed = 1 + (rand() % 3); + } +} + /* Simply draws the stars in their positions on screen and moves them around. @@ -2789,6 +2797,7 @@ int game_mainLoop() } else { + player_getInput(); LIMIT_ADD(engine.musicVolume, -0.2, 0, 100); audio_setMusicVolume(engine.musicVolume); if (SDL_GetTicks() >= engine.missionCompleteTimer) diff --git a/src/game.h b/src/game.h index ee33d44..55f4cba 100644 --- a/src/game.h +++ b/src/game.h @@ -99,6 +99,7 @@ extern Game game; extern char game_systemNames[SYSTEM_MAX][STRMAX_SHORT]; void game_init(); +void game_setStars(); void game_doStars(); void game_doExplosions(); void game_delayFrame(); diff --git a/src/player.c b/src/player.c index 3054526..b3d9a36 100644 --- a/src/player.c +++ b/src/player.c @@ -458,6 +458,7 @@ void player_getInput() if (engine.event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { screen_adjustDimensions(engine.event.window.data1, engine.event.window.data2); + game_setStars(); renderer_reset(); gfx_scaleBackground(); screen_clear(black);