a-game

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

commit ac38a202b97cbefca0ce820c3373f3b7f01ec9f4
parent 7f53d7e1ca61d73beffebe907186019f27875538
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Mon,  4 Mar 2019 17:48:51 -0800

Align the tile map to the upper left corner

Diffstat:
Msrc/game.c | 20++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -245,15 +245,24 @@ void game_update_and_render(struct GameState *game_state, float dt, v2u framebuf { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, }, }; - uint32_t start = 25; - float size = fabsf(100 * sinf(dt)); + float size; + if (screen_width < screen_height) + { + size = ((float)screen_width) / 16.0f; + } + else + { + size = ((float)screen_height) / 9.0f; + } + + float start = size / 2.0f; for (size_t y = 0; y < 9; y++) { for (size_t x = 0; x < 16; x++) { uint32_t tile_id = tile_map[y][x]; m4 model = glmth_m4_init_id(); - model = glmth_translate(model, glmth_v3_init(start + (size * x), start + (size * y), 0.0f)); + model = glmth_translate(model, glmth_v3_init(start + ((size + 1.0f) * x), start + ((size + 1.0f) * y), 0.0f)); model = glmth_scale(model, glmth_v3_init(size, size, 1.0f)); shader_setm4(&game_state->star_shader, "model", &model); @@ -264,12 +273,11 @@ void game_update_and_render(struct GameState *game_state, float dt, v2u framebuf } else { - color = glmth_v3_init(1.0f, 0.0f, 0.0f); + //color = glmth_v3_init(1.0f, 0.0f, 0.0f); } shader_setv3(&game_state->star_shader, "color", &color); - m4 projection = glmth_m4_init_id(); - projection = glmth_projection_ortho(0.0f, screen_width, screen_height, 0.0f, -1.0f, 1.0f); + m4 projection = glmth_projection_ortho(0.0f, screen_width, screen_height, 0.0f, -1.0f, 0.0f); shader_setm4(&game_state->star_shader, "projection", &projection); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);