feat: load zombie sprites from map

This commit is contained in:
Khaïs COLIN 2025-08-18 13:21:52 +02:00 committed by Theo Champion
parent 742a014597
commit 1966892c3e
7 changed files with 92 additions and 17 deletions

View file

@ -8,7 +8,7 @@ C 225,30,0
1111111111111111111111111
1000000000110000000000001
1011000001110000000000001
1011000001110000z00000001
10D1000000000000000000001
111111111011000001110M00000000001
100000000011000001110111110111111

70
ressources/zombie.xpm Normal file
View file

@ -0,0 +1,70 @@
/* XPM */
static char *dummy[]={
"64 64 3 1",
"# c #2c2c2c",
"a c #308ca3",
". c #ff00dc",
"................................................................",
"................................................................",
"................................................................",
"................................................................",
"................................................................",
"................................................................",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......######aa########aaaaaa##aa####aa####aaaaaa##########......",
"......######aa########aaaaaa##aa####aa####aaaaaa##########......",
"......########aa########aa####aaaa##aa######aa############......",
"......########aa########aa####aaaa##aa######aa############......",
"......##########aa######aa####aa##aaaa######aa############......",
"......##########aa######aa####aa##aaaa######aa############......",
"......########aa########aa####aa####aa######aa############......",
"......########aa########aa####aa####aa######aa############......",
"......######aa########aaaaaa##aa####aa######aa############......",
"......######aa########aaaaaa##aa####aa######aa############......",
"......####################################################......",
"......####################################################......",
"......################aaaa######aaaa####aa####aa##########......",
"......################aaaa######aaaa####aa####aa##########......",
"......##############aa####aa##aa##aaaa##aa####aa##########......",
"......##############aa####aa##aa##aaaa##aa####aa##########......",
"......##################aa####aaaa##aa##aaaaaaaa##########......",
"......##################aa####aaaa##aa##aaaaaaaa##########......",
"......################aa######aa####aa##aa####aa##########......",
"......################aa######aa####aa##aa####aa##########......",
"......##############aaaaaaaa####aaaa####aa####aa##########......",
"......##############aaaaaaaa####aaaa####aa####aa##########......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"......####################################################......",
"................................................................",
"................................................................",
"................................................................",
"................................................................",
"................................................................",
"................................................................"};

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */
/* Updated: 2025/08/18 18:50:05 by tchampio ### ########.fr */
/* Updated: 2025/08/19 20:06:57 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -39,6 +39,7 @@
# define REV_TEX "ressources/revive.xpm"
# define DBLTAP_TEX "ressources/dbltap.xpm"
# define MYSTERY_TEX "ressources/box.xpm"
# define ZOMBIE_TEX "ressources/zombie.xpm"
# ifdef BONUS
# define COMPILED_TEXT "Compiled with bonuses"

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:18:13 by kcolin #+# #+# */
/* Updated: 2025/08/12 16:18:08 by tchampio ### ########.fr */
/* Updated: 2025/08/18 13:46:15 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,7 +23,7 @@
*/
bool has_forbidden_characters(char *line)
{
static const char *allowedchars = " 10NSEWMQJD\n";
static const char *allowedchars = " 10NSEWMQJDz\n";
size_t strsize;
int i;

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* create_sprite.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */
/* Updated: 2025/08/18 12:55:21 by tchampio ### ########.fr */
/* Created: 2025/08/18 13:52:23 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:55:08 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,7 +16,7 @@
#include "../utils/inits.h"
t_sprite *create_sprite(t_cub3d_data *data, char *texture,
double x, double y)
double x, double y, t_sprite_type type)
{
t_sprite *sprite;
@ -25,7 +25,7 @@ t_sprite *create_sprite(t_cub3d_data *data, char *texture,
return (NULL);
sprite->x = x;
sprite->y = y;
sprite->sprite_type = OTHER;
sprite->sprite_type = type;
sprite->image = load_single_texture(data, texture);
return (sprite);
}
@ -35,15 +35,18 @@ t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x, double y)
t_sprite *sprite;
if (c == 'M')
sprite = create_sprite(data, MYSTERY_TEX, x + 0.5, y + 0.5);
sprite = create_sprite(data, MYSTERY_TEX, x + 0.5, y + 0.5, OTHER);
if (c == 'Q')
sprite = create_sprite(data,
REV_TEX, x + 0.5, y + 0.5);
REV_TEX, x + 0.5, y + 0.5, OTHER);
if (c == 'J')
sprite = create_sprite(data,
JUGG_TEX, x + 0.5, y + 0.5);
JUGG_TEX, x + 0.5, y + 0.5, OTHER);
if (c == 'D')
sprite = create_sprite(data,
DBLTAP_TEX, x + 0.5, y + 0.5);
DBLTAP_TEX, x + 0.5, y + 0.5, OTHER);
if (c == 'z')
sprite = create_sprite(data,
ZOMBIE_TEX, x + 0.5, y + 0.5, ZOMBIE);
return (sprite);
}

View file

@ -6,12 +6,13 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:22:50 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:25:07 by kcolin ### ########.fr */
/* Updated: 2025/08/18 13:57:39 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "move_sprites.h"
#include "sprite.h"
#include "../../libft/includes/libft.h"
void move_sprites(t_cub3d_data *data)
{
@ -21,7 +22,7 @@ void move_sprites(t_cub3d_data *data)
while (i < data->sprite_counter)
{
if (data->sprite_list[i]->sprite_type == ZOMBIE)
data->sprite_list[i]->sprite_pos_x += MOVEMENT_SPEED * data->delta;
data->sprite_list[i]->x += MOVEMENT_SPEED * data->delta;
i++;
}
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:43:05 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:13:22 by tchampio ### ########.fr */
/* Updated: 2025/08/18 13:52:41 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -65,7 +65,7 @@ void place_base_sprites(t_cub3d_data *data, char **map)
x = 0;
while (x < (int)ft_strlen(map[y]))
{
if (ft_strchr("MQJD", map[y][x]))
if (ft_strchr("MQJDz", map[y][x]))
{
if (data->sprite_counter < MAX_SPRITES)
data->sprite_list[data->sprite_counter++]