a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit d86c00fef61101315fa5484c7314584a5888e55e
parent 17b68bf6d0c99abb98db0264c28d50b9bfbdb40c
Author: amin <dev@aminmesbah.com>
Date:   Mon,  1 Apr 2019 01:40:37 +0000

Use the same room dimensions as Knytt

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

FossilOrigin-Name: 5b93267a10e825c2cfc2dcddc0b3481e89d2041365205adf3e3aeb9681b88f88
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;