GAME: Play the number guessing game -> PLAY NOW

feat: Added overlay animation & added soundtrack - freezo - A retro platform game

freezo

A retro platform game
git clone git@soophie.de:/srv/git/freezo
log | files | refs | readme

commit 3238b96f9db02ed03b8d51c7d017157fe1d62eaa
parent b20f2032d2e15cd3c64fbf5a98492b7b12d7ea36
Author: Sophie <info@soophie.de>
Date:   Mon, 16 Dec 2024 19:03:45 +0100

feat: Added overlay animation & added soundtrack

Diffstat:
Massets/tiles.png | 0
Aassets/track.wav | 0
Minclude/game.h | 5+++++
Msrc/game.c | 37++++++++++++++++++++++++++++++-------
Msrc/main.c | 6++++++
Msrc/player.c | 1+
6 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/assets/tiles.png b/assets/tiles.png Binary files differ. diff --git a/assets/track.wav b/assets/track.wav Binary files differ. diff --git a/include/game.h b/include/game.h @@ -9,6 +9,9 @@ typedef struct Game game_t; #include "menu.h" #include "level.h" #include "effect.h" +#include "door.h" + +#define GAME_SCEEN_TIMER 150 typedef enum { STATE_MENU, @@ -21,6 +24,7 @@ struct Assets { Texture2D font; Texture2D images; Texture2D background; + Sound track; }; struct Game { @@ -41,6 +45,7 @@ struct Game { Camera2D camera; int xp; int sceen_timer; + door_t *door; }; game_t *game_create(void); diff --git a/src/game.c b/src/game.c @@ -32,12 +32,14 @@ game_t *game_create(void) { .assets.font = texture_load("assets/font.png", SCALE - 1), .assets.images = texture_load("assets/images.png", SCALE), .assets.background = texture_load("assets/background.png", SCALE), + .assets.track = LoadSound("assets/track.wav"), .camera = (Camera2D) { .offset = (pos_t) { 0.0, 0.0 }, .zoom = 1, }, .xp = 0, .sceen_timer = 0, + .door = NULL, }; level_load(game, LEVEL_1); return game; @@ -57,7 +59,7 @@ void game_update(game_t *game) { if (game->level != NULL) { // defeat if (game->defeat) { - if (game->sceen_timer == 100) { + if (game->sceen_timer == GAME_SCEEN_TIMER) { level_e level = game->level->type; level_unload(game); level_load(game, level); @@ -71,7 +73,7 @@ void game_update(game_t *game) { } // victory if (game->victory) { - if (game->sceen_timer == 100) { + if (game->sceen_timer == GAME_SCEEN_TIMER) { if (game->level->type < LEVELS) { level_e level = game->level->type; level++; @@ -82,6 +84,9 @@ void game_update(game_t *game) { game->sceen_timer = 0; } else { + if (game->sceen_timer == 125) { + game->door->is_locked = true; + } game->sceen_timer++; } } @@ -131,8 +136,23 @@ void game_update(game_t *game) { } void game_draw(game_t *game) { - BeginDrawing(); + // render overlay + RenderTexture2D overlay_texture = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT); + BeginTextureMode(overlay_texture); ClearBackground(BLACK); + DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK); + BeginBlendMode(BLEND_SUBTRACT_COLORS); + int radius = WINDOW_WIDTH; + radius -= radius / 80.0 * game->sceen_timer; + if (radius < PLAYER_HEIGHT) { + radius = PLAYER_HEIGHT; + } + DrawCircle(game->player->pos.x + PLAYER_WIDTH / 2.0, WINDOW_HEIGHT - (game->player->pos.y + PLAYER_HEIGHT / 2.0), radius, WHITE); + EndBlendMode(); + EndTextureMode(); + // render sceen + BeginDrawing(); + ClearBackground((Color) { 5, 5, 5, 1 }); if (game->level != LEVEL_NULL) { BeginMode2D(game->camera); for (int i = 0; i < game->tiles_len; i++) { @@ -141,10 +161,14 @@ void game_draw(game_t *game) { for (int i = 0; i < game->entities_len; i++) { entity_draw(&game->entities[i], game); } - player_draw(game->player, game); + if (game->sceen_timer < 100) { + player_draw(game->player, game); + } for (int i = 0; i < game->effects_len; i++) { effect_draw(game->effects[i], game); } + // draw overlay + DrawTexture(overlay_texture.texture, 0, 0, WHITE); EndMode2D(); // draw interface int i = 0; @@ -172,14 +196,12 @@ void game_draw(game_t *game) { .y = TILE_WIDTH / 1.5 + 25, }; text_draw(level_pos, level_text, TEXT_ALIGNMENT_RIGHT, game); - if (game->defeat || game->victory) { - DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, (Color) { 0, 0, 0, 255 / 100 * game->sceen_timer }); - } } if (game->state == STATE_MENU) { menu_draw(game->menu, game); } EndDrawing(); + UnloadRenderTexture(overlay_texture); } void game_free(game_t *game) { @@ -192,5 +214,6 @@ void game_free(game_t *game) { UnloadTexture(game->assets.font); UnloadTexture(game->assets.images); UnloadTexture(game->assets.background); + UnloadSound(game->assets.track); free(game); } diff --git a/src/main.c b/src/main.c @@ -25,6 +25,9 @@ void handle_segfault(int signal) { game_t *game = NULL; void do_update(void) { + if (!IsSoundPlaying(game->assets.track)) { + PlaySound(game->assets.track); + } game_update(game); game_draw(game); } @@ -34,7 +37,9 @@ int main(void) { time_t t; srand((unsigned) time(&t)); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Freezo"); + InitAudioDevice(); game = game_create(); + SetSoundVolume(game->assets.track, 0.5); SetTargetFPS(60); SetExitKey(0); #if defined(PLATFORM_WEB) @@ -49,6 +54,7 @@ int main(void) { do_update(); } #endif + CloseAudioDevice(); CloseWindow(); game_free(game); return 0; diff --git a/src/player.c b/src/player.c @@ -356,6 +356,7 @@ void player_update(player_t *player, game_t *game) { player->pos.y + PLAYER_HEIGHT >= door->pos.y + tolerance ) { if (door_unlock(door, game)) { + game->door = door; game->victory = true; } }