headbob en hud
This commit is contained in:
parent
0a25f91436
commit
35aa1d57c3
BIN
assets/hud.png
Normal file
BIN
assets/hud.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
BIN
assets/hud_2.png
Normal file
BIN
assets/hud_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 952 KiB |
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
/* 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;
|
t_vec2 camera;
|
||||||
double speed;
|
double speed;
|
||||||
double fov;
|
double fov;
|
||||||
int steps;
|
int is_moving;
|
||||||
} t_player;
|
} t_player;
|
||||||
|
|
||||||
typedef struct s_map
|
typedef struct s_map
|
||||||
@ -80,6 +80,7 @@ typedef struct s_screen
|
|||||||
mlx_image_t *img;
|
mlx_image_t *img;
|
||||||
mlx_image_t *minimap;
|
mlx_image_t *minimap;
|
||||||
mlx_image_t *background;
|
mlx_image_t *background;
|
||||||
|
mlx_image_t *hud;
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
} t_screen;
|
} t_screen;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
/* 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_map(game->screen, game->map);
|
||||||
render_entities(game);
|
render_entities(game);
|
||||||
keyboard_update(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)
|
void game_free(t_game *game)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 18:53:19 by qmennen #+# #+# */
|
/* 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->camera.y = 0.66f;
|
||||||
player->speed = 3.f;
|
player->speed = 3.f;
|
||||||
player->fov = 90.f;
|
player->fov = 90.f;
|
||||||
player->steps = 0;
|
player->is_moving = 0;
|
||||||
(*game)->player = player;
|
(*game)->player = player;
|
||||||
return (SUCCESS);
|
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))
|
if (xa != 0 && collision_horizontal(map, player, xa))
|
||||||
{
|
{
|
||||||
player->pos.x += xa;
|
player->pos.x += xa;
|
||||||
player->steps++;
|
player->is_moving = 1;
|
||||||
}
|
}
|
||||||
if (ya != 0 && collision_vertical(map, player, ya))
|
if (ya != 0 && collision_vertical(map, player, ya))
|
||||||
{
|
{
|
||||||
player->pos.y += 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)
|
void player_update(t_game *game, double delta_time)
|
||||||
{
|
{
|
||||||
|
game->player->is_moving = 0;
|
||||||
if (get_key(game, MLX_KEY_W))
|
if (get_key(game, MLX_KEY_W))
|
||||||
move(game->map, game->player, 1, delta_time);
|
move(game->map, game->player, 1, delta_time);
|
||||||
else if (get_key(game, MLX_KEY_S))
|
else if (get_key(game, MLX_KEY_S))
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/02 11:58:09 by whaffman #+# #+# */
|
/* 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
11
src/screen.c
11
src/screen.c
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/15 15:30:27 by qmennen #+# #+# */
|
/* 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);
|
return (FAILURE);
|
||||||
screen->width = WIDTH;
|
screen->width = WIDTH;
|
||||||
screen->height = HEIGHT;
|
screen->height = HEIGHT;
|
||||||
// mlx_set_setting(MLX_FULLSCREEN, 1);
|
|
||||||
mlx = mlx_init(WIDTH, HEIGHT, TITLE, false);
|
mlx = mlx_init(WIDTH, HEIGHT, TITLE, false);
|
||||||
if (!mlx)
|
if (!mlx)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
screen->mlx = mlx;
|
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)
|
if (!screen->img)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
screen->minimap = mlx_new_image(screen->mlx, WIDTH, HEIGHT);
|
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);
|
screen->background = mlx_new_image(screen->mlx, WIDTH, HEIGHT);
|
||||||
if (!screen->background)
|
if (!screen->background)
|
||||||
return (FAILURE);
|
return (FAILURE);
|
||||||
|
screen->hud =mlx_texture_to_image(mlx, mlx_load_png("./assets/hud.png"));
|
||||||
(*game)->screen = screen;
|
(*game)->screen = screen;
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
@ -81,6 +81,11 @@ int screen_display(t_screen *screen)
|
|||||||
printf(RED"Failed to display buffer image\n"RESET);
|
printf(RED"Failed to display buffer image\n"RESET);
|
||||||
return (FAILURE);
|
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);
|
mlx_get_monitor_size(0, &m_width, &m_height);
|
||||||
if (m_width == 0 || m_height == 0)
|
if (m_width == 0 || m_height == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user