headbob en hud

This commit is contained in:
Quinten Mennen 2025-05-08 12:06:44 +02:00
parent 0a25f91436
commit 35aa1d57c3
7 changed files with 23 additions and 11 deletions

BIN
assets/hud.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

BIN
assets/hud_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 KiB

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
/* Updated: 2025/05/06 19:20:58 by qmennen ### ########.fr */
/* Updated: 2025/05/06 20:03:48 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,7 +49,7 @@ typedef struct s_player
t_vec2 camera;
double speed;
double fov;
int steps;
int is_moving;
} t_player;
typedef struct s_map
@ -80,6 +80,7 @@ typedef struct s_screen
mlx_image_t *img;
mlx_image_t *minimap;
mlx_image_t *background;
mlx_image_t *hud;
unsigned int width;
unsigned int height;
} t_screen;

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
/* Updated: 2025/05/06 18:56:57 by qmennen ### ########.fr */
/* Updated: 2025/05/06 19:57:54 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,6 +60,11 @@ void game_loop(void *param)
render_map(game->screen, game->map);
render_entities(game);
keyboard_update(game);
if (game->player->is_moving)
{
game->screen->img->instances[0].x += sin(framecount / 4) * 10;
game->screen->img->instances[0].y += (-0.5 * cos((framecount / 2))) * 10;
}
}
void game_free(t_game *game)

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
/* Updated: 2025/05/06 19:22:37 by qmennen ### ########.fr */
/* Updated: 2025/05/06 19:54:42 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ int player_create(t_game **game)
player->camera.y = 0.66f;
player->speed = 3.f;
player->fov = 90.f;
player->steps = 0;
player->is_moving = 0;
(*game)->player = player;
return (SUCCESS);
}
@ -42,12 +42,12 @@ static void move(t_map *map, t_player *player, int dir, double delta)
if (xa != 0 && collision_horizontal(map, player, xa))
{
player->pos.x += xa;
player->steps++;
player->is_moving = 1;
}
if (ya != 0 && collision_vertical(map, player, ya))
{
player->pos.y += ya;
player->steps++;
player->is_moving = 1;
}
}
@ -72,6 +72,7 @@ static void rotate(t_player *player, double rot_speed)
void player_update(t_game *game, double delta_time)
{
game->player->is_moving = 0;
if (get_key(game, MLX_KEY_W))
move(game->map, game->player, 1, delta_time);
else if (get_key(game, MLX_KEY_S))

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */
/* Updated: 2025/05/06 19:49:13 by qmennen ### ########.fr */
/* Updated: 2025/05/06 19:56:47 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
/* Updated: 2025/05/06 19:19:23 by qmennen ### ########.fr */
/* Updated: 2025/05/06 20:47:13 by qmennen ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,12 +22,11 @@ int screen_create(t_game **game)
return (FAILURE);
screen->width = WIDTH;
screen->height = HEIGHT;
// mlx_set_setting(MLX_FULLSCREEN, 1);
mlx = mlx_init(WIDTH, HEIGHT, TITLE, false);
if (!mlx)
return (FAILURE);
screen->mlx = mlx;
screen->img = mlx_new_image(screen->mlx, WIDTH, HEIGHT);
screen->img = mlx_new_image(screen->mlx, WIDTH + 50, HEIGHT + 50);
if (!screen->img)
return (FAILURE);
screen->minimap = mlx_new_image(screen->mlx, WIDTH, HEIGHT);
@ -36,6 +35,7 @@ int screen_create(t_game **game)
screen->background = mlx_new_image(screen->mlx, WIDTH, HEIGHT);
if (!screen->background)
return (FAILURE);
screen->hud =mlx_texture_to_image(mlx, mlx_load_png("./assets/hud.png"));
(*game)->screen = screen;
return (SUCCESS);
}
@ -81,6 +81,11 @@ int screen_display(t_screen *screen)
printf(RED"Failed to display buffer image\n"RESET);
return (FAILURE);
}
if (mlx_image_to_window(screen->mlx, screen->hud, 0, 0) < 0)
{
printf(RED"Failed to display buffer image\n"RESET);
return (FAILURE);
}
mlx_get_monitor_size(0, &m_width, &m_height);
if (m_width == 0 || m_height == 0)
{