A retro platform game
git clone git://soophie.de/freezo
diff --git a/assets/lose.wav b/assets/lose.wav
new file mode 100644
index 0000000..0f4ff82
Binary files /dev/null and b/assets/lose.wav differ
diff --git a/assets/song.wav b/assets/song.wav
new file mode 100644
index 0000000..d14e630
Binary files /dev/null and b/assets/song.wav differ
diff --git a/assets/tiles.png b/assets/tiles.png
index 2240f6d..a3474b3 100644
Binary files a/assets/tiles.png and b/assets/tiles.png differ
diff --git a/assets/win.wav b/assets/win.wav
new file mode 100644
index 0000000..eee9f52
Binary files /dev/null and b/assets/win.wav differ
diff --git a/include/game.h b/include/game.h
index 5db5874..91b8c68 100644
--- a/include/game.h
+++ b/include/game.h
1
@@ -12,7 +12,8 @@ typedef struct Game game_t;2
#include "door.h"4
#define GAME_SCEEN_TIMER 1505
-#define GAME_SOUND_VOLUME 0.5f6
+#define GAME_MUSIC_VOLUME 0.7f7
+#define GAME_SOUND_VOLUME 1.0f9
typedef enum {10
STATE_MENU,11
@@ -26,6 +27,8 @@ struct Assets {12
Texture2D images;13
Texture2D background;14
Sound track;15
+ Sound win;16
+ Sound lose;17
Sound locked;18
};
diff --git a/include/tile.h b/include/tile.h
index 5aeba23..cbfc5e8 100644
--- a/include/tile.h
+++ b/include/tile.h
1
@@ -14,6 +14,7 @@ typedef enum {2
TILE_STONE,3
TILE_SNOW,4
TILE_SAND,5
+ TILE_BOX,6
TILE_BG_CHANDELIER,7
TILE_BG_WINDOW_1,8
TILE_BG_WINDOW_2,
diff --git a/src/game.c b/src/game.c
index dc9dd43..845eda9 100644
--- a/src/game.c
+++ b/src/game.c
1
@@ -32,7 +32,9 @@ game_t *game_create(void) {2
.assets.font = texture_load("assets/font.png", SCALE - 1),3
.assets.images = texture_load("assets/images.png", SCALE),4
.assets.background = texture_load("assets/background.png", SCALE),5
- .assets.track = LoadSound("assets/track.wav"),6
+ .assets.track = LoadSound("assets/song.wav"),7
+ .assets.win = LoadSound("assets/win.wav"),8
+ .assets.lose = LoadSound("assets/lose.wav"),9
.assets.locked = LoadSound("assets/locked.wav"),10
.camera = (Camera2D) {11
.offset = (pos_t) { 0.0, 0.0 },12
@@ -45,7 +47,9 @@ game_t *game_create(void) {13
.is_muted = false,14
};15
level_load(game, LEVEL_1);16
- SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);17
+ SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);18
+ SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);19
+ SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);20
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);21
return game;22
}23
@@ -55,14 +59,18 @@ void game_update(game_t *game) {24
game->is_muted = !game->is_muted;25
if (game->is_muted) {26
SetSoundVolume(game->assets.track, 0.0f);27
+ SetSoundVolume(game->assets.win, 0.0f);28
+ SetSoundVolume(game->assets.lose, 0.0f);29
SetSoundVolume(game->assets.locked, 0.0f);30
}31
else {32
- SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);33
+ SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);34
+ SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);35
+ SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);36
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);37
}38
}39
- if (!IsSoundPlaying(game->assets.track)) {40
+ if (!IsSoundPlaying(game->assets.track) && !game->victory && !game->defeat) {41
PlaySound(game->assets.track);42
}43
switch (game->state) {44
@@ -78,6 +86,12 @@ void game_update(game_t *game) {45
if (game->level != NULL) {46
// defeat47
if (game->defeat) {48
+ if (game->sceen_timer == 0) {49
+ StopSound(game->assets.track);50
+ }51
+ if (game->sceen_timer == 20) {52
+ PlaySound(game->assets.lose);53
+ }54
if (game->sceen_timer == GAME_SCEEN_TIMER) {55
level_e level = game->level->type;56
level_unload(game);57
@@ -92,6 +106,12 @@ void game_update(game_t *game) {58
}59
// victory60
if (game->victory) {61
+ if (game->sceen_timer == 0) {62
+ StopSound(game->assets.track);63
+ }64
+ if (game->sceen_timer == 20) {65
+ PlaySound(game->assets.win);66
+ }67
if (game->sceen_timer == GAME_SCEEN_TIMER) {68
if (game->level->type < LEVELS) {69
level_e level = game->level->type;70
@@ -247,6 +267,8 @@ void game_free(game_t *game) {71
UnloadTexture(game->assets.images);72
UnloadTexture(game->assets.background);73
UnloadSound(game->assets.track);74
+ UnloadSound(game->assets.win);75
+ UnloadSound(game->assets.lose);76
UnloadSound(game->assets.locked);77
UnloadRenderTexture(game->overlay);78
free(game);
diff --git a/src/level.c b/src/level.c
index 3e2cc46..ed93ffd 100644
--- a/src/level.c
+++ b/src/level.c
1
@@ -56,8 +56,8 @@ const char *LEVEL_MAP_3 = {2
"....e........w....e....."3
"...---....2..w--txxx...."4
"....3........w..w......."5
- "........-----w--x......."6
- "....p.......ew.....s...."7
+ "........-----w.........."8
+ "....p.......ewj....s...."9
"..xxxx....xxxxxxxxxxxx.."10
"........................"11
"........................"12
@@ -137,6 +137,9 @@ void level_generate(game_t *game, const char *map, int width, int height) {13
case 'n':14
tile->type = TILE_SAND;15
break;16
+ case 'j':17
+ tile->type = TILE_BOX;18
+ break;19
case 'k':20
tile->type = TILE_BG_CHANDELIER;21
break;
diff --git a/src/player.c b/src/player.c
index 93af778..0a58d31 100644
--- a/src/player.c
+++ b/src/player.c
1
@@ -352,16 +352,12 @@ void player_update(player_t *player, game_t *game) {2
}3
// detect door entering4
if (holding) {5
+ rect_t player_rect = { player->pos.x, player->pos.y, PLAYER_WIDTH, PLAYER_HEIGHT };6
for (int i = 0; i < game->entities_len; i++) {7
if (game->entities[i].type == ENTITY_DOOR) {8
door_t *door = game->entities[i].door;9
- float tolerance = 0.0;10
- if (11
- player->pos.x <= door->pos.x + ENEMY_WIDTH - tolerance &&12
- player->pos.x + PLAYER_WIDTH >= door->pos.x + tolerance &&13
- player->pos.y <= door->pos.y + ENEMY_HEIGHT - tolerance &&14
- player->pos.y + PLAYER_HEIGHT >= door->pos.y + tolerance15
- ) {16
+ rect_t door_rect = entity_get_rect(&game->entities[i]);17
+ if (rect_collide(player_rect, door_rect)) {18
if (door_unlock(door, game)) {19
game->door = door;20
game->victory = true;
diff --git a/src/tile.c b/src/tile.c
index 186e0f1..ec86b51 100644
--- a/src/tile.c
+++ b/src/tile.c
1
@@ -54,6 +54,10 @@ void tile_draw(tile_t *tile, game_t *game) {2
DrawTextureRec(game->assets.tiles, texture_rect(6, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);3
break;4
}5
+ case TILE_BOX: {6
+ DrawTextureRec(game->assets.tiles, texture_rect(7, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);7
+ break;8
+ }9
case TILE_BG_CHANDELIER: {10
DrawTextureRec(game->assets.background, texture_rect_v(3, 5, 4, 3, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);11
break;12
@@ -105,6 +109,7 @@ bool tile_ground(tile_t *tile) {13
case TILE_STONE_JOINT:14
case TILE_SNOW:15
case TILE_SAND:16
+ case TILE_BOX:17
return true;18
default:19
return false;