commit 124ae0bb0a49d67bd7297dd18d9246d840cac195
parent 25594fb69607757bfbc9e92f494ccb5400536e0a
Author: amin <dev@aminmesbah.com>
Date: Sat, 13 Apr 2019 20:28:21 +0000
Constrain player (more or less) to the viewport
FossilOrigin-Name: 9aefabfb97a09a1d271d794fa83834169aa697c39337944b792847c4a6082452
Diffstat:
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -42,7 +42,7 @@ f32 randf(f32 min, f32 max)
void game_init(struct GameState *game_state, v2u framebuffer)
{
// init player
- game_state->player.pos = (v2) { 10.0f, 10.0f };
+ game_state->player.pos = (v2) { 1.0f, 1.0f };
// set up and load tiles
{
@@ -116,8 +116,6 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
f32 h_pad_size = (framebuffer.width - viewport_size.width) / 2.0f;
f32 v_pad_size = (framebuffer.height - viewport_size.height) / 2.0f;
- printf("h pad: %f\n", h_pad_size);
- printf("v pad: %f\n", v_pad_size);
viewport.min = (v2) {
h_pad_size,
@@ -125,16 +123,6 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
};
viewport.max = glmth_v2_a(viewport.min, viewport_size);
- printf("---------------------------------\n");
- printf("Screen: ");
- glmth_v2_print((v2) { (f32)framebuffer.x, (f32)framebuffer.y });
- printf("Size: ");
- glmth_v2_print(viewport_size);
- printf("Min: ");
- glmth_v2_print(viewport.min);
- printf("Max: ");
- glmth_v2_print(viewport.max);
- printf("---------------------------------\n");
}
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
@@ -142,9 +130,6 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- // 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
-
// render tiles
{
glBindVertexArray(game_state->tiles.vao);
@@ -223,20 +208,32 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
{
game_state->player.pos.x += movement_speed;
}
+ glmth_clampf(&(game_state->player.pos.x), 0, ROOM_TILE_DIM_X);
+ glmth_clampf(&(game_state->player.pos.y), 0, ROOM_TILE_DIM_Y);
}
// 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 });
// these dimensions are relative to a square 'meter', one tile
v2 player_dim = (v2) { 0.375f, 0.583f };
@@ -246,6 +243,7 @@ void game_update_and_render(struct GameState *game_state, f32 dt, v2u framebuffe
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,