diff options
author | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-03-11 18:06:17 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p1.le-101.fr> | 2020-03-11 18:06:17 +0100 |
commit | 7b61072321c71c1612a7b33d2e8d722a49c5bc99 (patch) | |
tree | 6369fc33d405013e40e152061bb080e6a5caabf8 | |
parent | Performance (diff) | |
download | 42-cub3d-7b61072321c71c1612a7b33d2e8d722a49c5bc99.tar.gz 42-cub3d-7b61072321c71c1612a7b33d2e8d722a49c5bc99.tar.bz2 42-cub3d-7b61072321c71c1612a7b33d2e8d722a49c5bc99.tar.xz 42-cub3d-7b61072321c71c1612a7b33d2e8d722a49c5bc99.tar.zst 42-cub3d-7b61072321c71c1612a7b33d2e8d722a49c5bc99.zip |
ca tue
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 4 | ||||
-rw-r--r-- | map/lvl_five.cub | 13 | ||||
-rw-r--r-- | map/map_one.cub | 2 | ||||
-rw-r--r-- | media/img/spikes.xpm | 451 | ||||
-rw-r--r-- | src/ft_draw_scene.c | 5 | ||||
-rw-r--r-- | src/ft_draw_traps.c | 110 | ||||
-rw-r--r-- | src/ft_draw_traps_extra.c | 44 | ||||
-rw-r--r-- | src/ft_get_player_spawn.c | 1 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 | ||||
-rw-r--r-- | src/ft_suffer_animation.c | 14 |
12 files changed, 628 insertions, 21 deletions
@@ -88,6 +88,8 @@ SRCS_NAME += ft_init_bmp.c SRCS_NAME += ft_floor_cast.c SRCS_NAME += ft_floor_cast_inits.c SRCS_NAME += ft_suffer_animation.c +SRCS_NAME += ft_draw_traps.c +SRCS_NAME += ft_draw_traps_extra.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index ae353ae..016677a 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -78,6 +78,8 @@ void ft_sprite_width(t_cub *cl, t_sprite *sprite); void ft_sprite_height(t_cub *cl, t_sprite *sprite); void ft_calc_sprite(t_cub *cl); void ft_draw_sprite(t_cub *cl, t_sprite *sprite); +void ft_calc_trap(t_cub *cl); +void ft_draw_traps(t_cub *cl, t_sprite *sprite); void ft_draw_skybox(t_cub *cl); void ft_suffer_animation(t_cub *cl); diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 957d154..7a30d09 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -182,9 +182,9 @@ typedef struct s_map size_t map_h; size_t mapl_len; int32_t sprite_nbr; - int32_t sprite_order[12]; + int32_t sprite_order[4096]; int32_t traps_nbr; - int32_t traps_order[12]; + int32_t traps_order[512]; size_t line_chk; size_t map_start; uint8_t isspawn; diff --git a/map/lvl_five.cub b/map/lvl_five.cub index 02df893..bd8acab 100644 --- a/map/lvl_five.cub +++ b/map/lvl_five.cub @@ -12,24 +12,25 @@ F ./media/img/plate_small.xpm LT ./media/img/larry_world.xpm L ./map/map_four.cub +T ./media/img/spikes.xpm SH 16 MU ./media/sound/TAPE-DU-PIED-ET-FRAPPE-TA-TANTE.wav 111111111111111111111111111111 -100000000000000000000000000001 +1T0000000000000000000000000001 11111101111110110111111110111111 - 1111101 101001 10000001 + 1111101 101T01 10000001 1000001 11101101 1111110111111 - 1101101 10000001 1000000000001 + 11T1101 10000001 1T00000000001 101101 111111101 1111111111101 111101 101 101 1000001 101 1011101 101 1011101 101 - 11110000011111N1 1010001 101 + 11110000011111N1 101T001 101 1011011111101111 10111111101 101101 1L0011 10000000001 100001 110111111111111111101 101101 11110000000000000000001 - 101101 10111111111110011111101 + 101101 1011111111111T011111101 111011111101111111111110111111011 -100000000000000000000000000000001 +1T00000000000000000000000000000T1 111111111111111111111111111111111 diff --git a/map/map_one.cub b/map/map_one.cub index 285fbf0..a774b0a 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -9,7 +9,7 @@ S ./media/img/pillar.xpm C 50,100,200 F 50,190,124 -T ./media/img/linus.xpm +T ./media/img/spikes.xpm SH 4 111111111111111111 diff --git a/media/img/spikes.xpm b/media/img/spikes.xpm new file mode 100644 index 0000000..2aef2ea --- /dev/null +++ b/media/img/spikes.xpm @@ -0,0 +1,451 @@ +/* XPM */ +static char *spikes[] = { +/* columns rows colors chars-per-pixel */ +"316 316 129 2 ", +" c #000000", +". c #080705", +"X c #0A0906", +"o c #0C0C0B", +"O c #100D06", +"+ c #100F0C", +"@ c #12110E", +"# c #18160E", +"$ c #151412", +"% c #181713", +"& c #1B1A15", +"* c #1D1C1A", +"= c #211E16", +"- c #201F1A", +"; c #252116", +": c #24221C", +"> c #29261E", +", c #2D291F", +"< c #312D1E", +"1 c #252422", +"2 c #292721", +"3 c #2C2A23", +"4 c #2D2D2A", +"5 c #312D24", +"6 c #312F29", +"7 c #353126", +"8 c #3A3526", +"9 c #3D3927", +"0 c #34322B", +"q c #3A362B", +"w c #3D392C", +"e c #353432", +"r c #383732", +"t c #3C3A33", +"y c #3D3C3A", +"u c #413B27", +"i c #423C2C", +"p c #483F2F", +"a c #423E33", +"s c #413F39", +"d c #46412D", +"f c #4A442E", +"g c #454135", +"h c #4E4935", +"j c #434138", +"k c #44423B", +"l c #474539", +"z c #46443E", +"x c #494738", +"c c #484639", +"v c #4E4B3A", +"b c #504735", +"n c #534B35", +"m c #534C3C", +"M c #504E3C", +"N c #504C3F", +"B c #594F3C", +"V c #575035", +"C c #595136", +"Z c #57523D", +"A c #55523E", +"S c #59543F", +"D c #5F593C", +"F c #62573F", +"G c #635B3D", +"H c #695E3F", +"J c #444443", +"K c #474642", +"L c #484540", +"P c #4C4940", +"I c #4D4C42", +"U c #494844", +"Y c #4E4C45", +"T c #4D4C4B", +"R c #514E40", +"E c #514F4A", +"W c #504F4D", +"Q c #555144", +"! c #595540", +"~ c #585443", +"^ c #5D5640", +"/ c #5D5741", +"( c #5B5444", +") c #51504A", +"_ c #54534F", +"` c #585648", +"' c #5A5649", +"] c #5D5A4B", +"[ c #525252", +"{ c #595755", +"} c #5E5B52", +"| c #605642", +" . c #635B44", +".. c #605B46", +"X. c #6A5E45", +"o. c #635C4B", +"O. c #695E4A", +"+. c #625E52", +"@. c #635F53", +"#. c #676046", +"$. c #6C6345", +"%. c #6B634C", +"&. c #716746", +"*. c #72664B", +"=. c #756A4B", +"-. c #796D4C", +";. c #77704C", +":. c #7C724E", +">. c #656253", +",. c #6B6553", +"<. c #6E6955", +"1. c #666358", +"2. c #6A6759", +"3. c #6D695A", +"4. c #706751", +"5. c #736B54", +"6. c #7A6D53", +"7. c #736D5B", +"8. c #796F59", +"9. c #7D7353", +"0. c #76705D", +"q. c #7B735C", +"w. c #6F6C61", +"e. c #736E60", +"r. c #757061", +"t. c #7B7561", +"y. c #7E7862", +"u. c #817551", +"i. c #827B63", +/* pixels */ +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" . o ", +" o * o + * o * . o o ", +" o 1 4 * * e % * e % o 1 : o ", +" $ e e 1 o o 1 e * 1 y * $ e 4 o ", +" $ 0 e e * & t r * . + e e * $ e 4 & ", +" : e t e $ * y t 4 + 1 J t : * 0 r 3 o ", +" & t y t 0 $ o 4 j j y % 4 [ j 4 o $ 0 t t & ", +" 1 W c t 3 o % y I j y & 3 [ j 0 $ @ 7 t t & ", +" : I c g 3 o % y x j 0 $ + e I x 0 - @ 0 x t = ", +" : c v g > o & t v v q $ * J I v g 0 o & w x x 0 & ", +" X 2 v M h 3 & : R v v g & * I N N h 0 o * w v v I 6 o ", +" : w Z Z N 7 * $ o 6 ' ~ ~ h = 1 I ~ S N t @ $ : g Z Z ~ x * ", +" * r Z Q Z n t 1 1 $ X 6 ~ ~ S v : 3 } ' S ~ v : o 1 3 h Z Z ~ j * ", +" * I ~ ~ S S i 1 1 o @ w S G ~ Z 7 X 6 >.] / ~ ~ > + 2 7 n S S S g & ", +" 0 >. . . .D t : * . : N .~ .~ w @ 4 o.$./ .G 5 * e 0 S . .~ Z ; ", +" * I <.$.$. .#.x : * o ; ~ $.$.$. .n & o q o.#.#.#.X.0 o $ 0 0 S . .$.D 7 ", +" 4 3.7.$.$.$.#.x > 0 * . > .$.$.$.$.N ; @ w .$.$.$.$.v & o : 8 .$.$.$. .w @ ", +" 0 3.=.=.$.=.$.n 3 0 * . X 8 $.*.=.*.$.S > @ w $.&.&.&.$. .> o * 7 .&.=.=.$.V ; ", +" 5 o.&.-.-.=.*.~ 3 1 @ & x $.=.-.=.&.$.< & j $.=.;.5.=.$.5 . % * w $.=.=.=.=.X.9 + ", +" X 8 $.=.-.:.=.=. .5 * $ ; n $.-.:.-.=.=.8 3 #.=.=.:.:.=.5.8 o 4 : g 6.-.-.:.-.=.o.2 ", +" : S 9.:.u.u.9.9.$.0 - 4 $ ; S &.u.u.u.:.9.i X w q.u.:.u.u.:.:.w @ 3 ; x u.:.u.u.9.:.u.w ", +" . 0 5.9.:.:.u.:.u.H < 2 s 4 + 5 $.:.:.:.:.:.:.u X w 9.9.:.u.u.:.;.d O $ 4 > n 9.:.u.u.u.9.u.w ", +" . a 9.-.:.:.:.:.:.G < > y J * o 8 &.$.:.:.:.:.&.f O 8 *.=.:.:.:.:.:.f # * 2 > f -.:.u.:.9.=.;.g @ ", +" q 3.F D G &.=.-.G 8 : e J & + q S G G G G G G 9 X o 3 n G #.$.&.;.;.f # $ 4 - & u &.:.=.&.$.G .a % ", +" 4 [ x f C G $.$.V 8 > 2 4 + o 0 v d d d b V f < X $ 0 i d V D G $.&.h = $ e 1 % 8 G $.G S n x a 5 @ ", +" o 5 L x n G .G C d < = * + + 2 q i 9 u u 9 w 0 $ % e t d h C D D G D : o 2 2 & < C F n n i 8 5 - % ", +" + 4 s R ~ S $. .| N q > & $ . $ > 5 5 5 7 < 3 5 0 $ @ 6 q 9 i d d f V v > $ 4 2 & 5 i f u u 8 8 3 3 4 $ ", +" . 2 E R +.4.#.o.$.X.S 8 : # $ o . $ 4 6 5 5 5 5 5 < > 3 $ + 4 3 < 7 0 0 w w t 0 @ $ 4 & % 5 i i u q 8 q 0 4 y * ", +" + y [ o.7.7.<.$.5.<.H i > % $ % $ . + 6 q q q u u q 7 5 > 3 o . + * 2 < 7 7 0 w w g t * * * + & 0 i p d p i i q 0 e % ", +" $ e I O.7.7.4.8.6.u.X.p > & % * 1 o . + 5 p a p x p a 8 5 > 2 + . + 1 > 5 5 8 q q a i x s : . . 1 % % * r a N N B b p i 5 3 1 o ", +" o 1 x O.<.O.7.u.8.8.%.p > & * 1 y * $ 8 N Q Q Q x a q 5 2 > % . $ e 8 6 8 q t a a v x p 4 o . * e * % 2 t p Q F F N p i 7 6 e & ", +" o 3 j %.7.O.7.u.i.q.*.x 2 = % 1 y * & a Q ' | R x p w 6 2 > 4 . 1 E y 5 i i a g s p x a 0 o * e - & 6 t s ~ $.o.R p i 7 6 y 1 o ", +" * t ' O.O.3.4.i.u.6.4.N 3 - & * 4 1 + X * x ' O. .R N g a q 5 3 e * X 1 [ s a a g x j x b s a 6 $ o * % & 0 t x ' 4.o.Q N p 7 6 e * ", +" $ e j / o.O.e.4.7.7.u.8.N 5 - % $ 4 J * 5 { 4.+.' ~ v x t q 5 6 y * - J a p s x L L N N s a e $ . % $ - t t v S <.o.B N s i 6 2 $ ", +" . 1 y Z +. .+.7.w.7.7.e.i.' 6 - % $ e T 4 X e +.8.O.] ~ I g a q 0 6 e % $ e r x I R R R R L s a t : . . + % $ : q a I ~ o.o.R B s a 6 5 $ ", +" $ e y ~ ] / >.7.7.7.u.i.i.' e 1 * $ 4 J 1 + a +.4.@.] ] ~ j a t 0 3 4 + X % 6 s L N E R R N N B a y 3 + . . 1 $ @ : t g N ~ o.' Q N B p r 6 - . ", +" % y J R ] ~ >.w.4.e.w.w.y.[ e * % $ 4 T 4 X $ e I o.+.] ' R I s a q 4 1 + & 8 x R Q ' ' R Q N s a y y % . o 1 $ $ : a g h v o.>.Q Q a s r 6 2 % ", +" * J j R ~ [ ' 7.7.e.e.e.i.} 0 - * $ 4 T 1 o & e s N ~ ' ] Q I j t 0 6 1 o $ 0 L ~ [ ~ ~ T v x x s y j * + 1 $ $ 3 x I x ' @.@.' R x s r 6 2 4 $ ", +" o 4 j j I R ~ ' +.+.1.1.1.e.} 0 * * @ 1 e * X - 6 r a R ~ ' I j j t r 4 : o $ 0 x [ ~ ~ R I I j j j t j * % 1 $ $ 6 R R R R @.@.E L x s r 5 e e $ ", +" 1 T y j I I R E o.+.+.e.e.w.' e - * @ @ * % . $ 1 0 0 t y x I ~ j j a e 6 1 $ . $ q I [ ] ] ~ I v j j j t t & . * * $ + 2 j R R ' +.' E R x s r 6 5 2 * ", +" 1 E J j x I I ~ o.+.+.w.e.e.} a - % @ @ * 4 + + 4 4 0 0 0 t t x I I j j t 4 1 & X & r R S o.~ [ ~ I I L j y r & o * * + @ : a x R .+.[ ' E I s r 6 6 2 4 $ ", +" 4 J j j j x x R ' +.@.e.w.e.} a * % + $ * e * . @ e 0 0 0 0 0 r t v I L j y e 2 % o 2 t [ o.+.+.' I I R L t t 0 : . o + @ $ : t g L O.O.+.[ R R x a e 5 2 r * ", +" $ e j s t s a x R ' +.@.1.4.e.} s - * $ o 1 y * % e 0 6 6 3 6 7 7 t v j j t 0 4 - o + 3 t ' +.>.>.+.I I R x s 0 0 3 o . o o @ @ - t g I .+.+.' [ I L s e 6 5 4 * ", +" $ t y a a a s x N | ' o.O.7.u.+.s - % $ + * e % * t 6 4 3 3 4 6 7 w t g g t t 4 1 o o 2 a o.+.#.} ] [ R I x x t w 0 $ . . o @ $ : q j N O.O. .N N x L s 7 e 2 1 * . ", +" & e t a t g p b B Q ' ' O.4.4.4.s - % $ + % 4 % + 4 3 3 3 3 3 6 7 7 w a a i q 6 1 o o 3 a | o.] ] ] ' E R N x g t r : o . o + @ @ - i x ~ O.+.~ R N N x a e 5 2 1 1 o ", +" 1 e q w a g x b n B F X.X.*.<.5.j 3 % $ + $ * o + 1 1 2 5 2 5 < 7 5 8 q i i 7 5 * O . $ 3 i | O.o.] ] _ M I c h g a w 2 o + + @ $ * 0 x | X.| F B N b p i i 5 2 1 * o ", +" . : 0 q q i a f b C B | X.*.*.$.5.~ 3 * $ @ + o $ - - = = > 5 5 < 7 7 q i i i 5 > + . @ 3 i ~ o.o.o.} ~ Q g R s g i q : X o + @ $ = 7 x F | | B B B b p i 8 5 5 2 * . ", +" o 1 0 0 0 w i p h h B | X.O.X.o.<.~ q * $ $ o o . % * - - 2 2 , > , 7 8 q i q i 4 4 % . & 3 w B .S _ ] ~ W I c c a a w 5 + . @ @ @ @ & 0 x N B B B V N b a i 5 5 5 2 : @ ", +" * 4 4 5 0 w w i i j b N B ' S S o. .g 1 $ @ $ % o . * * * - - = = > > > < 5 7 7 7 6 2 % & 3 t N R ~ ~ ~ _ I Z c c a a t q % @ * $ @ @ : q j x p x p p x a a 5 8 6 5 1 1 $ . ", +" @ 4 4 4 7 7 0 q q q i i p h S .~ o.S h 5 & @ & 1 + @ & & - = = > > > > > 5 8 i q 0 3 % X * 0 g N v N n v v g v j v x p a w % * 1 $ o @ : w x p f i i u i i i q 7 7 3 1 1 1 o ", +" $ 4 1 1 > < 7 7 8 8 i u i p R | S S N g < ; & * 1 + X * ; > , , 5 < < 8 8 8 8 i i i q > % . X : w h n n c h h h h v n n n n n i & o % * $ o @ & 0 n n C b b f d d d i 9 9 7 7 7 0 $ ", +" o & & : < 7 8 9 9 u u f i f b n n n d 8 > ; * $ % + o * t q 9 u u p u u d d d d x d d u > + $ : 8 x h n n S G G D .$.$.$.H F u & @ @ + + @ = 8 G $.$.H H G C C V f d u u 8 w e $ ", +" . % : & > 7 7 8 8 9 9 i u u i i p d i 8 3 > : * % % $ + + e j a p d x b d x h h n n B N n i 3 % $ . $ 4 3 w d x n S G $.*.$. .$.$.&.X.F i 6 @ o + + + + & 8 n *.-.6.=.&.G C n f d d 9 8 < 3 1 o ", +" . * 4 & * : > > > > > 3 > 7 7 7 7 6 6 6 2 2 ; * & $ & & o . * e e 0 0 w a a g j v R N | +.<.' a 7 * $ . & y q w g g I ~ ] >.<.<.~ ~ o.| R x t y * o * $ + @ + - x .5.5.;.<. .h w w 7 7 6 > > > - & @ ", +" . * * * * - - : - : : : 1 3 3 6 6 6 6 < 4 1 : & & $ & 1 $ . + e e e 0 0 t a a g I R ~ ' o.4.7.$.g 0 : o . * y t t j v ' >.<.<.<.<.+.o.3.O.R x t r 1 o + * $ + @ @ = a .5.>.<.<. .g 3 0 3 3 > > > : - - % + ", +" + * * % * - - - 1 : : 3 3 3 6 6 6 6 6 4 4 1 : * & $ * 1 1 o * e e 0 0 r t g g j v R ~ ] >.7.7.] t w 1 $ * y t a v ~ ] <.0.q.<.7.<.>.3.3.' v t 0 4 o . + % + + @ $ * t ] o.%.3.<.] g 0 0 6 6 4 2 > 1 - - * % ", +" + 4 * * * * * * - - : 3 1 2 3 3 4 6 6 6 2 > 1 ; * & $ $ 1 e % * T t 0 r r t j j j N ~ _ ] +.7.3._ t 0 2 $ & e t j j I ] 3.r.7.7.1.+.#.3.7.[ I t 0 1 o . $ $ o $ + $ & t ] .>.3.<.>.j w 0 3 4 2 2 2 1 - - * & + ", +" . * e 1 & * & * - : : 1 4 2 2 2 6 6 4 4 6 4 > : : * * $ $ 1 J * . * y q r r r a j x j I R [ o.+.1.7.I w r > @ . . % e e j x T ' >.3.3.3.<. .>.<.<.{ I a 0 : X o + + @ $ @ & t >.0.0.3.3.3.Z t 6 6 6 4 > 2 1 - - * * 1 + ", +" + e e 1 * * * * - - : 1 2 2 2 3 4 6 2 6 6 2 4 1 * # $ & $ * e % . * e t t t a j j J v R [ [ } 1.1.<.x w r 6 & $ 4 t j x ~ } >.3.3.3.>.>.3.7.<.+._ a 0 1 o . $ + + + @ $ & w #.t.t.q.3.1.W a 6 6 3 2 2 2 1 1 1 * 4 e % ", +" % e 4 - * * * - * - 1 1 1 2 2 4 4 6 4 3 3 3 2 1 ; * * & o * 1 * % e y a t y s x j j x ~ ' ] +.1.7.+.t 7 r 7 & . * e t j v _ >.>.3.1.1.>.>.3.e.3.>.~ j r 4 % . . % @ + @ @ @ & w $.q.t.r.3.+.I t 0 6 6 2 4 2 1 1 1 * 1 e * . ", +" % 0 1 * * * - * - - - 1 1 2 2 3 6 4 6 6 6 6 > 1 : * & & $ * e J e [ j a a s x L x v I R o.+.>.1.w.<.t r t 0 = o o 2 r t j x ~ ] 1.3.>.>.' ] 3.3.3.1.' x e e e % . + + + @ @ % & g $.q.;.3.3.} W t 7 6 6 4 2 4 1 1 1 1 * 1 * X ", +" $ e * * * : : * : ; : > 2 5 > < 6 5 2 3 3 4 4 2 1 ; * $ $ # e { y { L s j x v N N N N ] .o.4.7.0.>.g q q 0 ; o $ 4 q a x I ' o.+.O.O.O. .+.3.3.>.>.' N a r J * . o + + + @ % : v >.%.o.<.7.1.S c w r 7 7 0 > = 2 > > - 2 0 $ ", +" $ 1 * * & : : : : : : > > > 5 2 2 4 4 3 6 4 2 2 ; ; * # # $ : y 4 I J j x I R R Q ~ | O.O.O.6.&.5.O.g 0 q 0 : + $ 0 i p N B ' ] ' O.>.O.O.O.O.+.>.o.| B p a r % X $ + + + $ @ @ : N >.>.+.5.7.4./ x g w 7 7 7 5 5 , 2 = - 2 e * ", +" * * * : : : : > : > > , , < > 3 3 3 < 6 6 4 > 2 ; ; * * # $ $ - 2 s j I I I R F | | X.O.%.*.*.*.*.X.x q 8 7 2 + o $ q a x N S .} .o.X.O.O.O.>.+.o. .| F b a e $ o * $ + + @ $ # 3 ~ 7.r.<.7.8.<. .M c t i 9 7 7 , , , = , - 2 $ ", +" . % 4 1 1 : : : : : > > > > , 5 5 3 3 2 6 2 6 6 6 2 1 : * # # $ $ % 6 s x I I ~ R ~ | X.X.O.*.6.6.u.*.X.x 7 6 6 2 % : o + 5 p b B ~ o.[ .O.X.%.o./ ] +.o.] .| n a q % $ + + + $ $ $ 3 F u.7.1.q.7.$.>.! c d i w 7 7 5 5 5 > , - 2 2 + ", +" $ e 4 1 * : : : : > > > > > > 5 5 < 6 3 3 3 6 6 > > : : = = # & $ - r p R R ~ N ~ | o.O.o.O.*.*.5.8.6.O.s 5 7 6 2 - e % + 5 p b N N F ~ .] O.~ ~ ~ o. .' | | | N p q 2 o . o + @ @ @ % 5 o.0.5.5.q.:.<.O.N N p d w 7 w 5 5 5 5 > : 2 6 $ ", +" . 1 T e : * * : : : > : > > > > 3 5 < 7 3 3 6 7 6 > 2 > = : = * & : 2 x L R R R _ o. .O.O.O.O.O.O.X.u.8.4.p 5 7 7 5 * e % # q h b N B ' ' .o. .Q | Q ' Q ' ' .B N p a t - . + @ @ # # 5 ] $.<.5.6.8.7.O.F N N h t q q 5 5 > > 2 2 2 2 $ ", +" + e T e * - : : : : > > > > > > < 7 7 < 3 7 3 3 6 2 2 > : = * * & : 0 x N N [ ~ ' o.o.<.<.X.O.*.O.*.u.u.4.N 7 6 7 6 1 e % . = i h N Q Q R | F | | B Q Q Q R R Q | B N x x L 1 + @ # @ % 3 ~ ] >.7.5.8.8.$.' R R R d q q 7 7 5 > 5 > > - * o ", +" % e y 1 - : : : : > > > > > > < > 5 < 3 6 < 6 3 6 6 2 > : : * $ $ * j S N ~ ' ] o.O. .X.<.O.&.*.*.*.6.6.%.| p 7 6 6 * * o = i b B S R R ~ ~ F B F B B Q R B Q B n B N x j - X @ @ # % 5 Q ] >.t.q.7.%.<.| B v n c i i i i 5 < 5 > > 2 e $ ", +" * e 0 : : : : > > > > > > , < > 2 5 < 7 < 7 5 5 5 2 2 2 > - + X . 2 ./ Q ' / o.%.<.%.O.O.O.*.*.*.*.*.-.*.X.b 0 5 7 : o = p b B B B ~ ~ | N F B b B N N N b n n n b a a = . $ @ $ & t <.+.<.0.r.<.<.4.O.| Q R b p p p i q 5 5 2 > 5 r & ", +" 4 T 6 : : : : > > 3 2 2 , > 5 5 5 5 7 > < 7 7 5 6 5 2 2 2 & X . . 2 o. .| o./ >.%.5.6.*.4.7.6.6.6.6.6.-.-.*.S w 3 3 : o . = p B B R ~ N B F B N F B N B n B N N n N B N p - . o o $ - g 7.<.7.t.7.0.q.8.5.O./ Q R p N p p i 5 5 5 < > 2 * . ", +" . 1 s 6 > : : : > > 2 3 2 5 5 5 5 3 5 5 5 5 8 7 8 6 6 6 6 6 + 4 +.O.O.+.%.+.O.O.4.7.<.7.6.6.8.q.8.6.5.5.X.i 3 3 * X > x Q B Q N L Q N N n n B ~ p x N n h N N B p a : $ 1 g <.<.q.q.q.u.i.r.6.O. .| Q N h h i p a e 8 5 = 3 4 $ ", +" + 4 e 2 > 1 : : : > 2 2 2 2 2 2 5 0 5 5 5 7 5 5 0 q r e r 1 X 2 o.X.<.<.+.+.] +.O.O.1.o.<.6.8.q.8.6.6.q.*.x 3 1 @ X 5 x R N B x N R N B N B N L p s j b h N p a s p 2 o o 1 j o.<.5.q.t.i.i.t.7.O.o.' Q N N h y s p a 5 5 5 4 t & ", +" * y 6 : > 1 : : : 2 > 2 2 > 3 3 5 3 3 6 6 6 8 5 6 r J e : o 2 S $.7.7.1.+.>.O.O.7.<.o.<.4.5.7.7.4.u.r.5.~ t 1 o X 5 s x x x N x x b N N x s s p s x x x x x a a a 0 @ 1 g Z S .0.t.t.0.<.$.O.o.~ _ I v x x a a a 5 5 5 5 4 $ ", +" * y 4 - * * - - : : : - : - : > > 3 : > 2 > 3 3 2 r T 4 o > N ~ _ S ' ' ' ~ | R _ ~ ~ o. .o. .| o.<.o.~ t * o > i a i r a a a a a i q q q a p t q q q q 0 0 q 5 + o : 3 > t <.7.<.~ N S S I N v j t a i q q 5 5 > 2 > : o ", +" o 1 $ o @ o o @ @ @ @ o @ + @ @ @ @ $ @ @ # % # $ - 6 $ + 3 5 5 5 6 6 0 8 6 2 5 6 3 8 5 q 7 7 q q q 7 2 o + - - = - - - = = - - = - - - % - = - = = & & = $ X X X X & t g r 6 , 5 5 3 : 3 > : = - = % % % % $ @ @ . ", +" . . + . . X . X + o X O . o . o . X + O O + + o X . . . . . . . . . . X . . o @ X X X X X o X . . . . . ", +" ", +" ", +" ", +" " +}; diff --git a/src/ft_draw_scene.c b/src/ft_draw_scene.c index 39cdadc..80cd1bc 100644 --- a/src/ft_draw_scene.c +++ b/src/ft_draw_scene.c @@ -41,10 +41,6 @@ static int8_t void ft_draw_scene(t_cub *clist) { - /* clist->img.img = mlx_new_image(clist->wlist.wlx, */ - /* clist->wlist.x_size, clist->wlist.y_size); */ - /* clist->img.ptr = mlx_get_data_addr(clist->img.img, &clist->img.bpp, */ - /* &clist->img.sizeline, &clist->img.endian); */ if (clist->doicast) ft_castray(clist); else @@ -58,7 +54,6 @@ void if (clist->ishud && clist->mlist.isnlvl) if (ft_put_stage(clist) < 0) ft_error(FT_RET_ALLOC_ERR, FT_ERR_ALLOCATE, clist); - /* mlx_destroy_image(clist->wlist.wlx, clist->img.img); */ } void diff --git a/src/ft_draw_traps.c b/src/ft_draw_traps.c new file mode 100644 index 0000000..42f837b --- /dev/null +++ b/src/ft_draw_traps.c @@ -0,0 +1,110 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_traps.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +static void + ft_sort_traps_norme(float *dist_tab, int32_t it, t_cub *cl) +{ + uint32_t tmp; + + tmp = 0; + if (dist_tab[it] > dist_tab[it + 1]) + { + tmp = dist_tab[it]; + dist_tab[it] = dist_tab[it + 1]; + dist_tab[it + 1] = tmp; + tmp = cl->mlist.traps_order[it]; + cl->mlist.traps_order[it] = cl->mlist.traps_order[it + 1]; + cl->mlist.traps_order[it + 1] = tmp; + it = 0; + } +} + +void + ft_sort_traps(t_cub *cl) +{ + float dist_tab[4096]; + int32_t it; + + it = 0; + while (it < cl->mlist.sprite_nbr) + { + dist_tab[it] = ((cl->plist.pos_x - cl->traps[it].s_pos_x) * + (cl->plist.pos_x - cl->traps[it].s_pos_x) + + (cl->plist.pos_y - cl->traps[it].s_pos_y) * + (cl->plist.pos_y - cl->traps[it].s_pos_y)); + cl->mlist.traps_order[it] = it; + it++; + } + it = 0; + while (it < cl->mlist.traps_nbr) + { + ft_sort_traps_norme(dist_tab, it, cl); + } +} + +static void + ft_put_trap(t_sprite *sprite, t_cub *cl) +{ + float dist; + float calc; + + if ((dist = cl->rlist.wall_dist_tab[sprite->x]) <= 0) + dist = 0.0001; + calc = (dist * 0.1 * cl->mlist.darklvl); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 1] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 1] / calc; + cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline) + 2] = + (uint8_t)cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y + 2] / calc; + cl->img.ptr[sprite->x * 4 + cl->wlist.x_size * sprite->y + 3] = (char)0; +} + +void + ft_draw_traps(t_cub *cl, t_sprite *sprite) +{ + int32_t d; + + sprite->x = sprite->drawstartx; + while (sprite->x < sprite->drawendx) + { + sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + + sprite->spritescreenx)) * cl->tlist[15].img_w / sprite->spritewidth); + sprite->y = sprite->drawstarty; + while (sprite->y < sprite->drawendy) + { + d = sprite->y * 256 - cl->wlist.y_size * 128 + + sprite->spriteheight * 128; + sprite->tex_y = ((d * cl->tlist[15].img_h / 2) / + sprite->spriteheight) / 128; + if (sprite->transformy > 0 && cl->tlist[15].ptr[sprite->tex_x * 4 + 4 * + cl->tlist[15].img_h * sprite->tex_y] + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) + { + ft_put_trap(sprite, cl); + } + sprite->y++; + } + sprite->x++; + } +} diff --git a/src/ft_draw_traps_extra.c b/src/ft_draw_traps_extra.c new file mode 100644 index 0000000..a2fd0ab --- /dev/null +++ b/src/ft_draw_traps_extra.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_draw_traps_extra.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ +/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <cub3d.h> +#include <stdint.h> +#include <stdlib.h> +#include <math.h> + +void + ft_calc_trap(t_cub *cl) +{ + t_sprite sprite; + int32_t i; + + i = 0; + while (i < cl->mlist.traps_nbr) + { + sprite = cl->traps[i]; + sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist.dir_y + - cl->plist.dir_x * cl->plist.plane_y); + sprite.transformx = sprite.invdet * (cl->plist.dir_y * sprite.spritex + - cl->plist.dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * (-cl->plist.plane_y * sprite.spritex + + cl->plist.plane_x * sprite.spritey); + sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite.transformx / sprite.transformy); + ft_sprite_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_traps(cl, &sprite); + i++; + } +} diff --git a/src/ft_get_player_spawn.c b/src/ft_get_player_spawn.c index 6853313..ef2edd9 100644 --- a/src/ft_get_player_spawn.c +++ b/src/ft_get_player_spawn.c @@ -83,6 +83,7 @@ void plist->start_y = plist->pos_y; ft_get_start_side(clist->mlist.map[y][x], plist); ft_get_sprite_spawn(clist); + ft_get_trap_spawn(clist); return ; } x++; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 2d6d197..a0720ea 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -106,6 +106,7 @@ void } ft_floor_cast(cl); ft_calc_sprite(cl); + ft_calc_trap(cl); ft_memdel((void**)&cl->rlist.wall_dist_tab); ft_memdel((void**)&cl->rlist.wall_bz); } diff --git a/src/ft_suffer_animation.c b/src/ft_suffer_animation.c index 1a9b51a..b800a39 100644 --- a/src/ft_suffer_animation.c +++ b/src/ft_suffer_animation.c @@ -21,11 +21,9 @@ void { int32_t x; int32_t y; - int32_t col; t_rgb rgb; y = -1; - col = 0x00880000; while (++y < (int32_t)cl->wlist.y_size) { x = -1; @@ -33,14 +31,16 @@ void { rgb = ft_hex_to_og_rgb(*(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline)))); - rgb.r += 120; + rgb.r += 150; + rgb.g += 20; + rgb.b += 20; *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(rgb); } - /* if (y < (int32_t)cl->wlist.y_size / 2) */ - /* col += 0x00000000; */ - /* else */ - /* col -= 0x00000000; */ } + cl->plist.life -= 20; + if (cl->plist.life <= 0) + ft_exit(0, cl); + /* TODO death screen here */ cl->doicast = 0; } |