A retro platform game
git clone git://soophie.de/freezo
14
TILE_STONE,15
TILE_SNOW,16
TILE_SAND,17
TILE_BG_CHANDELIER,18
TILE_BG_WINDOW,19
TILE_BG_BANNER,20
TILE_BG_BRICK_1,21
TILE_BG_BRICK_2,22
TILE_BG_BRICK_3,23
} tile_e;25
struct Tile {
33
Texture texture_load(char *filename, int scale);34
Rectangle texture_rect(int x, int y, int width, int height);35
Rectangle texture_rect_v(int x, int y, int width, int height, int size_x, int size_y);37
typedef enum {38
TEXT_ALIGNMENT_LEFT,
147
void game_draw(game_t *game) {148
BeginDrawing();149
ClearBackground(BLACK);150
DrawTextureRec(game->assets.background, (Rectangle) { 0, 0, WINDOW_WIDTH * TILE_WIDTH, WINDOW_HEIGHT * TILE_HEIGHT }, (pos_t) { 0, 0 }, WHITE);150
if (game->level != LEVEL_NULL) {151
BeginMode2D(game->camera);152
for (int i = 0; i < game->tiles_len; i++) {
9
const char *LEVEL_MAP_1 = {10
"........................"11
"........................"12
"........k.......o......."13
"..1....................."14
"........................"15
"........................"14
"........................"15
"........................"16
"......e................."16
"......e......3.........."17
"....xxxx................"18
"........................"18
".....b.................."19
"...........--...xxx....."20
"................e......."21
"...............--xxxxx.."21
"...........2...--xxxxx.."22
"....p..................."23
"..xxxxxxxxx---xxxxxxxx.."24
"........................"
28
const char *LEVEL_MAP_2 = {29
"........................"30
"........................"31
"......3....b............"32
"........................"33
"........................"33
"........................"34
"..............xxxx......"35
"........s.e............."36
"....xxxxxxxxxtxxx--x...."34
"...............xxxx....."35
"..o......s.e............"36
".......xxxxxxtxxx--xx..."37
".............w.........."38
".............w...--....."38
".........2...w...--.1..."39
".............w.........."40
".........----x...--....."41
"....p...............e..."42
"..ggggg....xxxxxxxxxxx.."42
"..xxxxx....xxxxxxxxxxx.."43
"........................"44
"........................"45
};47
const char *LEVEL_MAP_3 = {48
"........................................"49
"........................................"50
"........................................"51
"........................................"52
"........................................"53
"........................................"54
"........................................"55
"........................................"56
"........................................"57
"........................................"58
"......e..................e...s.........."59
"....ggggg...--...xxxxxxxxxxxxxxxxx......"60
"........................................"61
"............--.........................."62
"....................e..................."63
"............--...xxxxxxxxt-............."64
".........................w.............."65
"............--...........w-............."66
"..............e.......s..w..e..........."67
"..........xxxxxxxxxxxxxxxxxxxxxxxt--x..."68
".................................w......"69
".................................w--...."70
".................................w......"71
".................................w--...."72
"........................e........w......"73
"....................xxtxxxtxx----x--...."74
"....p.......e.........w...w............."75
"..ggggg..-----...xxxxxxxxxxxxxxxxxxxxx.."76
"........................................"77
"........................................"48
"........................"49
"........................"50
"...b.....1....e...k....."51
"............-txx-......."52
".............w.........."53
"............-w..-......."54
"........s....w.........."55
"..x---xxxxxxxtxxx--xx..."56
"....e........w....e....."57
"...---....2..w--txxx...."58
"....3........w..w......."59
"........-----w--x......."60
"....p.......ew.....s...."61
"..xxxx....xxxxxxxxxxxx.."62
"........................"63
"........................"64
};66
// const char *LEVEL_MAP_3 = {67
// "........................................"68
// "........................................"69
// "........................................"70
// "........................................"71
// "........................................"72
// "........................................"73
// "........................................"74
// "........................................"75
// "........................................"76
// "........................................"77
// "......e..................e...s.........."78
// "....xxxxx...--...xxxxxxxxxxxxxxxxx......"79
// "........................................"80
// "............--.........................."81
// "....................e..................."82
// "............--...xxxxxxxxt-............."83
// ".........................w.............."84
// "............--...........w-............."85
// "..............e.......s..w..e..........."86
// "..........xxxxxxxxxxxxxxxxxxxxxxxt--x..."87
// ".................................w......"88
// ".................................w--...."89
// ".................................w......"90
// ".................................w--...."91
// "........................e........w......"92
// "....................xxtxxxtxx----x--...."93
// "....p.......e.........w...w............."94
// "..xxxxx..-----...xxxxxxxxxxxxxxxxxxxxx.."95
// "........................................"96
// "........................................"97
// };99
void level_generate(game_t *game, const char *map, int width, int height) {100
game->player = NULL;101
game->tiles = malloc(sizeof(tile_t) * width * height);
137
case 'n':138
tile->type = TILE_SAND;139
break;140
case 'k':141
tile->type = TILE_BG_CHANDELIER;142
break;143
case 'o':144
tile->type = TILE_BG_WINDOW;145
break;146
case 'b':147
tile->type = TILE_BG_BANNER;148
break;149
case '1':150
tile->type = TILE_BG_BRICK_1;151
break;152
case '2':153
tile->type = TILE_BG_BRICK_2;154
break;155
case '3':156
tile->type = TILE_BG_BRICK_3;157
break;158
default:159
break;160
}
219
break;220
}221
case LEVEL_3: {185
level_generate(game, LEVEL_MAP_3, 40, 30);186
level->width = 40;187
level->height = 30;222
level_generate(game, LEVEL_MAP_3, 24, 16);223
level->width = 24;224
level->height = 16;225
// level_generate(game, LEVEL_MAP_3, 40, 30);226
// level->width = 40;227
// level->height = 30;228
break;229
}230
}
54
DrawTextureRec(game->assets.tiles, texture_rect(6, 0, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);55
break;56
}57
case TILE_BG_CHANDELIER: {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: {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_BANNER: {66
DrawTextureRec(game->assets.background, texture_rect_v(3, 0, 3, 4, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);67
break;68
}69
case TILE_BG_BRICK_1: {70
DrawTextureRec(game->assets.background, texture_rect_v(0, 0, 2, 3, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);71
break;72
}73
case TILE_BG_BRICK_2: {74
DrawTextureRec(game->assets.background, texture_rect_v(0, 4, 2, 1, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);75
break;76
}77
case TILE_BG_BRICK_3: {78
DrawTextureRec(game->assets.background, texture_rect_v(0, 6, 2, 2, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);79
break;80
}81
}82
}
66
return (Rectangle) { x * width, y * height, width, height };67
}69
Rectangle texture_rect_v(int x, int y, int width, int height, int size_x, int size_y) {70
return (Rectangle) { x * size_x, y * size_y, width * size_x, height * size_y };71
}74
void text_draw(pos_t pos, char *text, text_alignment_e alignment, game_t *game) {75
pos_t text_pos = pos;