commit 2a7c197039c59c249b85cd20fd86c3bd4aba56d2
parent b9882d640fa79f55499c9b329821fc152d4f411d
Author: Sophie <info@soophie.de>
Date: Tue, 17 Dec 2024 16:39:53 +0100
feat: Added box tile & fixed door collision & added sounds
Diffstat:
10 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/assets/lose.wav b/assets/lose.wav
Binary files differ.
diff --git a/assets/song.wav b/assets/song.wav
Binary files differ.
diff --git a/assets/tiles.png b/assets/tiles.png
Binary files differ.
diff --git a/assets/win.wav b/assets/win.wav
Binary files differ.
diff --git a/include/game.h b/include/game.h
@@ -12,7 +12,8 @@ typedef struct Game game_t;
#include "door.h"
#define GAME_SCEEN_TIMER 150
-#define GAME_SOUND_VOLUME 0.5f
+#define GAME_MUSIC_VOLUME 0.7f
+#define GAME_SOUND_VOLUME 1.0f
typedef enum {
STATE_MENU,
@@ -26,6 +27,8 @@ struct Assets {
Texture2D images;
Texture2D background;
Sound track;
+ Sound win;
+ Sound lose;
Sound locked;
};
diff --git a/include/tile.h b/include/tile.h
@@ -14,6 +14,7 @@ typedef enum {
TILE_STONE,
TILE_SNOW,
TILE_SAND,
+ TILE_BOX,
TILE_BG_CHANDELIER,
TILE_BG_WINDOW_1,
TILE_BG_WINDOW_2,
diff --git a/src/game.c b/src/game.c
@@ -32,7 +32,9 @@ 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"),
+ .assets.track = LoadSound("assets/song.wav"),
+ .assets.win = LoadSound("assets/win.wav"),
+ .assets.lose = LoadSound("assets/lose.wav"),
.assets.locked = LoadSound("assets/locked.wav"),
.camera = (Camera2D) {
.offset = (pos_t) { 0.0, 0.0 },
@@ -45,7 +47,9 @@ game_t *game_create(void) {
.is_muted = false,
};
level_load(game, LEVEL_1);
- SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);
+ SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);
+ SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);
+ SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);
return game;
}
@@ -55,14 +59,18 @@ void game_update(game_t *game) {
game->is_muted = !game->is_muted;
if (game->is_muted) {
SetSoundVolume(game->assets.track, 0.0f);
+ SetSoundVolume(game->assets.win, 0.0f);
+ SetSoundVolume(game->assets.lose, 0.0f);
SetSoundVolume(game->assets.locked, 0.0f);
}
else {
- SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);
+ SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);
+ SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);
+ SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);
}
}
- if (!IsSoundPlaying(game->assets.track)) {
+ if (!IsSoundPlaying(game->assets.track) && !game->victory && !game->defeat) {
PlaySound(game->assets.track);
}
switch (game->state) {
@@ -78,6 +86,12 @@ void game_update(game_t *game) {
if (game->level != NULL) {
// defeat
if (game->defeat) {
+ if (game->sceen_timer == 0) {
+ StopSound(game->assets.track);
+ }
+ if (game->sceen_timer == 20) {
+ PlaySound(game->assets.lose);
+ }
if (game->sceen_timer == GAME_SCEEN_TIMER) {
level_e level = game->level->type;
level_unload(game);
@@ -92,6 +106,12 @@ void game_update(game_t *game) {
}
// victory
if (game->victory) {
+ if (game->sceen_timer == 0) {
+ StopSound(game->assets.track);
+ }
+ if (game->sceen_timer == 20) {
+ PlaySound(game->assets.win);
+ }
if (game->sceen_timer == GAME_SCEEN_TIMER) {
if (game->level->type < LEVELS) {
level_e level = game->level->type;
@@ -247,6 +267,8 @@ void game_free(game_t *game) {
UnloadTexture(game->assets.images);
UnloadTexture(game->assets.background);
UnloadSound(game->assets.track);
+ UnloadSound(game->assets.win);
+ UnloadSound(game->assets.lose);
UnloadSound(game->assets.locked);
UnloadRenderTexture(game->overlay);
free(game);
diff --git a/src/level.c b/src/level.c
@@ -56,8 +56,8 @@ const char *LEVEL_MAP_3 = {
"....e........w....e....."
"...---....2..w--txxx...."
"....3........w..w......."
- "........-----w--x......."
- "....p.......ew.....s...."
+ "........-----w.........."
+ "....p.......ewj....s...."
"..xxxx....xxxxxxxxxxxx.."
"........................"
"........................"
@@ -137,6 +137,9 @@ void level_generate(game_t *game, const char *map, int width, int height) {
case 'n':
tile->type = TILE_SAND;
break;
+ case 'j':
+ tile->type = TILE_BOX;
+ break;
case 'k':
tile->type = TILE_BG_CHANDELIER;
break;
diff --git a/src/player.c b/src/player.c
@@ -352,16 +352,12 @@ void player_update(player_t *player, game_t *game) {
}
// detect door entering
if (holding) {
+ rect_t player_rect = { player->pos.x, player->pos.y, PLAYER_WIDTH, PLAYER_HEIGHT };
for (int i = 0; i < game->entities_len; i++) {
if (game->entities[i].type == ENTITY_DOOR) {
door_t *door = game->entities[i].door;
- float tolerance = 0.0;
- if (
- player->pos.x <= door->pos.x + ENEMY_WIDTH - tolerance &&
- player->pos.x + PLAYER_WIDTH >= door->pos.x + tolerance &&
- player->pos.y <= door->pos.y + ENEMY_HEIGHT - tolerance &&
- player->pos.y + PLAYER_HEIGHT >= door->pos.y + tolerance
- ) {
+ rect_t door_rect = entity_get_rect(&game->entities[i]);
+ if (rect_collide(player_rect, door_rect)) {
if (door_unlock(door, game)) {
game->door = door;
game->victory = true;
diff --git a/src/tile.c b/src/tile.c
@@ -54,6 +54,10 @@ void tile_draw(tile_t *tile, game_t *game) {
DrawTextureRec(game->assets.tiles, texture_rect(6, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);
break;
}
+ case TILE_BOX: {
+ DrawTextureRec(game->assets.tiles, texture_rect(7, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);
+ break;
+ }
case TILE_BG_CHANDELIER: {
DrawTextureRec(game->assets.background, texture_rect_v(3, 5, 4, 3, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);
break;
@@ -105,6 +109,7 @@ bool tile_ground(tile_t *tile) {
case TILE_STONE_JOINT:
case TILE_SNOW:
case TILE_SAND:
+ case TILE_BOX:
return true;
default:
return false;