A retro platform game
git clone git://soophie.de/freezo
Binary file
Binary file
Binary file
1
#pragma once3
typedef struct Boss boss_t;5
#include "game.h"6
#include "util.h"8
typedef enum {9
BOSS_TEST,10
} boss_e;12
struct Boss {13
pos_t pos;14
boss_e type;15
bool on_ground;16
float velocity;17
float gravity;18
int dir;19
bool stunned;20
bool frozen;21
int frozen_timer;22
float fall_height;23
fz_timer_t *timer_walking;24
fz_timer_t *timer_sneaking;25
};27
boss_t *boss_create(pos_t pos, boss_e type);28
void boss_update(boss_t *boss, game_t *game);29
void boss_draw(boss_t *boss, game_t *game);30
void boss_kill(boss_t *boss, game_t *game);31
void boss_free(boss_t *boss);
6
#include "gate.h"7
#include "game.h"8
#include "door.h"9
#include "boss.h"11
typedef enum {12
ENTITY_ENEMY,13
ENTITY_GATE,14
ENTITY_DOOR,15
ENTITY_BOSS,16
} entity_e;18
struct Entity {
21
enemy_t *enemy;22
gate_t *gate;23
door_t *door;24
boss_t *boss;25
};26
bool is_bad;27
};
25
Texture2D images;26
Texture2D background;27
Sound track;28
Sound locked;29
};31
struct Game {
47
int xp;48
int sceen_timer;49
door_t *door;50
RenderTexture2D overlay;51
};53
game_t *game_create(void);
15
TILE_SNOW,16
TILE_SAND,17
TILE_BG_CHANDELIER,18
TILE_BG_WINDOW,18
TILE_BG_WINDOW_1,19
TILE_BG_WINDOW_2,20
TILE_BG_BANNER,21
TILE_BG_BRICK_1,22
TILE_BG_BRICK_2,
1
#include <stdlib.h>2
#include <math.h>4
#include "../include/boss.h"5
#include "../include/const.h"6
#include "../include/entity.h"7
#include "../include/effect.h"9
boss_t *boss_create(pos_t pos, boss_e type) {10
boss_t *boss = malloc(sizeof(boss_t));11
*boss = (boss_t) {12
.pos = pos,13
.type = type,14
.on_ground = false,15
.velocity = 0.0,16
.gravity = 0.0,17
.dir = 1,18
.stunned = false,19
.frozen = false,20
.frozen_timer = 0,21
.fall_height = 0.0,22
.timer_walking = fz_timer_create(9, 8),23
.timer_sneaking = fz_timer_create(9, 16),24
};25
return boss;26
}28
void boss_update(boss_t *boss, game_t *game) {29
(void) boss;30
(void) game;31
}33
void boss_draw(boss_t *boss, game_t *game) {34
pos_t pos = pos_snap(boss->pos);35
DrawTextureRec(game->assets.entities, texture_rect_v(10, 6, 2, 1, ENEMY_WIDTH, ENEMY_HEIGHT), pos, WHITE);36
}38
void boss_kill(boss_t *boss, game_t *game) {39
for (int i = 0; i < game->entities_len; i++) {40
if (game->entities[i].type == ENTITY_BOSS && game->entities[i].boss == boss) {41
if (i + 1 < game->entities_len) {42
for (int j = i; j < game->entities_len - 1; j++) {43
game->entities[j] = game->entities[j + 1];44
}45
}46
game->entities_len--;47
game->entities = realloc(game->entities, sizeof(entity_t) * game->entities_len);48
game->xp += 10;49
break;50
}51
}52
}54
void boss_free(boss_t *boss) {55
fz_timer_free(boss->timer_walking);56
fz_timer_free(boss->timer_sneaking);57
free(boss);58
}
171
int frame_walking = fz_timer_get(enemy->timer_walking);172
int frame_sneaking = fz_timer_get(enemy->timer_sneaking);173
if (enemy->dir > 0) {174
DrawTextureRec(game->assets.entities, texture_rect(enemy->stunned ? frame_sneaking : frame_walking, 8, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);174
DrawTextureRec(game->assets.entities, texture_rect(enemy->stunned ? frame_sneaking : frame_walking, 10, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);175
}176
else {177
DrawTextureRec(game->assets.entities, texture_rect(enemy->stunned ? frame_sneaking : frame_walking, 9, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);177
DrawTextureRec(game->assets.entities, texture_rect(enemy->stunned ? frame_sneaking : frame_walking, 11, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);178
}179
if (enemy->frozen) {180
if (enemy->frozen_timer <= 1200) {
18
case ENTITY_DOOR:19
entity->is_bad = false;20
break;21
case ENTITY_BOSS:22
entity->is_bad = true;23
break;24
}25
return entity;26
}
36
case ENTITY_DOOR:37
door_update(entity->door, game);38
break;39
case ENTITY_BOSS:40
boss_update(entity->boss, game);41
break;42
}43
}
53
case ENTITY_DOOR:54
door_draw(entity->door, game);55
break;56
case ENTITY_BOSS:57
boss_draw(entity->boss, game);58
break;59
}60
}
70
case ENTITY_DOOR:71
door_free(entity->door);72
break;73
case ENTITY_BOSS:74
boss_free(entity->boss);75
break;76
}77
}
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"),36
.assets.locked = LoadSound("assets/locked.wav"),37
.camera = (Camera2D) {38
.offset = (pos_t) { 0.0, 0.0 },39
.zoom = 1,
41
.xp = 0,42
.sceen_timer = 0,43
.door = NULL,44
.overlay = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT),45
};46
level_load(game, LEVEL_1);47
return game;
140
void game_draw(game_t *game) {141
// render overlay140
RenderTexture2D overlay_texture = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT);141
BeginTextureMode(overlay_texture);142
BeginTextureMode(game->overlay);143
ClearBackground(BLACK);144
DrawRectangle(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, BLACK);145
BeginBlendMode(BLEND_SUBTRACT_COLORS);
169
effect_draw(game->effects[i], game);170
}171
// draw overlay171
DrawTexture(overlay_texture.texture, 0, 0, WHITE);172
DrawTexture(game->overlay.texture, 0, 0, WHITE);173
EndMode2D();174
// draw interface175
int i = 0;
202
menu_draw(game->menu, game);203
}204
EndDrawing();204
UnloadRenderTexture(overlay_texture);205
}207
void game_free(game_t *game) {
215
UnloadTexture(game->assets.images);216
UnloadTexture(game->assets.background);217
UnloadSound(game->assets.track);218
UnloadSound(game->assets.locked);219
UnloadRenderTexture(game->overlay);220
free(game);221
}
9
const char *LEVEL_MAP_1 = {10
"........................"11
"........................"12
"........k.......o......."12
"........k.......O......."13
"..1....................."14
"........................"15
"........................"
32
"........................"33
"................u......."34
"...............xxxx....."35
"..o......s.e............"35
".........s.e............"36
".......xxxxxxtxxx--xx..."37
".............w.........."37
"...o.........w.........."38
".........2...w...--.1..."39
".............w.........."40
".........----x...--....."
140
case 'k':141
tile->type = TILE_BG_CHANDELIER;142
break;143
case 'O':144
tile->type = TILE_BG_WINDOW_1;145
break;146
case 'o':144
tile->type = TILE_BG_WINDOW;147
tile->type = TILE_BG_WINDOW_2;148
break;149
case 'b':150
tile->type = TILE_BG_BANNER;
212
game->entities_len++;213
break;214
}215
case 'z': {216
game->entities = realloc(game->entities, sizeof(enemy_t) * (game->entities_len + 1));217
boss_t *boss = boss_create((pos_t) {218
.x = x * TILE_WIDTH + (TILE_WIDTH - ENEMY_WIDTH) / 2.0,219
.y = y * TILE_HEIGHT,220
}, BOSS_TEST);221
game->entities[game->entities_len] = (entity_t) {222
.type = ENTITY_BOSS,223
.boss = boss,224
.is_bad = true,225
};226
game->entities_len++;227
break;228
}229
default:230
break;231
}
263
case ENTITY_DOOR:264
entity_rect = rect_from_pos((pos_t) { entity->gate->pos.x, entity->gate->pos.y - TILE_HEIGHT }, ENEMY_WIDTH, ENEMY_HEIGHT);265
break;266
case ENTITY_BOSS:267
entity_rect = rect_from_pos((pos_t) { entity->gate->pos.x, entity->gate->pos.y - TILE_HEIGHT }, 2 * ENEMY_WIDTH, ENEMY_HEIGHT);268
break;269
}270
if (rect_collide(shooting_rect, entity_rect)) {271
float entity_x = entity_rect.x + entity_rect.width / 2.0;
362
game->door = door;363
game->victory = true;364
}365
else {366
PlaySound(game->assets.locked);367
}368
}369
}370
}
426
if (player->damage_timer / 4 % 2 == 0) {427
if (player->sneaking) {428
if (player->dir > 0) {423
DrawTextureRec(game->assets.entities, texture_rect(frame, 6, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);429
DrawTextureRec(game->assets.entities, texture_rect(frame, 14, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);430
}431
else {426
DrawTextureRec(game->assets.entities, texture_rect(frame, 7, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);432
DrawTextureRec(game->assets.entities, texture_rect(frame, 15, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);433
}434
}435
else {436
if (player->dir > 0) {431
DrawTextureRec(game->assets.entities, texture_rect(frame, 4, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);437
DrawTextureRec(game->assets.entities, texture_rect(frame, 12, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);438
}439
else {434
DrawTextureRec(game->assets.entities, texture_rect(frame, 5, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);440
DrawTextureRec(game->assets.entities, texture_rect(frame, 13, PLAYER_WIDTH, PLAYER_HEIGHT), pos, WHITE);441
}442
}443
if (player->shooting) {
58
DrawTextureRec(game->assets.background, texture_rect_v(3, 5, 4, 3, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);59
break;60
}61
case TILE_BG_WINDOW: {61
case TILE_BG_WINDOW_1: {62
DrawTextureRec(game->assets.background, texture_rect_v(8, 0, 4, 6, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);63
break;64
}65
case TILE_BG_WINDOW_2: {66
DrawTextureRec(game->assets.background, texture_rect_v(8, 7, 3, 4, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);67
break;68
}69
case TILE_BG_BANNER: {70
DrawTextureRec(game->assets.background, texture_rect_v(3, 0, 3, 4, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);71
break;
10
- [x] Add wall collision11
- [ ] Add move velocity (for damage and maybe icy surfaces)12
- [x] Stop enemy movement on walls13
- [ ] Stop freeze laser on walls13
- [x] Stop freeze laser on walls14
- [ ] Add hitboxes (make them visible in debug mode)15
- [ ] Add countdown16
- [ ] Add new enemies