From bc9239174a1cf7a0916636768d71b68637190f7f Mon Sep 17 00:00:00 2001 From: Mark B Date: Sun, 2 Oct 2022 15:58:18 -0400 Subject: [PATCH] working on a better unlock system --- src/Gameplay.c | 2 +- src/LevelSel.c | 36 +++++++++++++++++++++--------------- src/Screens.h | 4 +++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/Gameplay.c b/src/Gameplay.c index fb8db13..fb58857 100644 --- a/src/Gameplay.c +++ b/src/Gameplay.c @@ -193,7 +193,7 @@ void UpdateGameplayScreen(void) if (INPUT_OPTION_PRESSED) pause = !pause; // code to end the game if (level > 2) { StopMusicStream(Gameplaysong); finishfromGameplayScreen = 3; } - if (CheckFireworkActivity() && level < 2) { StopMusicStream(Gameplaysong); levelunlocked++; finishfromGameplayScreen = 4; } + if (CheckFireworkActivity() && level < 2) { StopMusicStream(Gameplaysong); levelunlocked[nextlevel] = true; nextlevel++; finishfromGameplayScreen = 4; } if (!mute) UpdateMusicStream(Gameplaysong); diff --git a/src/LevelSel.c b/src/LevelSel.c index 3bbc208..fd0fd42 100644 --- a/src/LevelSel.c +++ b/src/LevelSel.c @@ -13,10 +13,13 @@ #include "Controls.h" #include "Gfx.h" -int finishfromLevelSelScreen = 0, levelSelected = 1, levelunlocked = 0; +int finishfromLevelSelScreen = 0, levelSelected = 0, nextlevel = 1; +bool levelunlocked[3] = {1, 0 , 0}; void InitLevelSelScreen(void) { + nextlevel = level + 1; + feather_sprite = LoadTexture("assets/gfx/feather.png"); finishfromLevelSelScreen = 0; } @@ -24,13 +27,13 @@ void InitLevelSelScreen(void) void UpdateLevelSelScreen(void) { if (INPUT_LEFT_PRESSED) levelSelected--; - if (INPUT_RIGHT_PRESSED) if (levelunlocked >= levelSelected) levelSelected++; - if (levelSelected < 1) levelSelected++; - if (levelSelected > 3) levelSelected--; + if (INPUT_RIGHT_PRESSED) if (levelunlocked[levelSelected+1]) levelSelected++; + if (levelSelected < 0) levelSelected++; + if (levelSelected > 2) levelSelected--; - if ((levelSelected == 1) && (INPUT_OPTION_PRESSED)) { level = LEVEL1; finishfromLevelSelScreen = 1; } - if ((levelSelected == 2) && (INPUT_OPTION_PRESSED)) { level = LEVEL2; finishfromLevelSelScreen = 1; } - if ((levelSelected == 3) && (INPUT_OPTION_PRESSED)) { level = LEVEL3; finishfromLevelSelScreen = 1; } + if ((levelSelected == 0) && (INPUT_OPTION_PRESSED)) { level = LEVEL1; finishfromLevelSelScreen = 1; } + if ((levelSelected == 1) && (INPUT_OPTION_PRESSED)) { level = LEVEL2; finishfromLevelSelScreen = 1; } + if ((levelSelected == 2) && (INPUT_OPTION_PRESSED)) { level = LEVEL3; finishfromLevelSelScreen = 1; } } void DrawLevelSelScreen(void) @@ -44,16 +47,19 @@ void DrawLevelSelScreen(void) if (score >= 10000) DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, (Color){ 222, 181, 0, 255 }); else DrawText(TextFormat("SCORE: %i", score), 10, 65, 30, BLUE); - if (levelSelected == 1) DrawText("1", 100, 220, 30, WHITE); - else DrawText("1", 100, 220, 30, BLUE); + if (levelSelected == 0) DrawText("1", 100, 220, 60, WHITE); + else DrawText("1", 100, 220, 60, BLUE); - if (levelSelected == 2) DrawText("2", 150, 220, 30, WHITE); - else if (levelunlocked >= 1) DrawText("2", 150, 220, 30, BLUE); - else DrawText("2", 150, 220, 30, GRAY); + if (levelSelected == 1) DrawText("2", 200, 220, 60, WHITE); + else if (levelunlocked[1]) DrawText("2", 200, 220, 60, BLUE); + else DrawText("2", 200, 220, 60, GRAY); - if (levelSelected == 3) DrawText("3", 200, 220, 30, WHITE); - else if (levelunlocked >= 2) DrawText("3", 200, 220, 30, BLUE); - else DrawText("3", 200, 220, 30, GRAY); + if (levelSelected == 2) DrawText("3", 300, 220, 60, WHITE); + else if (levelunlocked[2]) DrawText("3", 300, 220, 60, BLUE); + else DrawText("3", 300, 220, 60, GRAY); + + // printf("%d, %d, %d\n", levelunlocked[0], levelunlocked[1], levelunlocked[2]); + printf("%d\n", levelunlocked[nextlevel]); } void UnloadLevelSelScreen(void) diff --git a/src/Screens.h b/src/Screens.h index 44e377c..a417b38 100644 --- a/src/Screens.h +++ b/src/Screens.h @@ -14,7 +14,9 @@ typedef enum Levels { LEVEL1 = 0, LEVEL2, LEVEL3 } Levels; extern GameScreen currentScreen; extern Levels level; -extern int levelunlocked; +extern int nextlevel; +extern bool levelunlocked[3]; + void InitTitleScreen(void); void UpdateTitleScreen(void);