From 1d548eaa4b796f0416247f69074dfeec0264dd71 Mon Sep 17 00:00:00 2001 From: noshbar Date: Wed, 10 Oct 2018 22:05:13 +0200 Subject: [PATCH] 3 minor sample game cleanups: * changed bitwise & to logical && * removed redundant state check * moved a strcpy inside a NULL check to prevent a crash. NOTE: nothing sensible will happen as a result, but no crash at least. --- games/just_do/screens/screen_level06.c | 2 +- games/koala_seasons/screens/screen_gameplay.c | 2 +- games/transmission/screens/screen_ending.c | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/games/just_do/screens/screen_level06.c b/games/just_do/screens/screen_level06.c index a5536aa4..ec72d70c 100644 --- a/games/just_do/screens/screen_level06.c +++ b/games/just_do/screens/screen_level06.c @@ -132,7 +132,7 @@ void DrawLevel06Screen(void) DrawRectangleRec(movingRecs[i], GRAY); } - if (!done & (mouseOverNum >= 0)) DrawRectangleLines(movingRecs[mouseOverNum].x - 5, movingRecs[mouseOverNum].y - 5, movingRecs[mouseOverNum].width + 10, movingRecs[mouseOverNum].height + 10, Fade(LIGHTGRAY, 0.8f)); + if (!done && (mouseOverNum >= 0)) DrawRectangleLines(movingRecs[mouseOverNum].x - 5, movingRecs[mouseOverNum].y - 5, movingRecs[mouseOverNum].width + 10, movingRecs[mouseOverNum].height + 10, Fade(LIGHTGRAY, 0.8f)); if (levelFinished) { diff --git a/games/koala_seasons/screens/screen_gameplay.c b/games/koala_seasons/screens/screen_gameplay.c index 6bbcfaaf..4d8ff04d 100644 --- a/games/koala_seasons/screens/screen_gameplay.c +++ b/games/koala_seasons/screens/screen_gameplay.c @@ -954,7 +954,7 @@ void UpdateGameplayScreen(void) playerActive = false; killer = 5; } - else if (CheckCollisionRecs(bee, player) && (state == FINALFORM) && (state != KICK)) + else if (CheckCollisionRecs(bee, player) && (state == FINALFORM)) { isHitBee = true; beeVelocity = 8; diff --git a/games/transmission/screens/screen_ending.c b/games/transmission/screens/screen_ending.c index 0aba5f01..d0cf7d89 100644 --- a/games/transmission/screens/screen_ending.c +++ b/games/transmission/screens/screen_ending.c @@ -110,10 +110,12 @@ void InitEndingScreen(void) { // WARNING: It fails if the last sentence word has a '.' after space char *title = StringReplace(headline, messageWords[i].text, codingWords[messageWords[i].id]); - - strcpy(headline, title); // Base headline updated - - if (title != NULL) free(title); + + if (title != NULL) + { + strcpy(headline, title); // Base headline updated + free(title); + } } }