diff --git a/Makefile b/Makefile index bc23d75..5067e68 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: qmennen +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/05/27 17:00:58 by qmennen ### ########.fr # +# Updated: 2025/05/28 17:44:58 by qmennen ### ########.fr # # # # **************************************************************************** # diff --git a/inc/cub3d.h b/inc/cub3d.h index 90306e3..8cdb116 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 12:22:29 by qmennen #+# #+# */ -/* Updated: 2025/05/27 18:14:06 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:30:51 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ # include "texture.h" # include "game_manager.h" # include "game_menu.h" +# include "monster.h" int initialize_cub3d(t_game **game, const char *mapfile); int shader_init(t_game **game); diff --git a/inc/monster.h b/inc/monster.h new file mode 100644 index 0000000..c6eeeb4 --- /dev/null +++ b/inc/monster.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* monster.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/28 17:16:29 by qmennen #+# #+# */ +/* Updated: 2025/05/28 17:16:43 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MONSTER_H +# define MONSTER_H + +# include "cub3d.h" + +void update_monsters(t_game *game); + +#endif \ No newline at end of file diff --git a/monster.cub b/monster.cub new file mode 100644 index 0000000..79abf5a --- /dev/null +++ b/monster.cub @@ -0,0 +1,24 @@ + + +NO ./assets/tiles256.png + +WE ./assets/bricks2.png + +SO ./assets/stonewall256.png +EA ./assets/bricksx64.png + +F 90,30,30 + + +C 100,100,200 + +FT ./assets/tiles3.png +CT ./assets/ceiling64x64.png + +-s a ./assets/flying_eye.png + +11111111 +1000a001 +10000001 +100N0001 +11111111 \ No newline at end of file diff --git a/src/game/game.c b/src/game/game.c index 5922e7d..8e5b2c6 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */ -/* Updated: 2025/05/28 16:40:12 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:39:24 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,9 +45,9 @@ void game_run(t_game *game) game->elapsed_time += game->screen->mlx->delta_time; fps += (int)(1.f / game->screen->mlx->delta_time); set_uniforms(game); - player_update(game, game->screen->mlx->delta_time); cast_rays(game); + update_monsters(game); render_map(game); if (game->player->is_moving) { diff --git a/src/monster/monster.c b/src/monster/monster.c new file mode 100644 index 0000000..ffc5345 --- /dev/null +++ b/src/monster/monster.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* monster.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/05/28 17:15:52 by qmennen #+# #+# */ +/* Updated: 2025/05/28 17:45:37 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# include "cub3d.h" + +void update_monsters(t_game *game) +{ + int i; + double dx; + double dy; + t_sprite *sprite; + + i = -1; + while (++i < game->map->n_sprites) + { + sprite = &game->map->sprites[i]; + if (sprite->type != SPRITE_TYPE_ENEMY) + continue; + dx = game->player->pos.x - sprite->pos.x; + dy = game->player->pos.y - sprite->pos.y; + double dist_squared = dx * dx + dy * dy; + if (dist_squared > 0) + { + double inv_dist = 1.0 / sqrt(dist_squared); + sprite->pos.x += dx * inv_dist * .05f; + sprite->pos.y += dy * inv_dist * .05f; + } + } +} \ No newline at end of file diff --git a/src/parser/parse_config_line.c b/src/parser/parse_config_line.c index 86898ca..cf1bdc1 100644 --- a/src/parser/parse_config_line.c +++ b/src/parser/parse_config_line.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */ -/* Updated: 2025/05/28 17:13:29 by qmennen ### ########.fr */ +/* Updated: 2025/05/28 17:32:08 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -112,7 +112,7 @@ int handle_sprite(char *token, t_map *map) else { sprite.collectible = 0; - sprite.type = SPRITE_TYPE_DEFAULT; + sprite.type = SPRITE_TYPE_ENEMY; } symbol = *ft_strtok(NULL, " "); if (symbol < 'a' || symbol > 'z')