a-game

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

commit bb93277e46ee55dc501cb4c74eb2b4a654ae1147
parent ab962434122958e569ce215b96c3d481714c71f3
Author: amin <dev@aminmesbah.com>
Date:   Wed, 20 Mar 2019 04:01:14 +0000

Get tilemap to center properly

FossilOrigin-Name: 3ff8992c2d2fd6c044cc6fc67a07cb07c4862510e5e541943d78b8181047f1fd
Diffstat:
Msrc/game.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -205,24 +205,24 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, }; - f32 size; - if (screen_width < screen_height) - { - size = ((f32)screen_width) / 16.0f; - } - else + f32 size = ((f32)screen_width) / 16.0f; + if (size * 9.0f > screen_height) { size = ((f32)screen_height) / 9.0f; } - f32 start = size / 2.0f; + f32 tilemap_width = size * 16.0f; + f32 tilemap_height = size * 9.0f; + + f32 startx = size / 2.0f + ((screen_width - tilemap_width) / 2.0f); + f32 starty = size / 2.0f + ((screen_height - tilemap_height) / 2.0f); for (size_t y = 0; y < 9; y++) { for (size_t x = 0; x < 16; x++) { u32 tile_id = tile_map[y][x]; m4 model = glmth_m4_init_id(); - model = glmth_translate(model, (v3) {start + (size * x), start + (size * y), 0.0f}); + model = glmth_translate(model, (v3) {startx + (size * x), starty + (size * y), 0.0f}); model = glmth_scale(model, (v3) {size, size, 1.0f}); shader_setm4(&game_state->star_shader, "model", &model);