a-game

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

commit dc5a067fa4d7ce0e02ce82fc83615771ebb0b696
parent 124ae0bb0a49d67bd7297dd18d9246d840cac195
Author: amin <dev@aminmesbah.com>
Date:   Sun, 14 Apr 2019 01:11:37 +0000

Clean up player rendering code

FossilOrigin-Name: 435a3766fb27336075c34f94ca458df93edc4b97aa8dbbe30e008326b27e26eb
Diffstat:
Msrc/game.c | 51++++++++++++++-------------------------------------
Msrc/game.h | 1-
2 files changed, 14 insertions(+), 38 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -97,21 +97,21 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe { rect viewport; - f32 pixels_per_meter = 0.0f; + f32 ppm = 0.0f; { f32 screen_aspect_ratio = (f32)framebuffer.width / (f32)framebuffer.height; if (screen_aspect_ratio < ROOM_ASPECT_RATIO) { - pixels_per_meter = (f32)framebuffer.width / (f32)ROOM_TILE_DIM_X; + ppm = (f32)framebuffer.width / (f32)ROOM_TILE_DIM_X; } else { - pixels_per_meter = (f32)framebuffer.height / (f32)ROOM_TILE_DIM_Y; + ppm = (f32)framebuffer.height / (f32)ROOM_TILE_DIM_Y; } - v2 viewport_size = (v2) { - pixels_per_meter * (f32)ROOM_TILE_DIM_X, - pixels_per_meter * (f32)ROOM_TILE_DIM_Y, + v2 viewport_size = { + ppm * (f32)ROOM_TILE_DIM_X, + ppm * (f32)ROOM_TILE_DIM_Y, }; f32 h_pad_size = (framebuffer.width - viewport_size.width) / 2.0f; @@ -150,7 +150,7 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe { 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 = pixels_per_meter; + f32 tile_size = ppm; for (size_t y = 0; y < ROOM_TILE_DIM_Y; y++) { @@ -214,43 +214,20 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe // render player { - // In Knytt, the player is 9 by 14 texels and a tile is 24 by 24 texels - // TODO: Use world coordinates for everything other than rendering - shader_use(&game_state->player.shader); struct Entity player = game_state->player; glBindVertexArray(game_state->tiles.vao); - m4 model = glmth_m4_init_id(); - //player.pos = (v2) { 12.5f, 5.0f }; - printf("world pos: "); - glmth_v2_print(player.pos); - v2 player_render_pos = (v2) { - player.pos.x * pixels_per_meter, - player.pos.y * pixels_per_meter, - }; - player_render_pos = glmth_v2_a(player_render_pos, viewport.min); - printf("screen pos: "); - glmth_v2_print(player_render_pos); - - //model = glmth_translate(model, (v3) { viewport.min.x + (pixels_per_meter * player.pos.x), viewport.min.y + (pixels_per_meter * player.pos.y), 0.0f }); - model = glmth_translate(model, (v3) { player_render_pos.x, player_render_pos.y, 0.0f }); + // In Knytt, the player is 9 by 14 texels and a tile is 24 by 24 texels // these dimensions are relative to a square 'meter', one tile - v2 player_dim = (v2) { 0.375f, 0.583f }; - - v2 player_render_dim = (v2) { - player_dim.x * pixels_per_meter, - player_dim.y * pixels_per_meter, - }; - - //model = glmth_translate(model, (v3) { player_render_dim.x / 2.0f, player_render_dim.y / 2.0f, 0.0f }); - model = glmth_scale(model, (v3) { - player_render_dim.x, - player_render_dim.y, - 1.0f - }); + v2 player_dim = { 0.375f, 0.583f }; + m4 model = glmth_m4_init_id(); + model = glmth_translate(model, (v3) { viewport.min.x, viewport.min.y, 0.0f }); + model = glmth_translate(model, (v3) { player.pos.x * ppm, player.pos.y * ppm, 0.0f }); + model = glmth_scale(model, (v3) { player_dim.x * ppm, player_dim.y * ppm, 1.0f }); shader_setm4(&game_state->tiles.shader, "model", &model); + v3 color = (v3) { 1.0f, 0.0f, 1.0f }; shader_setv3(&game_state->tiles.shader, "color", &color); diff --git a/src/game.h b/src/game.h @@ -50,7 +50,6 @@ struct GameState struct Tiles tiles; struct GameInput input; struct Entity player; - rect viewport; }; #ifdef PLATFORM_HOTLOAD_GAME_CODE