NORM
This commit is contained in:
parent
09fa9aa66f
commit
6231545044
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/19 14:41:55 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:47:28 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 14:43:25 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -31,4 +31,10 @@ t_tile **copy_map(t_tile **grid, int width, int height);
|
||||
char **pointer_lines(char *buffer, char c);
|
||||
int valid_arguments(int argc, char **argv);
|
||||
int map_entries_present(t_game *game);
|
||||
int handle_wall(char *token, t_map *map);
|
||||
int handle_fc_color(char *token, t_map *map);
|
||||
int handle_fc_texture(char *token, t_map *map);
|
||||
int handle_sprite(char *token, t_map *map);
|
||||
mlx_texture_t *load_texture(const char *path);
|
||||
|
||||
#endif
|
||||
16
inc/render.h
16
inc/render.h
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* render.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/22 14:00:45 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* render.h :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:28:16 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 14:47:34 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
# define RENDER_H
|
||||
|
||||
# include "cub3d.h"
|
||||
|
||||
# define MIN_SPRITE_DIST 0.1
|
||||
void render_map(t_game *game);
|
||||
t_render cast_ray(t_game *game, int x);
|
||||
void cast_rays(t_game *game);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 14:40:59 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/29 11:17:56 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:42:51 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -28,15 +28,13 @@ int collision_sprite(t_map *map, t_player *player, double xa, double ya)
|
||||
i = 0;
|
||||
while (i < map->n_sprites)
|
||||
{
|
||||
if ((sprites[i].type == SPRITE_TYPE_COLLECTIBLE || sprites[i].type == SPRITE_TYPE_ENEMY)
|
||||
&& (fabs(player->pos.x + xa - sprites[i].pos.x) < 0.5
|
||||
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5))
|
||||
if ((sprites[i].type == SPRITE_TYPE_COLLECTIBLE
|
||||
|| sprites[i].type == SPRITE_TYPE_ENEMY)
|
||||
&& (fabs(player->pos.x + xa - sprites[i].pos.x) < 0.5
|
||||
&& fabs(player->pos.y + ya - sprites[i].pos.y) < 0.5))
|
||||
{
|
||||
if (sprites[i].type == SPRITE_TYPE_ENEMY)
|
||||
{
|
||||
player->battery -= 0.0001;
|
||||
printf("You were attacked by an enemy! Battery: %.2f\n", player->battery);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprites[i].type = SPRITE_TYPE_COLLECTED;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 15:46:08 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/29 11:14:15 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:24:01 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
// #include "glad.h"
|
||||
// #include "MLX42_Int.h"
|
||||
|
||||
int game_create(t_game **game)
|
||||
int game_create(t_game **game)
|
||||
{
|
||||
*game = malloc(sizeof(t_game));
|
||||
if (!game)
|
||||
@ -24,7 +24,7 @@ int game_create(t_game **game)
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
void free_game(t_game **game)
|
||||
void free_game(t_game **game)
|
||||
{
|
||||
if (game && *game)
|
||||
{
|
||||
@ -38,9 +38,9 @@ void free_game(t_game **game)
|
||||
}
|
||||
}
|
||||
|
||||
void game_run(t_game *game)
|
||||
void game_run(t_game *game)
|
||||
{
|
||||
static int fps = 0;
|
||||
static int fps = 0;
|
||||
|
||||
game->elapsed_time += game->screen->mlx->delta_time;
|
||||
fps += (int)(1.f / game->screen->mlx->delta_time);
|
||||
@ -59,7 +59,7 @@ void game_run(t_game *game)
|
||||
collision_sprite(game->map, game->player, 0, 0);
|
||||
}
|
||||
|
||||
void game_free(t_game *game)
|
||||
void game_free(t_game *game)
|
||||
{
|
||||
if (game->screen)
|
||||
{
|
||||
@ -82,7 +82,7 @@ void game_free(t_game *game)
|
||||
free(game);
|
||||
}
|
||||
|
||||
void game_terminate(t_game *game)
|
||||
void game_terminate(t_game *game)
|
||||
{
|
||||
print_scores(game);
|
||||
game_free(game);
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:01:29 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 18:49:29 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:43:05 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_game_manager *manager;
|
||||
t_game *game;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/23 12:21:13 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:04:12 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:24:13 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,7 +57,6 @@ static int map_validate_and_finalize(t_game **game, t_tile **grid)
|
||||
{
|
||||
ft_putendl_fd("Map is not enclosed", STDERR_FILENO);
|
||||
grid_free(grid, (*game)->map->height);
|
||||
// map_free((*game)->map);
|
||||
return (FAILURE);
|
||||
}
|
||||
grid_free((*game)->map->grid, (*game)->map->height);
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* map_entries_present.c :+: :+: */
|
||||
/* map_entries_present.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/29 12:38:19 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:44:10 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:25:11 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/23 12:22:28 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:05:59 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:28:30 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
void map_free(t_map *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!map)
|
||||
return ;
|
||||
|
||||
grid_free(map->grid, map->height);
|
||||
if (map->texture_floor)
|
||||
mlx_delete_texture(map->texture_floor);
|
||||
@ -29,16 +29,14 @@ void map_free(t_map *map)
|
||||
{
|
||||
if (map->sprite_lib[i].texture)
|
||||
mlx_delete_texture(map->sprite_lib[i].texture);
|
||||
if (i < 4)
|
||||
{
|
||||
if (map->textures[i])
|
||||
mlx_delete_texture(map->textures[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
free(map->sprite_lib);
|
||||
free(map->sprites);
|
||||
i = 4;
|
||||
while (i > 0)
|
||||
{
|
||||
i--;
|
||||
if (map->textures[i])
|
||||
mlx_delete_texture(map->textures[i]);
|
||||
}
|
||||
free(map);
|
||||
}
|
||||
|
||||
@ -6,18 +6,19 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/28 17:15:52 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/29 10:47:19 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 14:51:23 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
# include "cub3d.h"
|
||||
#include "cub3d.h"
|
||||
|
||||
void update_monsters(t_game *game)
|
||||
{
|
||||
int i;
|
||||
double dx;
|
||||
double dy;
|
||||
t_vec2 d;
|
||||
t_sprite *sprite;
|
||||
double dist_squared;
|
||||
double inv_dist;
|
||||
|
||||
i = -1;
|
||||
while (++i < game->map->n_sprites)
|
||||
@ -25,14 +26,13 @@ void update_monsters(t_game *game)
|
||||
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)
|
||||
d = sub(game->player->pos, sprite->pos);
|
||||
dist_squared = d.x * d.x + d.y * d.y;
|
||||
if (dist_squared >= 0.02)
|
||||
{
|
||||
double inv_dist = 1.0 / sqrt(dist_squared);
|
||||
sprite->pos.x += dx * inv_dist * .05f;
|
||||
sprite->pos.y += dy * inv_dist * .05f;
|
||||
inv_dist = 1.0 / sqrt(dist_squared);
|
||||
sprite->pos.x += d.x * inv_dist * .05f;
|
||||
sprite->pos.y += d.y * inv_dist * .05f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 20:08:27 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 11:16:13 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:43:26 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -29,7 +29,6 @@ static void move(t_map *map, t_player *player, int dir, double delta)
|
||||
player->pos.y += ya;
|
||||
player->is_moving = 1;
|
||||
}
|
||||
// collision_sprite(map, player, xa, ya);
|
||||
}
|
||||
|
||||
static void strave(t_map *map, t_player *player, int dir, double delta)
|
||||
@ -76,7 +75,6 @@ void visit_area(t_game *game)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void player_update(t_game *game, double delta_time)
|
||||
{
|
||||
game->player->is_moving = 0;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:10:06 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:52:32 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 14:40:15 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -26,125 +26,6 @@ mlx_texture_t *load_texture(const char *path)
|
||||
return (texture);
|
||||
}
|
||||
|
||||
int handle_wall(char *token, t_map *map)
|
||||
{
|
||||
const char *wall_tokens[] = {
|
||||
"NO", "SO", "WE", "EA", NULL
|
||||
};
|
||||
char *texture_path;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (texture_path == NULL)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " ") != NULL)
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
while (wall_tokens[i])
|
||||
{
|
||||
if (ft_strcmp(token, wall_tokens[i]) == 0)
|
||||
{
|
||||
if (map->textures[i] != NULL)
|
||||
return (FAILURE);
|
||||
map->textures[i] = load_texture(texture_path);
|
||||
if (map->textures[i] == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_color(char *token, t_map *map)
|
||||
{
|
||||
char *color_str;
|
||||
int color;
|
||||
|
||||
color_str = ft_strtok(NULL, " ");
|
||||
if ((ft_strcmp(token, "F") == 0 && map->floor_color != 0x0)
|
||||
|| (ft_strcmp(token, "C") == 0 && map->ceiling_color != 0x0))
|
||||
return (ft_putstr_fd("Error: Color already set or fully transparent\n", 2), FAILURE);
|
||||
if (!color_str)
|
||||
return (ft_putstr_fd("Error: Missing color value\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after color value\n", 2),
|
||||
FAILURE);
|
||||
color = parse_color(color_str);
|
||||
if (!color)
|
||||
return (ft_putstr_fd("Error: Invalid color value\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "F") == 0)
|
||||
map->floor_color = color;
|
||||
else if (ft_strcmp(token, "C") == 0)
|
||||
map->ceiling_color = color;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_texture(char *token, t_map *map)
|
||||
{
|
||||
char *texture_path;
|
||||
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if ((ft_strcmp(token, "FT") == 0 && map->texture_floor != 0x0)
|
||||
|| (ft_strcmp(token, "CT") == 0 && map->texture_ceiling != 0x0))
|
||||
return (ft_putstr_fd("Error: Texture already set\n", 2), FAILURE);
|
||||
if (!texture_path)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "FT") == 0)
|
||||
{
|
||||
map->texture_floor = load_texture(texture_path);
|
||||
if (map->texture_floor == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
else if (ft_strcmp(token, "CT") == 0)
|
||||
{
|
||||
map->texture_ceiling = load_texture(texture_path);
|
||||
if (map->texture_ceiling == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_sprite(char *token, t_map *map)
|
||||
{
|
||||
t_sprite_lib sprite;
|
||||
char *symbol;
|
||||
char *texture_path;
|
||||
|
||||
if (token[1] == 'c')
|
||||
{
|
||||
sprite.collectible = 1;
|
||||
sprite.type = SPRITE_TYPE_COLLECTIBLE;
|
||||
}
|
||||
else if (token[1] == 'e')
|
||||
{
|
||||
sprite.collectible = 0;
|
||||
sprite.type = SPRITE_TYPE_ENEMY;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.collectible = 0;
|
||||
sprite.type = SPRITE_TYPE_DEFAULT;
|
||||
}
|
||||
symbol = ft_strtok(NULL, " ");
|
||||
if (*symbol < 'a' || *symbol > 'z' ||ft_strlen(symbol) != 1)
|
||||
return (ft_putstr_fd("Error: Invalid sprite symbol\n", 2), FAILURE);
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (texture_path == NULL)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " ") != NULL)
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
sprite.texture = load_texture(texture_path);
|
||||
if (sprite.texture == NULL)
|
||||
return (FAILURE);
|
||||
if (map->sprite_lib[*symbol - 'a'].texture != NULL)
|
||||
return (ft_putstr_fd(
|
||||
"Error: Sprite already defined for this symbol\n", 2), FAILURE);
|
||||
map->sprite_lib[*symbol - 'a'] = sprite;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
t_token_handler handle_config_token(const char *token, t_map *map)
|
||||
{
|
||||
const char *config_tokens[] = {
|
||||
|
||||
139
src/parser/parse_handlers.c
Normal file
139
src/parser/parse_handlers.c
Normal file
@ -0,0 +1,139 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* parse_handlers.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/06/03 14:38:12 by whaffman #+# #+# */
|
||||
/* Updated: 2025/06/03 14:54:00 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
|
||||
int handle_wall(char *token, t_map *map)
|
||||
{
|
||||
const char *wall_tokens[] = {
|
||||
"NO", "SO", "WE", "EA", NULL
|
||||
};
|
||||
char *texture_path;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (texture_path == NULL)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " ") != NULL)
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
while (wall_tokens[i])
|
||||
{
|
||||
if (ft_strcmp(token, wall_tokens[i]) == 0)
|
||||
{
|
||||
if (map->textures[i] != NULL)
|
||||
return (FAILURE);
|
||||
map->textures[i] = load_texture(texture_path);
|
||||
if (map->textures[i] == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_color(char *token, t_map *map)
|
||||
{
|
||||
char *color_str;
|
||||
int color;
|
||||
|
||||
color_str = ft_strtok(NULL, " ");
|
||||
if ((ft_strcmp(token, "F") == 0 && map->floor_color != 0x0)
|
||||
|| (ft_strcmp(token, "C") == 0 && map->ceiling_color != 0x0))
|
||||
return (ft_putstr_fd("Error: Color already set \n", 2), FAILURE);
|
||||
if (!color_str)
|
||||
return (ft_putstr_fd("Error: Missing color value\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after color value\n", 2),
|
||||
FAILURE);
|
||||
color = parse_color(color_str);
|
||||
if (!color)
|
||||
return (ft_putstr_fd("Error: Invalid color value\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "F") == 0)
|
||||
map->floor_color = color;
|
||||
else if (ft_strcmp(token, "C") == 0)
|
||||
map->ceiling_color = color;
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_fc_texture(char *token, t_map *map)
|
||||
{
|
||||
char *texture_path;
|
||||
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if ((ft_strcmp(token, "FT") == 0 && map->texture_floor != 0x0)
|
||||
|| (ft_strcmp(token, "CT") == 0 && map->texture_ceiling != 0x0))
|
||||
return (ft_putstr_fd("Error: Texture already set\n", 2), FAILURE);
|
||||
if (!texture_path)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " "))
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
if (ft_strcmp(token, "FT") == 0)
|
||||
{
|
||||
map->texture_floor = load_texture(texture_path);
|
||||
if (map->texture_floor == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
else if (ft_strcmp(token, "CT") == 0)
|
||||
{
|
||||
map->texture_ceiling = load_texture(texture_path);
|
||||
if (map->texture_ceiling == NULL)
|
||||
return (FAILURE);
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int set_sprite_type(char *token, t_sprite_lib *sprite)
|
||||
{
|
||||
if (token[1] == 'c')
|
||||
{
|
||||
sprite->collectible = 1;
|
||||
sprite->type = SPRITE_TYPE_COLLECTIBLE;
|
||||
}
|
||||
else if (token[1] == 'e')
|
||||
{
|
||||
sprite->collectible = 0;
|
||||
sprite->type = SPRITE_TYPE_ENEMY;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->collectible = 0;
|
||||
sprite->type = SPRITE_TYPE_DEFAULT;
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
||||
int handle_sprite(char *token, t_map *map)
|
||||
{
|
||||
t_sprite_lib sprite;
|
||||
char *symbol;
|
||||
char *texture_path;
|
||||
|
||||
if (!set_sprite_type(token, &sprite))
|
||||
return (ft_putstr_fd("Error: Invalid sprite type\n", 2), FAILURE);
|
||||
symbol = ft_strtok(NULL, " ");
|
||||
if (*symbol < 'a' || *symbol > 'z' || ft_strlen(symbol) != 1)
|
||||
return (ft_putstr_fd("Error: Invalid sprite symbol\n", 2), FAILURE);
|
||||
texture_path = ft_strtok(NULL, " ");
|
||||
if (texture_path == NULL)
|
||||
return (ft_putstr_fd("Error: Missing texture path\n", 2), FAILURE);
|
||||
if (ft_strtok(NULL, " ") != NULL)
|
||||
return (ft_putstr_fd("Error: Extra tokens after path\n", 2), FAILURE);
|
||||
sprite.texture = load_texture(texture_path);
|
||||
if (sprite.texture == NULL)
|
||||
return (FAILURE);
|
||||
if (map->sprite_lib[*symbol - 'a'].texture != NULL)
|
||||
return (ft_putstr_fd(
|
||||
"Error: Sprite already defined for this symbol\n", 2), FAILURE);
|
||||
map->sprite_lib[*symbol - 'a'] = sprite;
|
||||
return (SUCCESS);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 13:11:18 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/25 10:53:31 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:37:35 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,10 +17,6 @@ void print_config(t_map *map)
|
||||
printf("Map:\n");
|
||||
printf("Width: %d, Height: %d\n", map->width, map->height);
|
||||
printf("Textures:\n");
|
||||
// printf("NO: %s\n", map->north_texture);
|
||||
// printf("SO: %s\n", map->south_texture);
|
||||
// printf("WE: %s\n", map->west_texture);
|
||||
// printf("EA: %s\n", map->east_texture);
|
||||
printf("Floor color: %u\n", map->floor_color);
|
||||
printf("Ceiling color: %u\n", map->ceiling_color);
|
||||
printf("Grid:\n");
|
||||
|
||||
@ -6,33 +6,33 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/15 16:28:10 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/29 09:37:49 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:38:16 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
void flash(t_game *game)
|
||||
|
||||
void flash(t_game *game)
|
||||
{
|
||||
mlx_image_t *img;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
mlx_image_t *img;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
if (game->screen->flash == 0)
|
||||
return;
|
||||
return ;
|
||||
img = game->screen->img;
|
||||
game->screen->flash--;
|
||||
x=0;
|
||||
x = 0;
|
||||
while (x < img->width)
|
||||
{
|
||||
y = 0;
|
||||
while (y < img->height)
|
||||
{
|
||||
mlx_put_pixel(img, x, y, 0xffffffff);
|
||||
mlx_put_pixel(img, x, y, 0xffffffff);
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cast_rays(t_game *game)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/14 13:06:39 by whaffman #+# #+# */
|
||||
/* Updated: 2025/05/29 12:57:37 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 13:38:31 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -57,7 +57,7 @@ static void draw_floor_row(t_game *game,
|
||||
floor_step = calc_floor_step(game, row_dist, left_ray, right_ray);
|
||||
floor_pos = add(game->player->pos, mul(left_ray, row_dist));
|
||||
if (isinf(floor_pos.x) || isinf(floor_pos.y))
|
||||
return;
|
||||
return ;
|
||||
while (coord.x < game->screen->width)
|
||||
{
|
||||
draw_floor_ceiling_pixel(game, coord, row_dist, floor_pos);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/05/08 12:23:17 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/29 11:16:51 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/06/03 14:47:08 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -32,7 +32,7 @@ static int sprite_visible(t_game *game,
|
||||
t_sprite *sprite, t_render *render, int x)
|
||||
{
|
||||
return (!isnan(sprite->cam_frac)
|
||||
&& sprite->dist > 0.5
|
||||
&& sprite->dist > MIN_SPRITE_DIST
|
||||
&& x > 0
|
||||
&& x < game->screen->width
|
||||
&& sprite->dist <= render[x].perp_dist);
|
||||
@ -46,7 +46,10 @@ static void draw_sprite_column(
|
||||
t_vec2 inv_range;
|
||||
int y;
|
||||
unsigned int color;
|
||||
int frame;
|
||||
|
||||
frame = (game->elapsed_time * sprite->animation_speed);
|
||||
frame %= sprite->n_frames;
|
||||
inv_range.y = 1.0 / (column.end.y - column.start.y);
|
||||
inv_range.x = 1.0 / (column.end.x - column.start.x);
|
||||
sprite->alpha = calculate_alpha(column.start.x,
|
||||
@ -59,8 +62,7 @@ static void draw_sprite_column(
|
||||
{
|
||||
tex.y = (y - column.start.y) * sprite->texture->height;
|
||||
tex.y *= inv_range.y;
|
||||
color = sample_texture_color(sprite, tex,
|
||||
(int)(game->elapsed_time * sprite->animation_speed) % sprite->n_frames);
|
||||
color = sample_texture_color(sprite, tex, frame);
|
||||
if (y > 0 && y < game->screen->height && (color & 0xFF) != 0)
|
||||
mlx_put_pixel(game->screen->img, column.x, y, color);
|
||||
y++;
|
||||
@ -69,7 +71,7 @@ static void draw_sprite_column(
|
||||
|
||||
void handle_flash(t_sprite *sprite, t_game *game)
|
||||
{
|
||||
if (sprite->type == SPRITE_TYPE_ENEMY && game->screen->flash > 0
|
||||
if (sprite->type == SPRITE_TYPE_ENEMY && game->screen->flash > 0
|
||||
&& sprite->dist < 2.0)
|
||||
sprite->type = SPRITE_TYPE_DISABLED;
|
||||
}
|
||||
@ -81,7 +83,7 @@ void draw_sprite(t_game *game, t_sprite *sprite, t_render *render)
|
||||
t_sprite_column column;
|
||||
int x;
|
||||
|
||||
if (isnan(sprite->cam_frac) || sprite->dist <= 0.5)
|
||||
if (isnan(sprite->cam_frac) || sprite->dist <= MIN_SPRITE_DIST)
|
||||
return ;
|
||||
get_start_end(game, sprite, &start, &end);
|
||||
x = start.x;
|
||||
@ -114,7 +116,7 @@ void render_sprites(t_render *render, t_game *game)
|
||||
i++;
|
||||
continue ;
|
||||
}
|
||||
cam_fraction(game, &game->map->sprites[i]);
|
||||
cam_fraction(game, &game->map->sprites[i]);
|
||||
draw_sprite(game, &game->map->sprites[i], render);
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* initialize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/05/28 17:15:03 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* initialize.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/04/22 17:08:26 by qmennen #+# #+# */
|
||||
/* Updated: 2025/06/03 13:41:33 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,16 +18,6 @@ t_sprite make_sprite(t_sprite_lib *def, double x, double y)
|
||||
|
||||
ft_memset(&sprite, 0, sizeof(t_sprite));
|
||||
sprite.texture = def->texture;
|
||||
// if (sprite.texture->width % 64 != 0)
|
||||
// {
|
||||
// ft_putstr_fd("Error: Texture width is not a multiple of 64\n", 2);
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
// if (sprite.texture->height != 64)
|
||||
// {
|
||||
// ft_putstr_fd("Error: Texture height must be 64\n", 2);
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
sprite.n_frames = sprite.texture->width / sprite.texture->height;
|
||||
sprite.animation_speed = 10;
|
||||
sprite.pos.x = x;
|
||||
@ -39,22 +29,7 @@ t_sprite make_sprite(t_sprite_lib *def, double x, double y)
|
||||
static int init_temp(t_game **game)
|
||||
{
|
||||
mlx_texture_t *hud_texture;
|
||||
// t_sprite *sprites;
|
||||
// (*game)->map->sprites = malloc(sizeof(t_sprite) * 10);
|
||||
// if (!(*game)->map->sprites)
|
||||
// return (FAILURE);
|
||||
// sprites = (*game)->map->sprites;
|
||||
// sprites[0] = make_sprite("./assets/battery.png", 3.5, 3.5, 1);
|
||||
// sprites[1] = make_sprite("./assets/plant.png", 2.5, 3.5, 0);
|
||||
// sprites[2] = make_sprite("./assets/plant.png", 1.5, 3.5, 0);
|
||||
// sprites[3] = make_sprite("./assets/broken_mirror.png", 3.5, 4.5, 0);
|
||||
// sprites[4] = make_sprite("./assets/lamp.png", 2.5, 5.5, 0);
|
||||
// sprites[5] = make_sprite("./assets/battery.png", 10.5, 6.5, 1);
|
||||
// sprites[6] = make_sprite("./assets/plant.png", 14.5, 3.5, 0);
|
||||
// sprites[7] = make_sprite("./assets/battery.png", 2.5, 7.5, 1);
|
||||
// sprites[8] = make_sprite("./assets/broken_mirror.png", 42.5, 4.5, 0);
|
||||
// sprites[9] = make_sprite("./assets/lamp.png", 9.5, 10.5, 0);
|
||||
// (*game)->map->n_sprites = 10;
|
||||
|
||||
hud_texture = mlx_load_png("./assets/overlay2.png");
|
||||
(*game)->screen->hud = mlx_texture_to_image((*game)->screen->mlx,
|
||||
hud_texture);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user