diff --git a/Makefile b/Makefile index 8bab3c7..6e787ad 100644 --- a/Makefile +++ b/Makefile @@ -383,7 +383,8 @@ PROJECT_SOURCE_FILES ?= \ $(PROJECT_SOURCE_PATH)/Credits.c \ $(PROJECT_SOURCE_PATH)/Gameover.c \ $(PROJECT_SOURCE_PATH)/Options.c \ - $(PROJECT_SOURCE_PATH)/Ending.c + $(PROJECT_SOURCE_PATH)/Ending.c \ + $(PROJECT_SOURCE_PATH)/LevelSel.c # Define all object files from source files OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES)) diff --git a/Makefile.emscripten b/Makefile.emscripten index 96046ae..29f6bda 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -383,7 +383,8 @@ PROJECT_SOURCE_FILES ?= \ $(PROJECT_SOURCE_PATH)/Credits.c \ $(PROJECT_SOURCE_PATH)/Gameover.c \ $(PROJECT_SOURCE_PATH)/Options.c \ - $(PROJECT_SOURCE_PATH)/Ending.c + $(PROJECT_SOURCE_PATH)/Ending.c \ + $(PROJECT_SOURCE_PATH)/LevelSel.c # Define all object files from source files OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES)) diff --git a/src/Controls.h b/src/Controls.h index a2c7dc1..62caf71 100644 --- a/src/Controls.h +++ b/src/Controls.h @@ -11,6 +11,8 @@ #define INPUT_UP_PRESSED IsKeyPressed(KEY_UP) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_LEFT_FACE_UP) #define INPUT_DOWN_PRESSED IsKeyPressed(KEY_DOWN) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_LEFT_FACE_DOWN) +#define INPUT_LEFT_PRESSED IsKeyPressed(KEY_LEFT) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_LEFT_FACE_LEFT) +#define INPUT_RIGHT_PRESSED IsKeyPressed(KEY_RIGHT) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) #define INPUT_OPTION_PRESSED IsKeyPressed(KEY_ENTER) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_MIDDLE_RIGHT) #define INPUT_FIRE_PRESSED IsKeyPressed(KEY_Z) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) diff --git a/src/Gameplay.c b/src/Gameplay.c index 402ea30..ced657e 100644 --- a/src/Gameplay.c +++ b/src/Gameplay.c @@ -18,7 +18,6 @@ #include "Gfx.h" int score = 0, bestscore = 0, finishfromGameplayScreen = 0; -Levels level = 0; Music Gameplaysong = { 0 }; @@ -41,8 +40,6 @@ void InitGameplayScreen(void) finishfromGameplayScreen = 0; - level = LEVEL1; - globalTimer = 0; player.currentframe = 0; @@ -240,6 +237,8 @@ void UpdateGameplayScreen(void) if (IsKeyPressed(KEY_G)) finishfromGameplayScreen = 1; if (IsKeyPressed(KEY_R)) finishfromGameplayScreen = 2; if (IsKeyPressed(KEY_W)) finishfromGameplayScreen = 3; + if (IsKeyPressed(KEY_EQUAL)) level++; + if (IsKeyPressed(KEY_MINUS)) level--; // call gameover when killed if (player.hp < 1) { StopMusicStream(Gameplaysong); finishfromGameplayScreen = 1; } @@ -249,14 +248,6 @@ void UpdateGameplayScreen(void) if (shoot[i].active) { shoot[i].hitbox.x += shoot[i].speed.x * GetFrameTime(); } - - if (CheckCollisionRecs(shoot[i].hitbox, enemy.hitbox) && shoot[i].active) { - DamageActor(&enemy); - scoreTimer += 300; - enemy.hitbox.y = GetRandomValue(0, GetScreenHeight()); - shoot[i].active = false; - } - if (shoot[i].hitbox.x + shoot[i].hitbox.width >= GetScreenWidth() + attack_sprite.width) shoot[i].active = false; } @@ -282,11 +273,20 @@ void UpdateGameplayScreen(void) } // Enemy logic - if (level < 3) { + if (level == 2) { if ((int)globalTimer % 40 == 0) enemy.hitbox.y = GetRandomValue(0, GetScreenHeight() - enemy_sprite.height); if (CheckCollisionRecs(player.hitbox, enemy.hitbox)) DamageActor(&player); + for (int i = 0; i < MAX_SHOOTS; i++) { + if (CheckCollisionRecs(shoot[i].hitbox, enemy.hitbox) && shoot[i].active) { + DamageActor(&enemy); + scoreTimer += 300; + enemy.hitbox.y = GetRandomValue(0, GetScreenHeight()); + shoot[i].active = false; + } + } + if (enemy.hp < 1) { level++; enemy.hp = 5; } } @@ -347,13 +347,13 @@ void DrawGameplayScreen(void) DrawText(TextFormat("GetTime(): %f", GetTime()), 10, 340, 20, GREEN); } if (feather.active) DrawTexture(feather_sprite, feather.sprite_pos.x, feather.sprite_pos.y, feather.color); - DrawTextureRec(enemy_sprite, enemy.frameRec, enemy.sprite_pos, enemy.color); for (int i = 0; i < MAX_FIREWORKS; i++) { DrawTexture(firework_sprite, fireworks[i].sprite_pos.x, fireworks[i].sprite_pos.y, fireworks[i].color); } for (int i = 0; i < MAX_SHOOTS; i++) { if (shoot[i].active) DrawTexture(attack_sprite, shoot[i].sprite_pos.x, shoot[i].sprite_pos.y, shoot[i].color); } + if (level == 2) DrawTextureRec(enemy_sprite, enemy.frameRec, enemy.sprite_pos, enemy.color); DrawTextureRec(player_sprite, player.frameRec, player.sprite_pos, player.color); DrawTexture(feather_sprite, 0, 0, GREEN); DrawText(TextFormat("= %i", player.hp), 30, 30, 30, GREEN); diff --git a/src/Gameplay.h b/src/Gameplay.h index 670750e..ba7e49b 100644 --- a/src/Gameplay.h +++ b/src/Gameplay.h @@ -9,8 +9,6 @@ #ifndef GAMEPLAY_HEADER #define GAMEPLAY_HEADER -typedef enum Levels { LEVEL1 = 0, LEVEL2, LEVEL3 } Levels; - #define MAX_FIREWORKS 10 #define PLAYER_HP 3 #define MAX_SHOOTS 3 diff --git a/src/LevelSel.c b/src/LevelSel.c new file mode 100644 index 0000000..2b5bd7e --- /dev/null +++ b/src/LevelSel.c @@ -0,0 +1,56 @@ +/* +- Avoid ~ a game by Canneddonuts +- Filename ~ LevelSel.c +- Author ~ Return0ne +- 2022 +- *no license* +*/ + +#include "../include/raylib.h" + +#include "Screens.h" +#include "Controls.h" +#include "Gfx.h" + +int finishfromLevelSelScreen = 0, levelSelected = 0; + +void InitLevelSelScreen(void) +{ + levelSelected = 0; + finishfromLevelSelScreen = 0; +} + +void UpdateLevelSelScreen(void) +{ + if (INPUT_LEFT_PRESSED) levelSelected++; + if (INPUT_RIGHT_PRESSED) levelSelected--; + if (levelSelected > 0) levelSelected--; + if (levelSelected < -2) levelSelected++; + + 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) +{ + DrawTexture(background, 0, 0, GRAY); + + if (levelSelected == 0) DrawText("1", 100, 220, 30, WHITE); + else DrawText("1", 100, 220, 30, BLUE); + + if (levelSelected == -1) DrawText("2", 150, 220, 30, WHITE); + else DrawText("2", 150, 220, 30, BLUE); + + if (levelSelected == -2) DrawText("3", 200, 220, 30, WHITE); + else DrawText("3", 200, 220, 30, BLUE); +} + +void UnloadLevelSelScreen(void) +{ +} + +int FinishLevelSelScreen(void) +{ + return finishfromLevelSelScreen; +} diff --git a/src/Main.c b/src/Main.c index 61c2fa2..69cec9e 100644 --- a/src/Main.c +++ b/src/Main.c @@ -26,6 +26,7 @@ static int transFromScreen = -1; static int transToScreen = -1; GameScreen currentScreen = 0; +Levels level = 0; Texture2D background; Texture2D player_sprite; @@ -73,6 +74,7 @@ void gameSetup(void) { // asset loading & setting of variable values currentScreen = TITLE; + level = LEVEL1; background = LoadTexture("assets/gfx/background.png"); ZadoBold = LoadFontEx("assets/fonts/ZadoBold.ttf", 96, 0, 110); @@ -104,6 +106,7 @@ static void update_transition(void) case CREDITS: UnloadCreditsScreen(); break; case OPTIONS: UnloadOptionsScreen(); break; case ENDING: UnloadEndingScreen(); break; + case LEVELSEL: UnloadLevelSelScreen(); break; default: break; } @@ -114,6 +117,7 @@ static void update_transition(void) case CREDITS: InitCreditsScreen(); break; case OPTIONS: InitOptionsScreen(); break; case ENDING: InitEndingScreen(); break; + case LEVELSEL: InitLevelSelScreen(); break; default: break; } @@ -154,7 +158,7 @@ static void update_draw_frame(void) switch (FinishTitleScreen()) { case 1: transition_to_screen(CREDITS); break; - case 2: transition_to_screen(GAMEPLAY); break; + case 2: transition_to_screen(LEVELSEL); break; case 3: transition_to_screen(OPTIONS); break; } } break; @@ -188,6 +192,11 @@ static void update_draw_frame(void) if (FinishEndingScreen() == 1) transition_to_screen(TITLE); } break; + case LEVELSEL: { + UpdateLevelSelScreen(); + + if (FinishLevelSelScreen() == 1) transition_to_screen(GAMEPLAY); + } break; default: break; } } else update_transition(); @@ -203,6 +212,7 @@ static void update_draw_frame(void) case GAMEOVER: DrawGameoverScreen(); break; case OPTIONS: DrawOptionsScreen(); break; case ENDING: DrawEndingScreen(); break; + case LEVELSEL: DrawLevelSelScreen(); break; default: break; } @@ -222,6 +232,7 @@ static void unloadGame(void) case CREDITS: UnloadCreditsScreen(); break; case OPTIONS: UnloadOptionsScreen(); break; case ENDING: UnloadEndingScreen(); break; + case LEVELSEL: UnloadLevelSelScreen(); break; default: break; } diff --git a/src/Screens.h b/src/Screens.h index 78aa3a1..09266cf 100644 --- a/src/Screens.h +++ b/src/Screens.h @@ -9,9 +9,11 @@ #ifndef SCREENS_HEADER #define SCREENS_HEADER -typedef enum GameScreen { TITLE = 0, GAMEPLAY, GAMEOVER, CREDITS, OPTIONS, ENDING } GameScreen; +typedef enum GameScreen { TITLE = 0, GAMEPLAY, GAMEOVER, CREDITS, OPTIONS, ENDING, LEVELSEL } GameScreen; +typedef enum Levels { LEVEL1 = 0, LEVEL2, LEVEL3 } Levels; extern GameScreen currentScreen; +extern Levels level; void InitTitleScreen(void); void UpdateTitleScreen(void); @@ -50,4 +52,10 @@ void DrawEndingScreen(void); void UnloadEndingScreen(void); int FinishEndingScreen(void); +void InitLevelSelScreen(void); +void UpdateLevelSelScreen(void); +void DrawLevelSelScreen(void); +void UnloadLevelSelScreen(void); +int FinishLevelSelScreen(void); + #endif diff --git a/src/Title.c b/src/Title.c index 90153ac..58afd00 100644 --- a/src/Title.c +++ b/src/Title.c @@ -30,6 +30,7 @@ void DrawScore(void) void InitTitleScreen(void) { + titleSelected = 0; finishfromTitleScreen = 0; }