Compare commits

...

27 commits

Author SHA1 Message Date
8445f240a2
feat: basic zombie movement (very bad) 2025-08-18 13:42:47 +02:00
Theo Champion
2fc8cf21a1 fix: fixed segfault when compiling for mandatory part. Fixed bad check 2025-08-18 13:40:01 +02:00
92770f44f8 fix: segfault & leak with missing sprite image 2025-08-18 13:18:12 +02:00
Theo Champion
4568124d3f fix: git merge conflict again 2025-08-18 13:13:42 +02:00
Theo Champion
5c7cc77419 dev: improved how sprites are detected in maps 2025-08-18 13:07:08 +02:00
Theo Champion
ef7a6c27a4 fix: Removed git conflict marker 2025-08-18 13:04:13 +02:00
Theo Champion
541bc9ccf8 dev: Added sprite types and gave 'base' sprites their types 2025-08-14 21:47:21 +02:00
Theo Champion
0ac6ee9394 norme: Fixed little oopsie 2025-08-14 21:47:00 +02:00
Theo Champion
3511b6aaf8 norme: Fixed little oopsie 2025-08-14 21:45:39 +02:00
Theo Champion
01f0ac21df feat: Made a little sprite interaction for perk type sprites
It's more for the sake of the demo but it shows we can make interactions
with sprites. Although it's badly integrated.
2025-08-14 21:41:35 +02:00
Theo Champion
ee329812fd dev: Added sprite types and gave 'base' sprites their types 2025-08-14 21:41:33 +02:00
Theo Champion
0d6cc4063a dev: changed the c var in place_base_sprites to a counter in data struct 2025-08-14 21:38:49 +02:00
Theo Champion
4a70e44697 fix: Added a check for the sprites, to avoid segfaults and/or invalid writes 2025-08-14 21:27:53 +02:00
Theo Champion
94075506f6 fix: Transferred sprite pathes to constants 2025-08-14 21:25:03 +02:00
Theo Champion
412dc89336 fix: Transferred trailing magic error messages as consts 2025-08-14 19:52:34 +02:00
Theo Champion
db66decbf8 fix: removed trailing BONUS definition 2025-08-12 16:18:34 +02:00
Theo Champion
dafe94804e norme: normed everything 2025-08-12 16:15:02 +02:00
Theo Champion
00e8a73d14 dev: improved sprites by creating a create_sprite function 2025-08-12 15:57:27 +02:00
Theo Champion
09ff569a31 feat: made sprites be placed in map file 2025-08-12 15:41:42 +02:00
Theo Champion
04705fe9e5 feat: added temp perk textures and placed perks in testmap_2 2025-08-12 15:40:29 +02:00
Theo Champion
41437ec215 dev: Changed magic values for error messages to constants 2025-08-12 14:49:44 +02:00
Theo Champion
2eb1d635d4 norme: Fixed little norm error 2025-08-12 14:49:11 +02:00
Theo Champion
9988b09e91 dev: Changed allowed characters to comply more about the current state of the game 2025-08-12 14:49:11 +02:00
Theo Champion
f1697a6c73 dev: Improved memory management of sprites 2025-08-12 14:49:11 +02:00
Theo Champion
3230a60c9f fix: Fixed memory leak 2025-08-12 14:49:09 +02:00
Theo Champion
aae5e42b13 fix(main): Bumped calloc for sprites from 3 to MAX_SPRITES and moved it 2025-08-12 14:48:41 +02:00
Theo Champion
b7d56363ab removal(main): Removed sprites initialization in main function 2025-08-12 14:48:15 +02:00
25 changed files with 580 additions and 89 deletions

View file

@ -4,13 +4,14 @@ CC = cc
# https://github.com/google/sanitizers/wiki/AddressSanitizer # https://github.com/google/sanitizers/wiki/AddressSanitizer
SANITIZERS = -fsanitize=address,undefined -fno-omit-frame-pointer SANITIZERS = -fsanitize=address,undefined -fno-omit-frame-pointer
ifeq ($(CFLAGS),) ifeq ($(CFLAGS),)
CFLAGS = -Wall -Wextra -Werror -g -O3 -ffast-math CFLAGS = -Wall -Wextra -Werror -g -O2
endif endif
IFLAGS = -I./mlx -I./libft IFLAGS = -I./mlx -I./libft
SOURCEFILES = \ SOURCEFILES = \
src/utils/inits.c \ src/utils/inits.c \
src/utils/time.c \ src/utils/time.c \
src/utils/destroy_utils.c \
src/draw/draw_map.c \ src/draw/draw_map.c \
src/draw/drawutils.c \ src/draw/drawutils.c \
src/main.c \ src/main.c \
@ -29,6 +30,8 @@ SOURCEFILES = \
src/raycast/ray.c \ src/raycast/ray.c \
src/raycast/walls.c \ src/raycast/walls.c \
src/renderer/render.c \ src/renderer/render.c \
src/sprites/create_sprite.c \
src/sprites/move_sprites.c \
src/sprites/sort_sprites.c \ src/sprites/sort_sprites.c \
src/sprites/sprite_caster.c \ src/sprites/sprite_caster.c \

78
ressources/doubletap.xpm Normal file
View file

@ -0,0 +1,78 @@
/* XPM */
static char * doubletap_xpm[] = {
"64 64 11 1",
" c #FF00DC",
". c #BFC7D5",
"+ c #FFFFFF",
"@ c #D66B1B",
"# c #F28A3C",
"$ c #864B1C",
"% c #FDE9D6",
"& c #F8CBAA",
"* c #F3B98B",
"= c #F0AA75",
"- c #EE9A5C",
" ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ++@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@@###@@@@++ ",
" ++@@@@@@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@++ ",
" ++@@++++@@@@@###@@@@@###@@@@@###@@@@@###@@@@++ ",
" ++@@##+##@@@#####@@@#####@@@#####@@@#####@@@++ ",
" ++###@+###@##@@###@##@@###@##@@###@##@@@##@#++ ",
" ++#+@@+@#####@@@#####@@@#####@@@#####@@@####++ ",
" ++#@++@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@@@##++ ",
" ++@@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@++ ",
" ++##+@+@@###@@@@@###@@@$###$@@@@@###@@@@@###++ ",
" ++#+@@++#####@@@#####@$#####$@@@#####@@@####++ ",
" ++@+##++#@@###@##@@########$$#@##@@###@###@@++ ",
" ++@+##++#@@@#####@@@$#####$$$$###@@@#####@@@++ ",
" ++@@++#@@@@@@##@@@@$######$$$$#@@@@@@###@@@@++ ",
" ++@@@@@@@@@@@@#@@@@$######$$$@#@@@@@@@#@@@@@++ ",
" ++@++++++@@@@##@@@@########$$##@@@@@@###@@@@++ ",
" ++@@+#+##@@@#$$$$@$########$#$$$$@@@#####@@@++ ",
" ++@#++###@@#$$$$$$$########$$$$$$$@###@###@@++ ",
" ++##+@++###$$$$$$$##########$$$$$$$##@@@####++ ",
" ++##+@++@##$$$$$$$##########$$$$$$$#@@@@@###++ ",
" ++@@@@@@@@$$$$$$$############$$$$$$$@@@@@@#@++ ",
" ++#+++++@#$$$$@$$############$$@$$$$@@@@@@##++ ",
" ++##+@@@##$$$@@$$####%%%%####$$@#$$$#@@@####++ ",
" ++##+++##$#$#@@$###%%%%%%%%###$###$#$@@@##@#++ ",
" ++@@+####$########$$%%%%%%$$########$####@@@++ ",
" ++@@+#++@@$#$####$$$$%%%%$$$$###@$#$@###@@@@++ ",
" ++@@@@@@@@@@@@###&$$$$%%$$$$%##@@@@@@@#@@@@@++ ",
" ++@++++@@@@@@####&%$$%%%%$$%%##@@@@@@###@@@@++ ",
" ++@@+##+#@@@###$&&%%%#%%#%%%%%$##@@@##++#+@@++ ",
" ++@#+#++#@@###@&&#%%%%##%%%%#%%##@@###@+#+@@++ ",
" ++##+@+@#####@@&&############%%@#####@++#+##++ ",
" ++##+@++@###@@@$&%##########%%$@@###@@+@@+##++ ",
" ++@@@@@@@@#@@@@@@&%##%%%%##%%@@@@@#@@@@++++@++ ",
" ++#@@@@@@##@@@@@@&&########%%@@@@##@@@@@@@##++ ",
" ++##@@@@#####@@$$&&&%####%%%&$$@#####@++#+##++ ",
" ++###@@###@##$$***&%%%%%%%%&***$$#@##@@@#+@#++ ",
" ++@@#####@@$***=====&&&&&&==&==**=$@###+++@@++ ",
" ++@@####@@$***===&&=**=&&*====&==**$@###@+@@++ ",
" ++@@@@@@@$**====&=***===&=**====&==*$@+++++@++ ",
" ++@@@##@@**====&=***=======**======**###@@@@++ ",
" ++@@#####*---====**=-----==**====---=#++#+@@++ ",
" ++@######*----&=***-------=***==----=#++#+@@++ ",
" ++##@@@@#$---$@***=---$$---=***@$--$#@@@++##++ ",
" ++##@@@@@##$$@@***---$@@$--=***@@$$$$@@+@+##++ ",
" ++@@@@@@@##$@@@***---@@@@---***@@@$$$++++++@++ ",
" ++#@@@@@@$$@@@@***--$@@@@$--***@@##$@@@@@@##++ ",
" ++##@@@@@###@@@**--$@@@@@#$--**@@###@@@@++##++ ",
" ++###@@######@@$$-$##@@####$$########@++##+#++ ",
" ++########@###@$$$@###@###@#$#####@###++##+#++ ",
" ++@@#####@@@###$$@@@#####@@@#$$##@@@##++#@+@++ ",
" ++@@####@@@@@###@@@@@###@@@@@###@@@@@##+@+@@++ ",
" ++@@@@@@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@++ ",
" ++@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@@###++@@++ ",
" ++@@#####@@@#####@@@#####@@@#####@@@###+#@+@++ ",
" ++@######@@###@##@@###@##@@###@##@@###@+##@@++ ",
" ++##@@@@#####@@@#####@@@#####@@@#####@@+####++ ",
" ++##@@@@@###@@@@@###@@@@@###@@@@@###@@++++##++ ",
" ++@@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@++ ",
" ++#@@@@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@@@##++ ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" "};

View file

@ -1,22 +1,22 @@
NO ./path_to_the_north_texture NO ressources/north.xpm
SO ./path_to_the_south_texture SO ressources/south.xpm
WE ./path_to_the_west_texture WE ressources/west.xpm
EA ./path_to_the_east_texture EA ressources/east.xpm
F 220,100,0 F 220,100,0
C 225,30,0 C 225,30,0
1111111111111111111111111 1111111111111111111111111
1000000000110000000000001 1000000000110000000000001
1011000001110000001000001 1011000001110000000000001
1001000000000000010000001 10D1000000000000000000001
111111111011000001110000100000001 111111111011000001110M00000000001
100000000011000001110111110111111 100000000011000001110111110111111
11110111111111011100000010001 11110111111111011100000010001
11110111111111011101010010001 11110111111111011101010010001
11000000110101011100000010001 11000000110101011100000010001
10000000000000001100000010001 100000000000000011J0000010001
10000000000000001101010010001 10000000000000001101010010001
11000001110101011111011110N0111 11Q00001110101011111011110N0111
11110111 1110101 101111010001 11110111 1110101 101111010001
11111111 1111111 111111111111 11111111 1111111 111111111111

78
ressources/juggernog.xpm Normal file
View file

@ -0,0 +1,78 @@
/* XPM */
static char * juggernog_xpm[] = {
"64 64 11 1",
" c #FF00DC",
". c #BFC7D5",
"+ c #FFFFFF",
"@ c #EC2D33",
"# c #FF6368",
"$ c #A61A1F",
"% c #FDE8E8",
"& c #FDD3D5",
"* c #FDBDBF",
"= c #FDA0A5",
"- c #FD8086",
" ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ++@@@@####@@@@@###@@@@@###@@@@@###@@@@@###@@++ ",
" ++@@@@#####@@@#####@@@#####@@@#####@@@#####@++ ",
" ++##++++####@#######@#######@#######@#######++ ",
" ++@##@+##@@##@@##@@##@@##@@##@@##@@##@@@##@@++ ",
" ++@@@@+@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@++ ",
" ++@+@@+@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@++ ",
" ++@#++@@@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@@@++ ",
" ++####@@@@@###@@@@@###@@@@@###@@@@@###@@@@@#++ ",
" ++##+#+@@######@@######$###$###@@#######@@##++ ",
" ++#+##++@#######@#####$#####$###@#######@###++ ",
" ++@+@@++#@@@#@@@#@@@#######$$@@@#@@@#@@@#@@@++ ",
" ++@+@@++#@@@@@@@#@@@$#####$$$$@@#@@@@@@@#@@@++ ",
" ++@@++@@#@@@@@@@#@@$######$$$$@@#@@@@@@@#@@@++ ",
" ++@@@@@##@@@@@@##@@$######$$$@@##@@@@@@@##@@++ ",
" ++@++++++#@@@@@###@########$$@@###@@@@@###@@++ ",
" ++#@+#+####@@$$$$#$########$@$$$$##@@#######++ ",
" ++##++######$$$$$$$########$$$$$$$##@#######++ ",
" ++@@+@++#@@$$$$$$$##########$$$$$$$@#@@@#@@@++ ",
" ++@@+@++@@@$$$$$$$##########$$$$$$$@#@@@@@@@++ ",
" ++@@@@@@@@$$$$$$$############$$$$$$$#@@@@@@@++ ",
" ++@+++++@@$$$$@$$############$$@$$$$#@@@@@@@++ ",
" ++##+#@@@@$$$##$$####%%%%####$$@@$$$###@@@##++ ",
" ++##+++@@$#$###$###%%%%%%%%###$@@#$#$###@@##++ ",
" ++@#+@@##$###@@###$$%%%%%%$$########$@@@##@@++ ",
" ++@@+@++#@$#$@@##$$$$%%%%$$$$##@#$#$#@@@#@@@++ ",
" ++@@@@@@#@@@@@@##&$$$$%%$$$$%##@#@@@@@@@#@@@++ ",
" ++@++++@#@@@@@@##&%$$%%%%$$%%##@#@@@@@@@#@@@++ ",
" ++@@+@#+##@@@@@$&&%%%#%%#%%%%%$###@@@@++#+@@++ ",
" ++@@+@++###@@@#&&#%%%%##%%%%#%%####@@@#+#+#@++ ",
" ++##+#+#####@##&&############%%#####@#++#+##++ ",
" ++@#+@++#@@##@@$&%##########%%$##@@##@+@#+@@++ ",
" ++@@@@@@@@@@#@@@@&%##%%%%##%%@@@@@@@#@@++++@++ ",
" ++@@@@@@@@@@#@@@@&&########%%@@@@@@@#@@@@@@@++ ",
" ++@##@@@@@@##@@$$&&&%####%%%&$$@@@@##@++@+@@++ ",
" ++####@@@@@##$$***&%%%%%%%%&***$$@@###@@@+@#++ ",
" ++#####@@##$***=====&&&&&&==&==**=$####+++##++ ",
" ++######@#$***===&&=**=&&*====&==**$####@+##++ ",
" ++@@@@@@#$**====&=***===&=**====&==*$@+++++@++ ",
" ++@@@@@@#**====&=***=======**======**@@@#@@@++ ",
" ++@@@@@@#*---====**=-----==**====---=@++#+@@++ ",
" ++@@@@@##*----&=***-------=***==----=@++#+@@++ ",
" ++@@@@###$---$#***=---$$---=***#$--$@@##++#@++ ",
" ++#@@######$$##***---$##$--=***##$$$$##+#+##++ ",
" ++@##@@####$#@@***---@@##---***##@$$$++++++@++ ",
" ++@@@@@@#$$@#@@***--$@@@#$--***@#@@$#@@@#@@@++ ",
" ++@@@@@@@@@@#@@**--$#@@@@@$--**@@@@@#@@@++@@++ ",
" ++@@@@@@@@@@#@@$$-$@#@@@@@@$$##@@@@@#@++@@+@++ ",
" ++@##@@@@@@##@@$$$@##@@@@@@#$##@@@@##@++@@+@++ ",
" ++####@@@@#####$$@#####@@@###$$@@@####++@@+#++ ",
" ++#####@@######@@######@@######@@######+@+##++ ",
" ++@##@@##@@##@@##@@##@@##@@##@@##@@##@@@##@@++ ",
" ++@@@@@@#@@@#@@@#@@@#@@@#@@@#@@@#@@@#@@@++@@++ ",
" ++@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@+#@+@++ ",
" ++@@@@@@#@@@@@@@#@@@@@@@#@@@@@@@#@@@@@@+#@@@++ ",
" ++@@@@####@@@@@###@@@@@###@@@@@###@@@@@+##@@++ ",
" ++@@@@#####@@@#####@@@#####@@@#####@@@++++#@++ ",
" ++##########@#######@#######@#######@#######++ ",
" ++@##@@##@@##@@##@@##@@##@@##@@##@@##@@@##@@++ ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" "};

78
ressources/revive.xpm Normal file
View file

@ -0,0 +1,78 @@
/* XPM */
static char * revive_xpm[] = {
"64 64 11 1",
" c #FF00DC",
". c #BFC7D5",
"+ c #FFFFFF",
"@ c #7A73BB",
"# c #5E579C",
"$ c #403995",
"% c #F9F7FF",
"& c #DDDAFB",
"* c #A9A6C9",
"= c #8D88BA",
"- c #5B54A0",
" ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ++@@###@@@@@###@@@@@###@@@@@###@@@@@####@@@@++ ",
" ++@#####@@@#####@@@#####@@@#####@@@@####@@@@++ ",
" ++##++++#@#######@#######@#######@##########++ ",
" ++####+##@#######@#######@#######@##########++ ",
" ++@@##+@@@@@@##@@@@@@##@@@@@@##@@@@@@##@@@@@++ ",
" ++@+##+@@#@@###@@#@@###@@#@@###@@#@@####@@@@++ ",
" ++#@++@@###@@@@@###@@@@@###@@@@@####@@@@####++ ",
" ++##@@@#####@@@#####@@@#####@@@#####@@@@####++ ",
" ++##+@+######@#######@#$@@@$#@##############++ ",
" ++#+#@++#####@#######@$@@@@@$@##############++ ",
" ++@+@@++##@@@@@@@##@@@@@@@@$$@@@@##@@@@@@##@++ ",
" ++#+@#++###@@#@@###@$@@@@@$$$$@@####@@@@####++ ",
" ++@@++#@@@@@###@@@@$@@@@@@$$$$#@@@@@####@@@@++ ",
" ++@#####@@@#####@@@$@@@@@@$$$###@@@@####@@@@++ ",
" ++#+++++@@#######@@@@@@@@@@$$####@@######@@#++ ",
" ++##+#+##@###$$$$@$@@@@@@@@$#$$$$@##########++ ",
" ++##++##@@##$$$$$$$@@@@@@@@$$$$$$$@##@@##@@#++ ",
" ++@@+#++@#@$$$$$$$@@@@@@@@@@$$$$$$$@####@@@@++ ",
" ++@@+@++##$$$$$$$$@@@@@@@@@@$$$$$$$$@@@@@##@++ ",
" ++##@@@###$$$$$$$@@@@@@@@@@@@$$$$$$$@@@@####++ ",
" ++#+++++##$$$$@$$@@@@@@@@@@@@$$#$$$$#@@#####++ ",
" ++##+@####$$$@#$$@@@@%%%%@@@@$$##$$$########++ ",
" ++##+++#@$@$@@@$@@@%%%%%%%%@@@$##@$@$@@##@@#++ ",
" ++#@+#@@#$@@@#@@@@$$%%%%%%$$@@@@#@@@$@@@####++ ",
" ++@@+#++@@@@$##@@$$$$%%%%$$$$@@@@$@@@##@@@@@++ ",
" ++@#####@@@####@@&$$$$%%$$$$%@@#@@@@####@@@@++ ",
" ++#++++#@@#####@@&%$$%%%%$$%%@@##@@######@@#++ ",
" ++##+##+#@#####$&&%%%@%%@%%%%%$##@####++#+##++ ",
" ++##+#++@@####@&&@%%%%@@%%%%@%%##@@##@@+#+@#++ ",
" ++@@+#+@@#@@###&&@@@@@@@@@@@@%%@@#@@##++@+@@++ ",
" ++@@+@++##@@@@@$&%@@@@@@@@@@%%$@@##@@@+@@+#@++ ",
" ++##@@@#####@@@##&%@@%%%%@@%%@@#####@@@++++#++ ",
" ++##@@#######@@##&&@@@@@@@@%%@@######@@#####++ ",
" ++###@#######@#$$&&&%@@@@%%%&$$#######++#+##++ ",
" ++##@@##@####$$***&%%%%%%%%&***$$#@##@@##+@#++ ",
" ++#@@#@@##$$***=====&&&&&&==&==**=$$@@@+++##++ ",
" ++@@##@@@@****===&&=**=&&*====&==**=@##@@+@@++ ",
" ++@#####@$**====&=***===&=**====&==*$#+++++@++ ",
" ++######$**====&=***=======**=======*$###@@#++ ",
" ++######$*---====**=-----==**====---=$++#+##++ ",
" ++##@###$*----&=***-------=***==----=$++#+@#++ ",
" ++@@###@@$---$#***=---$$---=***@$---####++@@++ ",
" ++@@@@@@$@-$$@@***---$@@$--=***@@$$$$@@+@+#@++ ",
" ++##@@@#$@@$@@@***---@@##---***###$$$@+++++#++ ",
" ++##@@###$$##@@***--$@@##$--***####$#@@#####++ ",
" ++###@#######@#**--$#@####$--**#########++##++ ",
" ++##@@##@####@@$$-$##@@###@$$@@###@##@++#@+#++ ",
" ++@@@@@@##@@@@@$$$#@@@@@@##@$@@@@##@@@++@#+@++ ",
" ++@@##@@@@@@@##$$@@@@##@@@@@@$$@@@@@@#++@@+@++ ",
" ++@@###@@@@@###@@@@@###@@@@@###@@@@@###+@+@@++ ",
" ++######@@#######@@######@@######@@######@@#++ ",
" ++#######@#######@#######@#######@######++##++ ",
" ++##@###@@####@##@@###@##@@###@##@@##@@+#@+#++ ",
" ++@@##@@@@@@@##@@@@@@##@@@@@@##@@@@@@##+@@@@++ ",
" ++@@@@@@##@@@@@@@##@@@@@@##@@@@@@##@@@@+@##@++ ",
" ++#@@@@@###@@@@@###@@@@@###@@@@@####@@++++##++ ",
" ++##@@#######@@######@@######@@######@@#####++ ",
" ++###@#######@#######@#######@##############++ ",
" .++++++++++++++++++++++++++++++++++++++++++++. ",
" ..++++++++++++++++++++++++++++++++++++++++++.. ",
" "};

View file

@ -6,32 +6,58 @@
/* 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:32:47 by kcolin ### ########.fr */ /* Updated: 2025/08/14 21:23:25 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef CONSTS_H #ifndef CONSTS_H
# define CONSTS_H # define CONSTS_H
// Window
# define WIDTH 800 # define WIDTH 800
# define HEIGHT 600 # define HEIGHT 600
// Texture size
# define SIZE 64 # define SIZE 64
# define TEXTURE_SIZE 64
// minimap handling
# define MAP_SIZE 10 # define MAP_SIZE 10
# define PLAYER_SIZE 6 # define PLAYER_SIZE 6
# define RESSOURCE_DIR "ressources" # define RESSOURCE_DIR "ressources"
// movement handling
# define MOVEMENT_SPEED 0.000005 # define MOVEMENT_SPEED 0.000005
# define MOVEMENT_STEP 0.1 # define MOVEMENT_STEP 0.1
# define ROTATION_SPEED 0.000002 # define ROTATION_SPEED 0.000002
# define PLANE_VALUE 0.6 # define PLANE_VALUE 0.6
# define TEXTURE_SIZE 64
// Sprite consts
# define SPRITE_TRANPARENCY_COLOR 0xff00dc # define SPRITE_TRANPARENCY_COLOR 0xff00dc
// 4 static ones, 3 perks, the box and 25 zombies at max # define MAX_SPRITES 30
# define MAX_SPRITES 30 // FIXME: Change to 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"
# else # else
# define COMPILED_TEXT " " # define COMPILED_TEXT " "
# endif # endif
// Error messages
# define ENOCUB "Not a .cub file"
# define EOPEN "Can't open file"
# define EMALMAP "Map is malformed (invalid chars or missing walls)"
# define ENOPLAYER "No player"
# 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

View file

@ -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/07 11:28:49 by tchampio ### ########.fr */ /* Updated: 2025/08/14 21:36:15 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,6 +20,9 @@
# include "utils/keypresses.h" # include "utils/keypresses.h"
# include "consts.h" # include "consts.h"
// FIXME: Delete this line to let it compile for bonus part
# define BONUS 1
// the 4 static sprites are some of the perks and the mystery box // the 4 static sprites are some of the perks and the mystery box
typedef struct s_cub3d_data typedef struct s_cub3d_data
{ {
@ -37,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];

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/08/12 14:23:27 by kcolin ### ########.fr */ /* Updated: 2025/08/18 13:23:26 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,6 +31,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include "utils/time.h" #include "utils/time.h"
#include "sprites/move_sprites.h"
int game_loop(t_cub3d_data *data) int game_loop(t_cub3d_data *data)
{ {
@ -41,6 +42,7 @@ int game_loop(t_cub3d_data *data)
data->last_tick = get_milliseconds(); data->last_tick = get_milliseconds();
reset_matrix(data); reset_matrix(data);
move_player(data); move_player(data);
move_sprites(data);
raycaster(data, &ray); raycaster(data, &ray);
sprite_caster(data); sprite_caster(data);
matrix_to_image(data); matrix_to_image(data);
@ -64,19 +66,6 @@ int main(int argc, char **argv)
if (argc < 2) if (argc < 2)
return (ft_printf("Error: Missing cub3d file\n"), 1); return (ft_printf("Error: Missing cub3d file\n"), 1);
init_cub3d_data(&data, argv); init_cub3d_data(&data, argv);
// FIXME: Delete this whole piece of code when we will init sprites from
// map
data.sprite_list = ft_calloc(sizeof(t_sprite *), 3);
data.sprite_list[0] = ft_calloc(sizeof(t_sprite), 1);
data.sprite_list[1] = ft_calloc(sizeof(t_sprite), 1);
data.sprite_list[0]->x = data.map->startx + 1;
data.sprite_list[0]->y = data.map->starty;
data.sprite_list[0]->image = load_single_texture(&data,
"ressources/box.xpm");
data.sprite_list[1]->x = data.map->startx;
data.sprite_list[1]->y = data.map->starty - 2;
data.sprite_list[1]->image = load_single_texture(&data,
"ressources/test_holed.xpm");
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data); mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask,
keyrelease_handler, &data); keyrelease_handler, &data);

View file

@ -6,19 +6,24 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:18:13 by kcolin #+# #+# */ /* Created: 2025/07/17 14:18:13 by kcolin #+# #+# */
/* Updated: 2025/07/17 14:47:34 by kcolin ### ########.fr */ /* Updated: 2025/08/12 16:18:08 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../libft/includes/libft.h" #include "../../libft/includes/libft.h"
// TODO: use a #define for allowedchars, to prevent needless repetition
#ifdef BONUS #ifdef BONUS
/*
* 10NSEW are from mandatory part
* M - Mystery box
* Q - Quick Revive perk
* J - Juggernog perk
* D - Double tap perk
*/
bool has_forbidden_characters(char *line) bool has_forbidden_characters(char *line)
{ {
static const char *allowedchars = " 10NSEWDdZzsM\n"; static const char *allowedchars = " 10NSEWMQJD\n";
size_t strsize; size_t strsize;
int i; int i;

View file

@ -6,12 +6,13 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */ /* Created: 2025/06/06 17:54:42 by tchampio #+# #+# */
/* Updated: 2025/07/29 14:43:32 by tchampio ### ########.fr */ /* Updated: 2025/08/12 13:43:42 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../../libft/includes/libft.h" #include "../../libft/includes/libft.h"
#include "../utils/colors.h" #include "../utils/colors.h"
#include "../consts.h"
#include "mapdata.h" #include "mapdata.h"
#include "populate_map.h" #include "populate_map.h"
#include "checkers.h" #include "checkers.h"
@ -61,10 +62,10 @@ bool check_cubfile(char *file, t_mapdata *map)
int fd; int fd;
if (!check_filename(map, file)) if (!check_filename(map, file))
return (ft_strlcpy(map->error, "Not a .cub file", ERRLEN), false); return (ft_strlcpy(map->error, ENOCUB, ERRLEN), false);
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (fd < 0) if (fd < 0)
return (ft_strlcpy(map->error, "Can't open file", ERRLEN), false); return (ft_strlcpy(map->error, EOPEN, ERRLEN), false);
if (add_textures(fd, map) != 0) if (add_textures(fd, map) != 0)
return (close(fd), false); return (close(fd), false);
if (map->error[0]) if (map->error[0])
@ -72,15 +73,13 @@ bool check_cubfile(char *file, t_mapdata *map)
if (!populate_maps(map, fd)) if (!populate_maps(map, fd))
return (close(fd), false); return (close(fd), false);
if (!check_walls(map)) if (!check_walls(map))
return (close(fd), ft_strlcpy(map->error, return (close(fd), ft_strlcpy(map->error, EMALMAP, ERRLEN), false);
"Map is malformed (invalid chars or missing walls)", ERRLEN),
false);
if (!check_bare_minimum(map)) if (!check_bare_minimum(map))
return (close(fd), ft_strlcpy(map->error, "No player", ERRLEN), false); return (close(fd), ft_strlcpy(map->error, ENOPLAYER, ERRLEN), false);
map->isvalid = true; map->isvalid = true;
flood_fill(map, map->startx, map->starty); flood_fill(map, map->startx, map->starty);
if (!map->isvalid) if (!map->isvalid)
return (close(fd), ft_strlcpy(map->error, "Holes in map", ERRLEN), return (close(fd), ft_strlcpy(map->error, EHOLES, ERRLEN),
false); false);
return (true); return (true);
} }

View file

@ -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')

View file

@ -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])
{ {

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */ /* Created: 2025/07/17 15:51:29 by kcolin #+# #+# */
/* Updated: 2025/07/29 13:28:08 by tchampio ### ########.fr */ /* Updated: 2025/08/13 15:31:17 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_sprite.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/12 15:43:19 by tchampio #+# #+# */
/* Updated: 2025/08/18 12:55:21 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#include "sprite.h"
#include "../../libft/includes/libft.h"
#include "../cub3d_data.h"
#include "../utils/inits.h"
t_sprite *create_sprite(t_cub3d_data *data, char *texture,
double x, double y)
{
t_sprite *sprite;
sprite = ft_calloc(sizeof(t_sprite), 1);
if (!sprite)
return (NULL);
sprite->x = x;
sprite->y = y;
sprite->sprite_type = OTHER;
sprite->image = load_single_texture(data, texture);
return (sprite);
}
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);
if (c == 'Q')
sprite = create_sprite(data,
REV_TEX, x + 0.5, y + 0.5);
if (c == 'J')
sprite = create_sprite(data,
JUGG_TEX, x + 0.5, y + 0.5);
if (c == 'D')
sprite = create_sprite(data,
DBLTAP_TEX, x + 0.5, y + 0.5);
return (sprite);
}

View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_sprite.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/12 15:49:25 by tchampio #+# #+# */
/* Updated: 2025/08/12 16:13:02 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CREATE_SPRITE_H
# define CREATE_SPRITE_H
# include "../cub3d_data.h"
t_sprite *create_sprite(t_cub3d_data *data,
char *filename, double x, double y);
t_sprite *place_right_sprite(t_cub3d_data *data, char c, double x,
double y);
#endif // CREATE_SPRITE_H

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_sprites.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:22:50 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:25:07 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "move_sprites.h"
#include "sprite.h"
void move_sprites(t_cub3d_data *data)
{
int i;
i = 0;
while (i < data->sprite_counter)
{
if (data->sprite_list[i]->sprite_type == ZOMBIE)
data->sprite_list[i]->sprite_pos_x += MOVEMENT_SPEED * data->delta;
i++;
}
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_sprites.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:22:06 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:22:40 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MOVE_SPRITES_H
# define MOVE_SPRITES_H
# include "../cub3d_data.h"
void move_sprites(t_cub3d_data *data);
#endif // MOVE_SPRITES_H

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 12:59:44 by tchampio #+# #+# */ /* Created: 2025/08/05 12:59:44 by tchampio #+# #+# */
/* Updated: 2025/08/06 14:41:17 by tchampio ### ########.fr */ /* Updated: 2025/08/13 14:44:02 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,6 +15,14 @@
# include "../draw/img_data.h" # include "../draw/img_data.h"
typedef enum e_sprite_type
{
ZOMBIE,
PERK,
BOX,
OTHER
} t_sprite_type;
/* /*
* x - real position for the sprite * x - real position for the sprite
* y - real position for the sprite * y - real position for the sprite
@ -36,23 +44,24 @@
*/ */
typedef struct s_sprite typedef struct s_sprite
{ {
double x; double x;
double y; double y;
t_img_data *image; t_img_data *image;
int img_width; int img_width;
int img_height; int img_height;
double sprite_pos_x; double sprite_pos_x;
double sprite_pos_y; double sprite_pos_y;
double inv_det; double inv_det;
double transform_x; double transform_x;
double transform_y; double transform_y;
int sprite_screen_x; int sprite_screen_x;
int sprite_height; int sprite_height;
int sprite_draw_start_y; int sprite_draw_start_y;
int sprite_draw_end_y; int sprite_draw_end_y;
int sprite_width; int sprite_width;
int sprite_draw_start_x; int sprite_draw_start_x;
int sprite_draw_end_x; int sprite_draw_end_x;
t_sprite_type sprite_type;
} t_sprite; } t_sprite;
#endif // SPRITE_H #endif // SPRITE_H

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/05 15:51:01 by tchampio #+# #+# */ /* Created: 2025/08/05 15:51:01 by tchampio #+# #+# */
/* Updated: 2025/08/07 16:57:29 by tchampio ### ########.fr */ /* Updated: 2025/08/18 13:39:26 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,8 +15,8 @@
#include "../renderer/render.h" #include "../renderer/render.h"
#include "sort_sprites.h" #include "sort_sprites.h"
#include <math.h> #include <math.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../../libft/includes/libft.h"
static void calculate_pos_and_transform(t_cub3d_data *data, t_sprite *sprite, static void calculate_pos_and_transform(t_cub3d_data *data, t_sprite *sprite,
int i) int i)
@ -106,9 +106,20 @@ void sprite_caster(t_cub3d_data *data)
{ {
int i; int i;
if (!data->sprite_list) if (!data->sprite_list || !data->sprite_list[0])
return ; return ;
sort_sprites(data->sprite_order, data->sprite_distances, data); sort_sprites(data->sprite_order, data->sprite_distances, data);
if (data->sprite_distances[3] <= 1.5)
{
if (data->sprite_list[data->sprite_order[3]]->sprite_type == PERK)
{
if (data->keypresses.is_f_pressed)
{
data->keypresses.is_f_pressed = false;
ft_printf("🎵You need a little revive🎵\n");
}
}
}
i = 0; i = 0;
while (data->sprite_list[i] && i < MAX_SPRITES) while (data->sprite_list[i] && i < MAX_SPRITES)
{ {

47
src/utils/destroy_utils.c Normal file
View file

@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* destroy_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:05:31 by kcolin #+# #+# */
/* Updated: 2025/08/18 13:05:31 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d_data.h"
#include "../../mlx/mlx.h"
#include <stdlib.h>
void destroy_textures(t_cub3d_data *data)
{
if (data->no_texture)
mlx_destroy_image(data->mlx, data->no_texture->img);
free(data->no_texture);
if (data->so_texture)
mlx_destroy_image(data->mlx, data->so_texture->img);
free(data->so_texture);
if (data->ea_texture)
mlx_destroy_image(data->mlx, data->ea_texture->img);
free(data->ea_texture);
if (data->we_texture)
mlx_destroy_image(data->mlx, data->we_texture->img);
free(data->we_texture);
}
void destroy_sprites(t_cub3d_data *data)
{
int sprite;
sprite = 0;
if (data->sprite_list == NULL)
return ;
while (data->sprite_list[sprite] && sprite < MAX_SPRITES)
{
mlx_destroy_image(data->mlx, data->sprite_list[sprite]->image->img);
free(data->sprite_list[sprite]->image);
free(data->sprite_list[sprite]);
sprite++;
}
}

21
src/utils/destroy_utils.h Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* destroy_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/11 12:07:48 by tchampio #+# #+# */
/* Updated: 2025/08/11 12:10:21 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DESTROY_UTILS_H
# define DESTROY_UTILS_H
# include "../cub3d_data.h"
void destroy_textures(t_cub3d_data *data);
void destroy_sprites(t_cub3d_data *data);
#endif

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */ /* Created: 2025/07/17 13:59:27 by kcolin #+# #+# */
/* Updated: 2025/07/31 14:25:10 by kcolin ### ########.fr */ /* Updated: 2025/08/12 15:38:45 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,7 @@
#include "../../libft/includes/libft.h" #include "../../libft/includes/libft.h"
#include "../map/mapdata.h" #include "../map/mapdata.h"
#include "../cub3d_data.h" #include "../cub3d_data.h"
#include "./destroy_utils.h"
#include <stdlib.h> #include <stdlib.h>
void free_tab(char **tab) void free_tab(char **tab)
@ -65,21 +66,12 @@ int destroy(t_cub3d_data *data, int exit_code)
mlx_destroy_window(data->mlx, data->mlx_win); mlx_destroy_window(data->mlx, data->mlx_win);
if (data->img_data) if (data->img_data)
mlx_destroy_image(data->mlx, data->img_data->img); mlx_destroy_image(data->mlx, data->img_data->img);
destroy_textures(data);
destroy_sprites(data);
free(data->img_data); free(data->img_data);
if (data->no_texture)
mlx_destroy_image(data->mlx, data->no_texture->img);
free(data->no_texture);
if (data->so_texture)
mlx_destroy_image(data->mlx, data->so_texture->img);
free(data->so_texture);
if (data->ea_texture)
mlx_destroy_image(data->mlx, data->ea_texture->img);
free(data->ea_texture);
if (data->we_texture)
mlx_destroy_image(data->mlx, data->we_texture->img);
free(data->we_texture);
if (data->mlx) if (data->mlx)
mlx_destroy_display(data->mlx); mlx_destroy_display(data->mlx);
free(data->sprite_list);
free(data->mlx); free(data->mlx);
free(data->screen_matrix); free(data->screen_matrix);
exit(exit_code); exit(exit_code);

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */ /* Created: 2025/07/17 14:22:57 by kcolin #+# #+# */
/* Updated: 2025/07/29 13:35:29 by tchampio ### ########.fr */ /* Updated: 2025/08/13 15:25:04 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,6 +31,8 @@ int keypress_handler(int keycode, t_cub3d_data *data)
data->keypresses.is_s_pressed = true; data->keypresses.is_s_pressed = true;
if (keycode == XK_d) if (keycode == XK_d)
data->keypresses.is_d_pressed = true; data->keypresses.is_d_pressed = true;
if (keycode == XK_f)
data->keypresses.is_f_pressed = true;
if (keycode == XK_Left) if (keycode == XK_Left)
data->keypresses.is_left_pressed = true; data->keypresses.is_left_pressed = true;
if (keycode == XK_Right) if (keycode == XK_Right)
@ -48,6 +50,8 @@ int keyrelease_handler(int keycode, t_cub3d_data *data)
data->keypresses.is_s_pressed = false; data->keypresses.is_s_pressed = false;
if (keycode == XK_d) if (keycode == XK_d)
data->keypresses.is_d_pressed = false; data->keypresses.is_d_pressed = false;
if (keycode == XK_f)
data->keypresses.is_f_pressed = false;
if (keycode == XK_Left) if (keycode == XK_Left)
data->keypresses.is_left_pressed = false; data->keypresses.is_left_pressed = false;
if (keycode == XK_Right) if (keycode == XK_Right)

View file

@ -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/05 15:45:01 by tchampio ### ########.fr */ /* Updated: 2025/08/18 13:13:22 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,9 @@
#include "../../libft/includes/libft.h" #include "../../libft/includes/libft.h"
#include "../../mlx/mlx.h" #include "../../mlx/mlx.h"
#include "../map/map_checker.h" #include "../map/map_checker.h"
#include "../sprites/create_sprite.h"
#include "frees.h" #include "frees.h"
#include <stdio.h>
t_img_data *load_single_texture(t_cub3d_data *data, char *path) t_img_data *load_single_texture(t_cub3d_data *data, char *path)
{ {
@ -52,6 +54,29 @@ void load_textures(t_cub3d_data *data)
data->ea_texture = load_single_texture(data, data->map->ea_texture); data->ea_texture = load_single_texture(data, data->map->ea_texture);
} }
void place_base_sprites(t_cub3d_data *data, char **map)
{
int y;
int x;
y = 0;
while (y < data->map->mapheight)
{
x = 0;
while (x < (int)ft_strlen(map[y]))
{
if (ft_strchr("MQJD", map[y][x]))
{
if (data->sprite_counter < MAX_SPRITES)
data->sprite_list[data->sprite_counter++]
= place_right_sprite(data, map[y][x], x, y);
}
x++;
}
y++;
}
}
void init_cub3d_data(t_cub3d_data *data, char **argv) void init_cub3d_data(t_cub3d_data *data, char **argv)
{ {
ft_bzero(data, sizeof(*data)); ft_bzero(data, sizeof(*data));
@ -72,5 +97,7 @@ void init_cub3d_data(t_cub3d_data *data, char **argv)
init_player(&data->player, data->map); init_player(&data->player, data->map);
data->screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT); data->screen_matrix = ft_calloc(sizeof(int), WIDTH * HEIGHT);
load_textures(data); load_textures(data);
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
ft_memset(data->sprite_distances, -1, MAX_SPRITES); ft_memset(data->sprite_distances, -1, MAX_SPRITES);
place_base_sprites(data, data->map->map);
} }

View file

@ -6,7 +6,7 @@
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */ /* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/29 13:42:39 by tchampio #+# #+# */ /* Created: 2025/07/29 13:42:39 by tchampio #+# #+# */
/* Updated: 2025/07/29 20:09:30 by tchampio ### ########.fr */ /* Updated: 2025/08/13 15:22:54 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,6 +21,7 @@ typedef struct s_keypresses
bool is_d_pressed; bool is_d_pressed;
bool is_left_pressed; bool is_left_pressed;
bool is_right_pressed; bool is_right_pressed;
bool is_f_pressed;
} t_keypresses; } t_keypresses;
#endif // KEYPRESSES_H #endif // KEYPRESSES_H