commit 27964f479ebb63f719496979e055778055bfa376
parent 9442e6627006ee7cf338792a5e430836e55e4647
Author: amin <dev@aminmesbah.com>
Date: Wed, 3 Apr 2019 06:31:33 +0000
Scale player dimensions based on meter size
FossilOrigin-Name: a98dac02836eae3e4d13dd0b7a36e1b9bac8d3463e35a5cc27e1f9c9e8779878
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/game.c b/src/game.c
@@ -113,6 +113,7 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
// In Knytt, the player is a 9 by 14 pixels and a tile is 24 by 24 pixels
// TODO: Use world coordinates for everything other than rendering
+ f32 meter_size = 0.0f;
// render tiles
{
glBindVertexArray(game_state->tiles.vao);
@@ -138,6 +139,7 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
{
tile_size = ((f32)screen.height) / (f32)ROOM_TILE_DIM_Y;
}
+ meter_size = tile_size;
v2 tilemap = (v2) {
tile_size * (f32)ROOM_TILE_DIM_X,
@@ -209,7 +211,19 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
glBindVertexArray(game_state->tiles.vao);
m4 model = glmth_m4_init_id();
model = glmth_translate(model, (v3) { player.pos.x, player.pos.y, 0.0f });
- model = glmth_scale(model, (v3) { 9.0f, 14.0f, 1.0f });
+ // 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 * meter_size,
+ player_dim.y * meter_size,
+ };
+
+ model = glmth_scale(model, (v3) {
+ player_render_dim.x,
+ player_render_dim.y,
+ 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);