commit 6d5d3a11488221a52886c567f4e1ce9137966ef9
parent 0a2cf38e9bd76b4ce598ddf0c46cccc9bb1807aa
Author: amin <dev@aminmesbah.com>
Date: Fri, 19 Apr 2019 23:17:57 +0000
Highlight current player tile
FossilOrigin-Name: 25790f246567db00132b0a26b0bb54039c5c01647eb7bbbfd7f33db281d28134
Diffstat:
M | src/game.c | | | 65 | +++++++++++++++++++++++++++++++++++++++-------------------------- |
1 file changed, 39 insertions(+), 26 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -121,6 +121,32 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
// Screen origin is in the upper left
m4 projection = glmth_projection_ortho(0.0f, framebuffer.width, framebuffer.height, 0.0f, -1.0f, 0.0f);
+ // update player
+ {
+ f32 max_meters_per_second = 5.0f;
+ f32 movement_speed = max_meters_per_second * game_input->dt;
+
+ if (game_input->key_up)
+ {
+ game_state->player.pos.y += movement_speed;
+ }
+ else if (game_input->key_down)
+ {
+ game_state->player.pos.y -= movement_speed;
+ }
+
+ if (game_input->key_left)
+ {
+ game_state->player.pos.x -= movement_speed;
+ }
+ else if (game_input->key_right)
+ {
+ game_state->player.pos.x += movement_speed;
+ }
+ glmth_clamp(&(game_state->player.pos.x), 0, ROOM_TILE_DIM_X);
+ glmth_clamp(&(game_state->player.pos.y), 0, ROOM_TILE_DIM_Y);
+ }
+
// render tiles
{
glBindVertexArray(game_state->tiles.vao);
@@ -170,6 +196,19 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
{
color = (v3) {0.3f, 0.3f, 0.3f};
}
+
+ v2 player_pos = game_state->player.pos;
+ bool player_is_in_tile = (
+ player_pos.x >= tile_pos.x
+ && player_pos.x <= tile_pos.x + tile_size
+ && player_pos.y >= tile_pos.y
+ && player_pos.y <= tile_pos.y + tile_size
+ );
+ if (player_is_in_tile)
+ {
+ color = (v3) {0.4f, 0.8f, 0.4f};
+ }
+
shader_setv3(&game_state->tiles.shader, "color", &color);
shader_setm4(&game_state->tiles.shader, "model", &model);
shader_setm4(&game_state->tiles.shader, "view", &view);
@@ -181,32 +220,6 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
glBindVertexArray(0);
}
- // update player
- {
- f32 max_meters_per_second = 5.0f;
- f32 movement_speed = max_meters_per_second * game_input->dt;
-
- if (game_input->key_up)
- {
- game_state->player.pos.y += movement_speed;
- }
- else if (game_input->key_down)
- {
- game_state->player.pos.y -= movement_speed;
- }
-
- if (game_input->key_left)
- {
- game_state->player.pos.x -= movement_speed;
- }
- else if (game_input->key_right)
- {
- game_state->player.pos.x += movement_speed;
- }
- glmth_clamp(&(game_state->player.pos.x), 0, ROOM_TILE_DIM_X);
- glmth_clamp(&(game_state->player.pos.y), 0, ROOM_TILE_DIM_Y);
- }
-
// render player
{
shader_use(&game_state->player.shader);