commit 3747da9658018bcc416b0b1cf8afacd92c20c628
parent bf3597438f123c7a4825e80f24015f326c9012d7
Author: Amin Mesbah <dev@aminmesbah.com>
Date: Tue, 19 Mar 2019 21:01:15 -0700
Get tilemap to center properly
Diffstat:
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);