Compare commits

...

7 commits

Author SHA1 Message Date
fb4680e4bd
feat: close window and exit on window close event 2025-08-20 13:53:18 +02:00
Theo Champion
0771881690 feat: New texture for the double tap perk machine 2025-08-20 13:43:40 +02:00
Theo Champion
a6c6420398 fix: Used blocking check function instead of rewriting test 2025-08-20 12:49:33 +02:00
Theo Champion
c643d9f22a fix: Fixed inversion of x and y for blocking checks functions 2025-08-20 12:48:48 +02:00
Theo Champion
b138fe8100 fix(sprite caster): Fixed crash when sprites overlap
Actually I'm not that sure it's the sprite overlap but it happened when
the sprites overlapped too close to the player, but basically the
program tried to render pixels out of bounds from the images, tex_x or
tex_y were able to go < 0. I forcefully set them to 0 if it was the
case, and I didn't see really much of visual glitches or something.
Anyways I'll stop rambling in this commit, just to say I stopped a real
weird crash because when I tried using valgrind or sanitizers, the
program would behave well and not crash. Might be tied to how fast the
program renders frames ?
2025-08-19 19:45:00 +02:00
Theo Champion
0ac7c27445 norme: Fixed norme error 2025-08-19 19:13:58 +02:00
Theo Champion
38487527f9 feat: Improved movements for the sprite 2025-08-19 18:58:55 +02:00
8 changed files with 190 additions and 53 deletions

112
ressources/dbltap.xpm Normal file
View file

@ -0,0 +1,112 @@
/* XPM */
static char * dbltap_xpm[] = {
"64 64 45 1",
" c #FF00DC",
". c #000001",
"+ c #AA9F9F",
"@ c #F89C2F",
"# c #A45D18",
"$ c #DF8C2A",
"% c #C97F26",
"& c #A67310",
"* c #D19114",
"= c #E8A117",
"- c #F7AB18",
"; c #D49315",
"> c #A77310",
", c #F0972E",
"' c #F4A918",
") c #F5AA18",
"! c #DE8B2A",
"~ c #F3A818",
"{ c #DD8B2A",
"] c #EF962D",
"^ c #B37B0F",
"/ c #96680F",
"( c #F6D79A",
"_ c #F4E3C3",
": c #E8E0D1",
"< c #A87410",
"[ c #E9A217",
"} c #EE962D",
"| c #848282",
"1 c #767474",
"2 c #B3B3B3",
"3 c #ADADAD",
"4 c #ACACAC",
"5 c #A9180D",
"6 c #6B6969",
"7 c #D29214",
"8 c #A97510",
"9 c #6A6969",
"0 c #777575",
"a c #494949",
"b c #B38007",
"c c #FFB400",
"d c #F0AB06",
"e c #975B26",
"f c #E09E00",
" ",
" .............................................................. ",
" .++++++@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .+++++++@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@##++#@@@###@. ",
" .+++++++@@@@@@@@@@@@@@@@@@$.........$@@@@@@@#@@@#@@#+#+@@#+@#. ",
" .++++++++@@@@@@@@@@@@@@@%...&*=-=;>...%@@@@@#@@@#@@#+#+@@#++#. ",
" .@+++++++@@@@@@@@@@@@@,...'---------)...,@@@#@@@#@@#@#@@+#++#. ",
" .@+++++++@@@@@@@@@@@@!..~-------------'..!@@#@@@#@@#@#@@+#++#. ",
" .@@+++++@@@@@@@@@@@@{..-----------------..{@###@@##@@###@###+. ",
" .@@@@@+@@@@@@@@@@@@]..-.................-..]@@@@@@@@@@@@@++++. ",
" .@@@@@@@@@@@@@@@@@@..--.^^^^^^^^^^^^^^^.--..@@@@@@@@@@@@@++++. ",
" .@@@@@@@@@@@@@@@@@..'--.^^^^^^^^^^^^^^^.--'..@@@@@@@@@@@@++++. ",
" .@@@@@@@@@@@@@@@@@./---.^^((((((((^(((^.---/.@@@@@@@@@@@@++++. ",
" .@@@@@@@@@@@@@@@@!.)---.((((((((((^^^^^.---).!@@@@@@@@@@@++++. ",
" .@@@@@@@@@@@@@@@@..----.^^(______(^((((.----..@@@@@@@@@@@:+++. ",
" .@@@@@+++@@+++@@@.>----.^^^^^^^^^^^^^^^.----<.@@@@@@@@@@:::++. ",
" .@@@@++@@@@+++@@@._____.^^^^^^^^^^^^^^^._____.@@@@@@@@@:@:+++. ",
" .@@@@@+@@@++++@@@.[----.^^^^^^((((((^(^.----[.@@@@@@@@@:@:@++. ",
" .@@@@@@@@@@@@+@@@._____.^^^(((((((((^^^._____.@@@:@@::@@:::+@. ",
" .@@@@@@@@@@@@@@@@.[----.^^^^^^(____(^((.----[.@@::@:@@:@@:@@@. ",
" .@@@@@@@@@@@@@@@@._____.^^^^^^^^^^^^^^^._____.@:@:@:@@:@@@@@@. ",
" .@@+++@@@@@+@@@@@.>----.^^^^^^^^^^^^^^^.----<.@@@:@:@@:@@@@@@. ",
" .@++++@@@@@++@@@@..----..^^^^^^^^^^^^^..----..@@@:@:@@:@+@@@@. ",
" .@+++@@@@@@++@@@@!.)----..^^^^^^^^^^^..----).{@@@:@:@@:@+@@@@. ",
" .+++@@@@@@@++@@@@@./-----..^^^^^^^^^..-----/.@@@@:@@::@@@@++@. ",
" .@@@@@@@@@@@++@@@@..'-----..^^^^^^^..-----'..@@@@@@@@@@@@@+@@. ",
" .@@@@@@@@@@@@+@@@@@..------..^^^^^..------..@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@}..------..^^^..------..}@@@@@@@@@@@@@@@@@. ",
" .@@@@@@@@@@@@@@@@@@@{..------..^..------..{@@@@@@@@@@@@@@@@@@. ",
" .||||||||||||||||||||1..'-----...-----'..1|||||||||||||||||||. ",
" .2222222222222222222223...'----.----)...422222222222222222222. ",
" .|55|||||55|||||||||||||6...>7[-[;8...9||||||||||||||||||||||. ",
" .5555|||555|||||||||||||||0.........0||||||||||||||||||||||||. ",
" .222555555522222222222222222222a2222222222.......22......2222. ",
" .||5||555||||||||||||||||||||||a||||||||||.bbbbb.||.cccc.||||. ",
" .225555522252222222222222222222a2222222222.bbbbb.22.cccc.2222. ",
" .||5|55|||55|||||||||||||||||||a||||||||||.bbbbb.||.cccc.||||. ",
" .|||5555555||||||||||||||||||||a||||||||||.......||.cccc.||||. ",
" .222555552222222222222222222222a2222222222..d.dd.22.cccc.2222. ",
" .|555555|||||||||||||||||||||||a||||||||||.dd.dd.||.cccc.||||. ",
" .255555522222222222222222222222a2222222222..d.dd.22.cccc.2222. ",
" .5555555|||||||||||||||||||||||a||||||||||.......||......||||. ",
" .5555555||||5||||||5|||||||||||a|||||||||||||||||||||||||||||. ",
" .552555222255555555552222222222a22222222222222222222222222222. ",
" .||||||55|||55||||||555||||||||a|||||||||||||||||||||||||||||. ",
" .222222255555222222225522222222a22222222222222222222222222222. ",
" .||||||||||||||||||||||||||||||a|||||||||||||||||||||||||||||. ",
" .++@@@@@@@@@@@@@@@@@@@@@@@@@@@@a@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .++++@@@@++@@@@@@@@@@@@@@@@@@@@a@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .+++++++@@@+@@@@@@@@@@@@@@@@@@@a@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .+++++++@@@@@@@+++@@@@@@@@@@@@@a@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .+++++++@++@@@@@@++@@@@@@@@@@@@a@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ",
" .eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee. ",
" .eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee. ",
" .eeeeeeefffeeeffeefeefefffeefeeefffeeeefffffeeffeefffeeeeeeee. ",
" .____eeefeefefeefefeefefeefefeeefeeeeeeeefeeefeefefeefeee____. ",
" .eeeeeeefeefefeefefeefefeefefeeefeeeeeeeefeeefeefefeefeeeeeee. ",
" .____eeefeefefeefefeefefefeefeeeffeeeeeeefeeeffffefffeeee____. ",
" .eeeeeeefeefefeefefeefefeefefeeefeeeeeeeefeeefeefefeeeeeeeeee. ",
" .____eeefeefefeefefeefefeefefeeefeeeeeeeefeeefeefefeeeeee____. ",
" .eeeeeeefffeeeffeeeffeefffeefffefffeeeeeefeeefeefefeeeeeeeeee. ",
" .eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee. ",
" .eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee. ",
" .............................................................. "};

View file

@ -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/18 13:51:33 by kcolin ### ########.fr */ /* Updated: 2025/08/19 20:07:29 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,9 +37,11 @@
# define MAX_SPRITES 30 # define MAX_SPRITES 30
# define JUGG_TEX "ressources/juggernog.xpm" # define JUGG_TEX "ressources/juggernog.xpm"
# define REV_TEX "ressources/revive.xpm" # define REV_TEX "ressources/revive.xpm"
# define DBLTAP_TEX "ressources/doubletap.xpm" # define DBLTAP_TEX "ressources/dbltap.xpm"
# define MYSTERY_TEX "ressources/box.xpm" # define MYSTERY_TEX "ressources/box.xpm"
# define ZOMBIE_TEX "ressources/zombie.xpm" # define ZOMBIE_TEX "ressources/zombie.xpm"
// Approximated, value is actually MOVEMENT_SPEED / 1.5
# define ZOMBIE_SPEED 0.0000033333
# ifdef BONUS # ifdef BONUS
# define COMPILED_TEXT "Compiled with bonuses" # define COMPILED_TEXT "Compiled with bonuses"

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/18 20:05:29 by tchampio ### ########.fr */ /* Updated: 2025/08/20 13:52:42 by kcolin ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,7 +21,7 @@
#include "raycast/ray.h" #include "raycast/ray.h"
#include "sprites/sprite_caster.h" #include "sprites/sprite_caster.h"
#include "utils/inits.h" #include "utils/inits.h"
#include "sprites/sprite.h" #include "utils/frees.h"
#include "utils/hooks.h" #include "utils/hooks.h"
#include "utils/inits.h" #include "utils/inits.h"
#include <bits/types/struct_timeval.h> #include <bits/types/struct_timeval.h>
@ -59,6 +59,12 @@ int game_loop(t_cub3d_data *data)
return (0); return (0);
} }
int good_bye(void *data)
{
destroy(data, 0);
return (0);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
t_cub3d_data data; t_cub3d_data data;
@ -72,6 +78,7 @@ int main(int argc, char **argv)
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);
mlx_hook(data.mlx_win, DestroyNotify, NoEventMask, good_bye, &data);
mlx_loop_hook(data.mlx, game_loop, &data); mlx_loop_hook(data.mlx, game_loop, &data);
mlx_loop(data.mlx); mlx_loop(data.mlx);
} }

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/06 11:25:05 by kcolin #+# #+# */ /* Created: 2025/08/06 11:25:05 by kcolin #+# #+# */
/* Updated: 2025/08/06 11:49:00 by kcolin ### ########.fr */ /* Updated: 2025/08/20 12:47:52 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,22 +17,22 @@ static bool out_of_bounds(t_mapdata *data, int x, int y)
{ {
if (x < 0 if (x < 0
|| y < 0 || y < 0
|| x >= data->mapheight || y >= data->mapheight
|| y > (int)ft_strlen(data->map[x])) || x > (int)ft_strlen(data->map[y]))
return (true); return (true);
return (false); return (false);
} }
bool blocks_movement(t_mapdata *data, int x, int y) bool blocks_movement(t_mapdata *data, int x, int y)
{ {
if (out_of_bounds(data, x, y) || data->map[x][y] == '1') if (out_of_bounds(data, x, y) || data->map[y][x] == '1')
return (true); return (true);
return (false); return (false);
} }
bool blocks_view(t_mapdata *data, int x, int y) bool blocks_view(t_mapdata *data, int x, int y)
{ {
if (out_of_bounds(data, x, y) || data->map[x][y] == '1') if (out_of_bounds(data, x, y) || data->map[y][x] == '1')
return (true); return (true);
return (false); return (false);
} }

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/08 14:06:37 by kcolin #+# #+# */ /* Created: 2025/08/08 14:06:37 by kcolin #+# #+# */
/* Updated: 2025/08/12 12:16:17 by kcolin ### ########.fr */ /* Updated: 2025/08/20 12:43:23 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -42,16 +42,16 @@ bool move_forward_step(t_cub3d_data *data, double mov_x, double mov_y)
blocks = 2; blocks = 2;
x_step = calc_step(mov_x); x_step = calc_step(mov_x);
y_step = calc_step(mov_y); y_step = calc_step(mov_y);
if (!blocks_movement(data->map, (int)data->player.y, if (!blocks_movement(data->map, (int)data->player.x,
(int)(data->player.x + x_step))) (int)(data->player.y + y_step)))
{ {
data->player.x += x_step; data->player.y += y_step;
blocks--; blocks--;
} }
if (!blocks_movement(data->map, if (!blocks_movement(data->map,
(int)(data->player.y + y_step), (int)data->player.x)) (int)(data->player.x + x_step), (int)data->player.y))
{ {
data->player.y += y_step; data->player.x += x_step;
blocks--; blocks--;
} }
return (blocks < 2); return (blocks < 2);
@ -66,16 +66,16 @@ bool move_backward_step(t_cub3d_data *data, double mov_x, double mov_y)
blocks = 2; blocks = 2;
x_step = calc_step(mov_x); x_step = calc_step(mov_x);
y_step = calc_step(mov_y); y_step = calc_step(mov_y);
if (!blocks_movement(data->map, (int)data->player.y, if (!blocks_movement(data->map, (int)data->player.x,
(int)(data->player.x - x_step))) (int)(data->player.y - y_step)))
{ {
data->player.x -= x_step; data->player.y -= y_step;
blocks--; blocks--;
} }
if (!blocks_movement(data->map, if (!blocks_movement(data->map,
(int)(data->player.y - y_step), (int)data->player.x)) (int)(data->player.x - x_step), (int)data->player.y))
{ {
data->player.y -= y_step; data->player.x -= x_step;
blocks--; blocks--;
} }
return (blocks < 2); return (blocks < 2);
@ -90,16 +90,16 @@ bool move_strafe_left_step(t_cub3d_data *data, double mov_x, double mov_y)
blocks = 2; blocks = 2;
x_step = calc_step(mov_x); x_step = calc_step(mov_x);
y_step = calc_step(mov_y); y_step = calc_step(mov_y);
if (!blocks_movement(data->map, (int)data->player.y, if (!blocks_movement(data->map, (int)data->player.x,
(int)(data->player.x - x_step))) (int)(data->player.y - y_step)))
{ {
data->player.x -= x_step; data->player.y -= y_step;
blocks--; blocks--;
} }
if (!blocks_movement(data->map, if (!blocks_movement(data->map,
(int)(data->player.y - y_step), (int)data->player.x)) (int)(data->player.x - x_step), (int)data->player.y))
{ {
data->player.y -= y_step; data->player.x -= x_step;
blocks--; blocks--;
} }
return (blocks < 2); return (blocks < 2);
@ -114,17 +114,17 @@ bool move_strafe_right_step(t_cub3d_data *data, double mov_x, double mov_y)
blocks = 2; blocks = 2;
x_step = calc_step(mov_x); x_step = calc_step(mov_x);
y_step = calc_step(mov_y); y_step = calc_step(mov_y);
if (!blocks_movement(data->map, (int)data->player.y, if (!blocks_movement(data->map, (int)data->player.x,
(int)(data->player.x + x_step))) (int)(data->player.y + y_step)))
{
data->player.x += x_step;
blocks--;
}
if (!blocks_movement(data->map,
(int)(data->player.y + y_step), (int)data->player.x))
{ {
data->player.y += y_step; data->player.y += y_step;
blocks--; blocks--;
} }
if (!blocks_movement(data->map,
(int)(data->player.x + x_step), (int)data->player.y))
{
data->player.x += x_step;
blocks--;
}
return (blocks < 2); return (blocks < 2);
} }

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */ /* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
/* Updated: 2025/08/06 14:02:40 by tchampio ### ########.fr */ /* Updated: 2025/08/20 12:48:06 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,7 +70,7 @@ void calculate_wall_dist(t_ray *ray, t_mapdata *map)
ray->map_y += ray->step_y; ray->map_y += ray->step_y;
ray->side = SOUTH; ray->side = SOUTH;
} }
if (blocks_view(map, ray->map_y, ray->map_x)) if (blocks_view(map, ray->map_x, ray->map_y))
break ; break ;
} }
if (ray->side == NORTH) if (ray->side == NORTH)

View file

@ -6,38 +6,51 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */ /* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/18 13:22:50 by kcolin #+# #+# */ /* Created: 2025/08/18 13:22:50 by kcolin #+# #+# */
/* Updated: 2025/08/18 19:51:41 by tchampio ### ########.fr */ /* Updated: 2025/08/20 12:38:53 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "move_sprites.h" #include "move_sprites.h"
#include "../map/collision.h"
#include "sprite.h" #include "sprite.h"
#include "../../libft/includes/libft.h"
#include <math.h> #include <math.h>
void make_move(t_cub3d_data *data, t_sprite *sprite)
{
double dx;
double dy;
double dist;
double future_x;
double future_y;
future_x = sprite->x;
future_y = sprite->y;
dx = data->player.x - sprite->x;
dy = data->player.y - sprite->y;
dist = sqrt(dx * dx + dy * dy);
if (dist > 0.4)
{
dx /= dist;
dy /= dist;
future_x += dx * ZOMBIE_SPEED * data->delta;
future_y += dy * ZOMBIE_SPEED * data->delta;
if (!blocks_movement(data->map, (int)sprite->x, (int)future_y))
sprite->y = future_y;
if (!blocks_movement(data->map, (int)future_x, (int)sprite->y))
sprite->x = future_x;
}
}
void move_sprites(t_cub3d_data *data) void move_sprites(t_cub3d_data *data)
{ {
int i; int i;
double dx;
double dy;
double dist;
static double zombie_movement = MOVEMENT_SPEED / 1.5;
i = 0; i = 0;
while (i < data->sprite_counter) while (i < data->sprite_counter)
{ {
if (data->sprite_list[i]->sprite_type == ZOMBIE) if (data->sprite_list[i]->sprite_type == ZOMBIE)
{ {
dx = data->player.x - data->sprite_list[i]->x; make_move(data, data->sprite_list[i]);
dy = data->player.y - data->sprite_list[i]->y;
dist = sqrt(dx * dx + dy * dy);
if (dist > 0.0001)
{
dx /= dist;
dy /= dist;
data->sprite_list[i]->x += dx * zombie_movement * data->delta;
data->sprite_list[i]->y += dy * zombie_movement * data->delta;
}
} }
i++; i++;
} }

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/18 13:39:26 by tchampio ### ########.fr */ /* Updated: 2025/08/19 19:42:43 by tchampio ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,6 @@
#include "../renderer/render.h" #include "../renderer/render.h"
#include "sort_sprites.h" #include "sort_sprites.h"
#include <math.h> #include <math.h>
#include <stdlib.h>
#include "../../libft/includes/libft.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,
@ -73,6 +72,8 @@ static void render_sprite_col(t_cub3d_data *data, int i, int tex_x, int stripe)
d = (j) * 256 - HEIGHT * 128 d = (j) * 256 - HEIGHT * 128
+ data->sprite_list[i]->sprite_height * 128; + data->sprite_list[i]->sprite_height * 128;
tex_y = ((d * SIZE) / data->sprite_list[i]->sprite_height) / 256; tex_y = ((d * SIZE) / data->sprite_list[i]->sprite_height) / 256;
if (tex_y < 0)
tex_y = 0;
color = my_mlx_pixel_get( color = my_mlx_pixel_get(
data->sprite_list[data->sprite_order[i]]->image, data->sprite_list[data->sprite_order[i]]->image,
tex_x, tex_y); tex_x, tex_y);
@ -94,6 +95,8 @@ static void render_sprites(t_cub3d_data *data, int i)
- (-data->sprite_list[i]->sprite_width / 2 - (-data->sprite_list[i]->sprite_width / 2
+ data->sprite_list[i]->sprite_screen_x)) + data->sprite_list[i]->sprite_screen_x))
* SIZE / data->sprite_list[i]->sprite_width) / 256; * SIZE / data->sprite_list[i]->sprite_width) / 256;
if (tex_x < 0)
tex_x = 0;
if (data->sprite_list[i]->transform_y > 0 && stripe > 0 if (data->sprite_list[i]->transform_y > 0 && stripe > 0
&& stripe < WIDTH && stripe < WIDTH
&& data->sprite_list[i]->transform_y < data->zbuffer[stripe]) && data->sprite_list[i]->transform_y < data->zbuffer[stripe])