a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit 726a65405e45e908d10369db84a124d4664ca727
parent ede21dd1ee7d7d3980d8504e938db49dcfdec3d1
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Sun, 31 Mar 2019 18:40:38 -0700

Use the same room dimensions as Knytt

Also reproduce the layout of one of the lovely rooms in Knytt.

Diffstat:
Msrc/game.c | 42++++++++++++++++++++++--------------------
Msrc/game.h | 3+++
2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -114,40 +114,42 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe { glBindVertexArray(game_state->tiles.vao); shader_use(&game_state->tiles.shader); - u32 tile_map[9][16] = { - { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, - { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, }, - { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, - - { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, }, - { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, - { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, }, - - { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, - { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, }, - { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, + + // the little hanging fly village from knytt + u32 tiles[ROOM_TILE_DIM_Y][ROOM_TILE_DIM_X] = { + { 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 }, + + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, + { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, }; - f32 tile_size = ((f32)screen.width) / 16.0f; - if (tile_size * 9.0f > screen.height) + f32 tile_size = ((f32)screen.width) / (f32)ROOM_TILE_DIM_X; + if (tile_size * (f32)ROOM_TILE_DIM_Y > screen.height) { - tile_size = ((f32)screen.height) / 9.0f; + tile_size = ((f32)screen.height) / (f32)ROOM_TILE_DIM_Y; } v2 tilemap = (v2) { - tile_size * 16.0f, - tile_size * 9.0f, + tile_size * (f32)ROOM_TILE_DIM_X, + tile_size * (f32)ROOM_TILE_DIM_Y, }; v2 start = (v2) { tile_size / 2.0f + ((screen.width - tilemap.width) / 2.0f), tile_size / 2.0f + ((screen.height - tilemap.height) / 2.0f), }; - for (size_t y = 0; y < 9; y++) + for (size_t y = 0; y < ROOM_TILE_DIM_Y; y++) { - for (size_t x = 0; x < 16; x++) + for (size_t x = 0; x < ROOM_TILE_DIM_X; x++) { - u32 tile_id = tile_map[y][x]; + u32 tile_id = tiles[y][x]; m4 model = glmth_m4_init_id(); model = glmth_translate(model, (v3) {start.x + (tile_size * x), start.y + (tile_size * y), 0.0f}); model = glmth_scale(model, (v3) {tile_size, tile_size, 1.0f}); diff --git a/src/game.h b/src/game.h @@ -11,6 +11,9 @@ #include "glmth.h" #include "shader.h" +#define ROOM_TILE_DIM_X 25 +#define ROOM_TILE_DIM_Y 10 + struct Tiles { GLuint vao;