A retro platform game
git clone git://soophie.de/freezo
Binary file
Binary file
Binary file
Binary file
12
#include "door.h"14
#define GAME_SCEEN_TIMER 15015
#define GAME_SOUND_VOLUME 0.5f15
#define GAME_MUSIC_VOLUME 0.7f16
#define GAME_SOUND_VOLUME 1.0f18
typedef enum {19
STATE_MENU,
27
Texture2D images;28
Texture2D background;29
Sound track;30
Sound win;31
Sound lose;32
Sound locked;33
};
14
TILE_STONE,15
TILE_SNOW,16
TILE_SAND,17
TILE_BOX,18
TILE_BG_CHANDELIER,19
TILE_BG_WINDOW_1,20
TILE_BG_WINDOW_2,
32
.assets.font = texture_load("assets/font.png", SCALE - 1),33
.assets.images = texture_load("assets/images.png", SCALE),34
.assets.background = texture_load("assets/background.png", SCALE),35
.assets.track = LoadSound("assets/track.wav"),35
.assets.track = LoadSound("assets/song.wav"),36
.assets.win = LoadSound("assets/win.wav"),37
.assets.lose = LoadSound("assets/lose.wav"),38
.assets.locked = LoadSound("assets/locked.wav"),39
.camera = (Camera2D) {40
.offset = (pos_t) { 0.0, 0.0 },
47
.is_muted = false,48
};49
level_load(game, LEVEL_1);48
SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);50
SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);51
SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);52
SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);53
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);54
return game;55
}
59
game->is_muted = !game->is_muted;60
if (game->is_muted) {61
SetSoundVolume(game->assets.track, 0.0f);62
SetSoundVolume(game->assets.win, 0.0f);63
SetSoundVolume(game->assets.lose, 0.0f);64
SetSoundVolume(game->assets.locked, 0.0f);65
}66
else {61
SetSoundVolume(game->assets.track, GAME_SOUND_VOLUME);67
SetSoundVolume(game->assets.track, GAME_MUSIC_VOLUME);68
SetSoundVolume(game->assets.win, GAME_SOUND_VOLUME);69
SetSoundVolume(game->assets.lose, GAME_SOUND_VOLUME);70
SetSoundVolume(game->assets.locked, GAME_SOUND_VOLUME);71
}72
}65
if (!IsSoundPlaying(game->assets.track)) {73
if (!IsSoundPlaying(game->assets.track) && !game->victory && !game->defeat) {74
PlaySound(game->assets.track);75
}76
switch (game->state) {
86
if (game->level != NULL) {87
// defeat88
if (game->defeat) {89
if (game->sceen_timer == 0) {90
StopSound(game->assets.track);91
}92
if (game->sceen_timer == 20) {93
PlaySound(game->assets.lose);94
}95
if (game->sceen_timer == GAME_SCEEN_TIMER) {96
level_e level = game->level->type;97
level_unload(game);
106
}107
// victory108
if (game->victory) {109
if (game->sceen_timer == 0) {110
StopSound(game->assets.track);111
}112
if (game->sceen_timer == 20) {113
PlaySound(game->assets.win);114
}115
if (game->sceen_timer == GAME_SCEEN_TIMER) {116
if (game->level->type < LEVELS) {117
level_e level = game->level->type;
267
UnloadTexture(game->assets.images);268
UnloadTexture(game->assets.background);269
UnloadSound(game->assets.track);270
UnloadSound(game->assets.win);271
UnloadSound(game->assets.lose);272
UnloadSound(game->assets.locked);273
UnloadRenderTexture(game->overlay);274
free(game);
56
"....e........w....e....."57
"...---....2..w--txxx...."58
"....3........w..w......."59
"........-----w--x......."60
"....p.......ew.....s...."59
"........-----w.........."60
"....p.......ewj....s...."61
"..xxxx....xxxxxxxxxxxx.."62
"........................"63
"........................"
137
case 'n':138
tile->type = TILE_SAND;139
break;140
case 'j':141
tile->type = TILE_BOX;142
break;143
case 'k':144
tile->type = TILE_BG_CHANDELIER;145
break;
352
}353
// detect door entering354
if (holding) {355
rect_t player_rect = { player->pos.x, player->pos.y, PLAYER_WIDTH, PLAYER_HEIGHT };356
for (int i = 0; i < game->entities_len; i++) {357
if (game->entities[i].type == ENTITY_DOOR) {358
door_t *door = game->entities[i].door;358
float tolerance = 0.0;359
if (360
player->pos.x <= door->pos.x + ENEMY_WIDTH - tolerance &&361
player->pos.x + PLAYER_WIDTH >= door->pos.x + tolerance &&362
player->pos.y <= door->pos.y + ENEMY_HEIGHT - tolerance &&363
player->pos.y + PLAYER_HEIGHT >= door->pos.y + tolerance364
) {359
rect_t door_rect = entity_get_rect(&game->entities[i]);360
if (rect_collide(player_rect, door_rect)) {361
if (door_unlock(door, game)) {362
game->door = door;363
game->victory = true;
54
DrawTextureRec(game->assets.tiles, texture_rect(6, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);55
break;56
}57
case TILE_BOX: {58
DrawTextureRec(game->assets.tiles, texture_rect(7, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);59
break;60
}61
case TILE_BG_CHANDELIER: {62
DrawTextureRec(game->assets.background, texture_rect_v(3, 5, 4, 3, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);63
break;
109
case TILE_STONE_JOINT:110
case TILE_SNOW:111
case TILE_SAND:112
case TILE_BOX:113
return true;114
default:115
return false;