mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
Compare commits
5 commits
db66decbf8
...
3511b6aaf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3511b6aaf8 | ||
|
|
0d6cc4063a | ||
|
|
4a70e44697 | ||
|
|
94075506f6 | ||
|
|
412dc89336 |
6 changed files with 35 additions and 22 deletions
13
src/consts.h
13
src/consts.h
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/08/12 14:49:36 by tchampio ### ########.fr */
|
/* Updated: 2025/08/14 21:23:25 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,6 +35,10 @@
|
||||||
// Sprite consts
|
// Sprite consts
|
||||||
# define SPRITE_TRANPARENCY_COLOR 0xff00dc
|
# define SPRITE_TRANPARENCY_COLOR 0xff00dc
|
||||||
# define MAX_SPRITES 30
|
# define MAX_SPRITES 30
|
||||||
|
# define JUGG_TEX "ressources/juggernog.xpm"
|
||||||
|
# define REV_TEX "ressources/revive.xpm"
|
||||||
|
# define DBLTAP_TEX "ressources/doubletap.xpm"
|
||||||
|
# define MYSTERY_TEX "ressources/box.xpm"
|
||||||
|
|
||||||
# ifdef BONUS
|
# ifdef BONUS
|
||||||
# define COMPILED_TEXT "Compiled with bonuses"
|
# define COMPILED_TEXT "Compiled with bonuses"
|
||||||
|
|
@ -48,5 +52,12 @@
|
||||||
# define EMALMAP "Map is malformed (invalid chars or missing walls)"
|
# define EMALMAP "Map is malformed (invalid chars or missing walls)"
|
||||||
# define ENOPLAYER "No player"
|
# define ENOPLAYER "No player"
|
||||||
# define EHOLES "Holes in map"
|
# define EHOLES "Holes in map"
|
||||||
|
# define ETRAILING "Trailing chars after map"
|
||||||
|
# define EBADCHARCOLOR "invalid characters in color definition"
|
||||||
|
# define EBADVALCOLOR "invalid value for colors"
|
||||||
|
# define ETOOMANYCOLORS "too many colors"
|
||||||
|
# define ENOTENOUGHCOLORS "Not enough colors"
|
||||||
|
# define EDUPTEX "Duplicated texture directive"
|
||||||
|
# define EMAPBFTEX "Map started before all the textures"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:59:37 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/08/11 11:59:21 by tchampio ### ########.fr */
|
/* Updated: 2025/08/14 21:36:15 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,6 +40,7 @@ typedef struct s_cub3d_data
|
||||||
int delta;
|
int delta;
|
||||||
int last_tick;
|
int last_tick;
|
||||||
t_sprite **sprite_list;
|
t_sprite **sprite_list;
|
||||||
|
int sprite_counter;
|
||||||
double zbuffer[WIDTH];
|
double zbuffer[WIDTH];
|
||||||
int sprite_order[MAX_SPRITES];
|
int sprite_order[MAX_SPRITES];
|
||||||
double sprite_distances[MAX_SPRITES];
|
double sprite_distances[MAX_SPRITES];
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */
|
/* Created: 2025/07/17 14:44:02 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/23 13:34:33 by kcolin ### ########.fr */
|
/* Updated: 2025/08/14 19:46:26 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ bool populate_maps(t_mapdata *map, int fd)
|
||||||
{
|
{
|
||||||
if (line[0] != '\n' && end_reached)
|
if (line[0] != '\n' && end_reached)
|
||||||
{
|
{
|
||||||
ft_strlcpy(map->error, "Trailing chars after map", ERRLEN);
|
ft_strlcpy(map->error, ETRAILING, ERRLEN);
|
||||||
retvalue = false;
|
retvalue = false;
|
||||||
}
|
}
|
||||||
if (line[0] != '\n')
|
if (line[0] != '\n')
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */
|
/* Created: 2025/06/21 19:35:43 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/31 14:08:27 by kcolin ### ########.fr */
|
/* Updated: 2025/08/14 19:50:20 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../libft/includes/libft.h"
|
#include "../../libft/includes/libft.h"
|
||||||
#include "../utils/frees.h"
|
#include "../utils/frees.h"
|
||||||
|
#include "../consts.h"
|
||||||
#include "mapdata.h"
|
#include "mapdata.h"
|
||||||
|
|
||||||
bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
|
bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
|
||||||
|
|
@ -24,8 +25,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
|
||||||
{
|
{
|
||||||
if (!ft_isdigit(strcolor[i]))
|
if (!ft_isdigit(strcolor[i]))
|
||||||
{
|
{
|
||||||
ft_strlcpy(map->error, "invalid characters in color definition",
|
ft_strlcpy(map->error, EBADCHARCOLOR, ERRLEN);
|
||||||
ERRLEN);
|
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -33,7 +33,7 @@ bool perform_color_checks(int *color, char *strcolor, t_mapdata *map)
|
||||||
colorvalue = ft_atoi(strcolor);
|
colorvalue = ft_atoi(strcolor);
|
||||||
if (colorvalue < 0 || colorvalue > 255)
|
if (colorvalue < 0 || colorvalue > 255)
|
||||||
{
|
{
|
||||||
ft_strlcpy(map->error, "invalid value for colors", ERRLEN);
|
ft_strlcpy(map->error, EBADVALCOLOR, ERRLEN);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
*color = colorvalue;
|
*color = colorvalue;
|
||||||
|
|
@ -53,14 +53,14 @@ unsigned int set_color(const char *s, t_mapdata *map)
|
||||||
while (tab[i])
|
while (tab[i])
|
||||||
{
|
{
|
||||||
if (i > 2)
|
if (i > 2)
|
||||||
ft_strlcpy(map->error, "too many colors", ERRLEN);
|
ft_strlcpy(map->error, ETOOMANYCOLORS, ERRLEN);
|
||||||
isok = perform_color_checks(&rgb[i], tab[i], map);
|
isok = perform_color_checks(&rgb[i], tab[i], map);
|
||||||
free(tab[i]);
|
free(tab[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
free(tab);
|
free(tab);
|
||||||
if (i <= 2)
|
if (i <= 2)
|
||||||
return (ft_strlcpy(map->error, "Not enough colors", ERRLEN), 0);
|
return (ft_strlcpy(map->error, ENOTENOUGHCOLORS, ERRLEN), 0);
|
||||||
if (!isok)
|
if (!isok)
|
||||||
return (0);
|
return (0);
|
||||||
finalcolor = ((rgb[0] & 0xff) << 16)
|
finalcolor = ((rgb[0] & 0xff) << 16)
|
||||||
|
|
@ -77,7 +77,7 @@ int try_set_texture(t_mapdata *map, char **texture, char *texture_name)
|
||||||
{
|
{
|
||||||
if (*texture != NULL)
|
if (*texture != NULL)
|
||||||
{
|
{
|
||||||
ft_strlcpy(map->error, "Duplicated texture directive", ERRLEN);
|
ft_strlcpy(map->error, EDUPTEX, ERRLEN);
|
||||||
return (2);
|
return (2);
|
||||||
}
|
}
|
||||||
*texture = ft_strdup(texture_name);
|
*texture = ft_strdup(texture_name);
|
||||||
|
|
@ -99,7 +99,7 @@ int set_textures(char *line, t_mapdata *map)
|
||||||
tab = ft_split(line, ' ');
|
tab = ft_split(line, ' ');
|
||||||
if (tab[0][0] == '1')
|
if (tab[0][0] == '1')
|
||||||
return (free_tab(tab), ft_strlcpy(map->error,
|
return (free_tab(tab), ft_strlcpy(map->error,
|
||||||
"Map started before all the textures", ERRLEN), 1);
|
EMAPBFTEX, ERRLEN), 1);
|
||||||
retvalue = 0;
|
retvalue = 0;
|
||||||
if (tab[0] && tab[1])
|
if (tab[0] && tab[1])
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */
|
/* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/08/12 16:14:27 by tchampio ### ########.fr */
|
/* Updated: 2025/08/14 21:24:03 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,15 +34,15 @@ t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y)
|
||||||
t_sprite *sprite;
|
t_sprite *sprite;
|
||||||
|
|
||||||
if (c == 'M')
|
if (c == 'M')
|
||||||
sprite = create_sprite(data, "ressources/box.xpm", x + 0.5, y + 0.5);
|
sprite = create_sprite(data, MYSTERY_TEX, x + 0.5, y + 0.5);
|
||||||
if (c == 'Q')
|
if (c == 'Q')
|
||||||
sprite = create_sprite(data,
|
sprite = create_sprite(data,
|
||||||
"ressources/revive.xpm", x + 0.5, y + 0.5);
|
REV_TEX, x + 0.5, y + 0.5);
|
||||||
if (c == 'J')
|
if (c == 'J')
|
||||||
sprite = create_sprite(data,
|
sprite = create_sprite(data,
|
||||||
"ressources/juggernog.xpm", x + 0.5, y + 0.5);
|
JUGG_TEX, x + 0.5, y + 0.5);
|
||||||
if (c == 'D')
|
if (c == 'D')
|
||||||
sprite = create_sprite(data,
|
sprite = create_sprite(data,
|
||||||
"ressources/doubletap.xpm", x + 0.5, y + 0.5);
|
DBLTAP_TEX, x + 0.5, y + 0.5);
|
||||||
return (sprite);
|
return (sprite);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/08/12 16:13:50 by tchampio ### ########.fr */
|
/* Updated: 2025/08/14 21:45:19 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -58,10 +58,8 @@ void place_base_sprites(t_cub3d_data *data, char **map)
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
int x;
|
int x;
|
||||||
int c;
|
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
c = 0;
|
|
||||||
while (y < data->map->mapheight)
|
while (y < data->map->mapheight)
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
|
|
@ -69,8 +67,11 @@ void place_base_sprites(t_cub3d_data *data, char **map)
|
||||||
{
|
{
|
||||||
if (map[y][x] == 'M' || map[y][x] == 'Q'
|
if (map[y][x] == 'M' || map[y][x] == 'Q'
|
||||||
|| map[y][x] == 'J' || map[y][x] == 'D')
|
|| map[y][x] == 'J' || map[y][x] == 'D')
|
||||||
data->sprite_list[c++] = place_right_sprite(data,
|
{
|
||||||
map[y][x], x, y);
|
if (data->sprite_counter < MAX_SPRITES)
|
||||||
|
data->sprite_list[data->sprite_counter++]
|
||||||
|
= place_right_sprite(data, map[y][x], x, y);
|
||||||
|
}
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
y++;
|
y++;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue