mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
Compare commits
3 commits
351e4bb679
...
f325eb3dbf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f325eb3dbf | ||
|
|
94fd8779e2 | ||
|
|
5cc6988c9c |
11 changed files with 80 additions and 60 deletions
1
Makefile
1
Makefile
|
|
@ -34,6 +34,7 @@ SOURCEFILES = \
|
|||
src/player/pay.c \
|
||||
src/raycast/barricades.c \
|
||||
src/raycast/ray.c \
|
||||
src/raycast/ray2.c \
|
||||
src/raycast/walls.c \
|
||||
src/raycast/zombie_checker.c \
|
||||
src/renderer/render.c \
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ C 225,30,0
|
|||
1011000001110000z00000001
|
||||
10D1000000000000000000001
|
||||
111111111011000001110M00000000001
|
||||
10000000001100000111011111d111111
|
||||
10000000001100000111011111P111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ typedef struct s_cub3d_data
|
|||
t_mapdata *map;
|
||||
t_player player;
|
||||
t_keypresses keypresses;
|
||||
int door_amount;
|
||||
int *screen_matrix;
|
||||
int last_since_shoot; // temp
|
||||
int delta;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ static bool out_of_bounds(t_mapdata *data, int x, int y)
|
|||
|
||||
bool blocks_movement(t_mapdata *data, int x, int y)
|
||||
{
|
||||
if (out_of_bounds(data, x, y) || ft_strchr("12345678d", data->map[y][x]))
|
||||
if (out_of_bounds(data, x, y) || ft_strchr("12345678dP", data->map[y][x]))
|
||||
return (true);
|
||||
return (false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,15 +13,7 @@
|
|||
#include "../cub3d_data.h"
|
||||
#include "../../libft/includes/libft.h"
|
||||
|
||||
int door_amount(void)
|
||||
{
|
||||
static int amount = 500;
|
||||
|
||||
amount += 250;
|
||||
return (amount);
|
||||
}
|
||||
|
||||
bool pay(t_cub3d_data *data, int amount)
|
||||
bool pay(t_cub3d_data *data, int amount, bool isdoor)
|
||||
{
|
||||
if (data->player.points < amount)
|
||||
{
|
||||
|
|
@ -29,5 +21,7 @@ bool pay(t_cub3d_data *data, int amount)
|
|||
return (false);
|
||||
}
|
||||
data->player.points -= amount;
|
||||
if (isdoor)
|
||||
data->door_amount += 250;
|
||||
return (true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
# include "../cub3d_data.h"
|
||||
|
||||
int door_amount(void);
|
||||
bool pay(t_cub3d_data *data, int amount);
|
||||
bool pay(t_cub3d_data *data, int amount, bool isdoor);
|
||||
|
||||
#endif // PAY_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
|
||||
/* Updated: 2025/10/01 14:10:46 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/10/02 00:10:20 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,10 +19,7 @@
|
|||
#include "../cub3d_data.h"
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "../map/collision.h"
|
||||
#include "../player/pay.h"
|
||||
#include "../../libft/includes/libft.h"
|
||||
|
||||
void init_ray(t_ray *ray, int pos_x, t_player *player)
|
||||
{
|
||||
|
|
@ -59,53 +56,16 @@ void ray_calculate_step(t_ray *ray, t_player *player)
|
|||
}
|
||||
}
|
||||
|
||||
void handle_door_ray(t_ray *ray, t_cub3d_data *data)
|
||||
{
|
||||
if ((data->map->map[ray->map_y][ray->map_x] == 'd' || data->map->map[ray->map_y][ray->map_x] == 'i' || data->map->map[ray->map_y][ray->map_x] == 'P') && ray->wall_dist < 1.5)
|
||||
{
|
||||
ft_printf("map[%d][%d] = door reachable\n", ray->map_y, ray->map_x);
|
||||
data->player.closest_door[0] = ray->map_x;
|
||||
data->player.closest_door[1] = ray->map_y;
|
||||
data->player.can_open_door = true;
|
||||
if (data->keypresses.is_f_pressed)
|
||||
{
|
||||
data->keypresses.is_f_pressed = false;
|
||||
if (data->map->map[ray->map_y][ray->map_x] == 'd')
|
||||
data->map->map[ray->map_y][ray->map_x] = 'i';
|
||||
else if (data->map->map[ray->map_y][ray->map_x] == 'P' && pay(data, door_amount()))
|
||||
data->map->map[ray->map_y][ray->map_x] = '0';
|
||||
else if (data->map->map[ray->map_y][ray->map_x] == 'i')
|
||||
data->map->map[ray->map_y][ray->map_x] = 'd';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data->player.closest_door[0] = -1;
|
||||
data->player.closest_door[1] = -1;
|
||||
data->player.can_open_door = false;
|
||||
}
|
||||
}
|
||||
|
||||
void calculate_wall_dist(t_ray *ray, int x, t_cub3d_data *data)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (x == WIDTH / 2)
|
||||
check_for_zombies(ray, data);
|
||||
if (!blocks_view(data->map, ray->map_x, ray->map_y) && data->map->map[ray->map_y][ray->map_x] == 'i')
|
||||
if (!blocks_view(data->map, ray->map_x, ray->map_y)
|
||||
&& data->map->map[ray->map_y][ray->map_x] == 'i')
|
||||
handle_door_ray(ray, data);
|
||||
if (ray->side_dist_x < ray->side_dist_y)
|
||||
{
|
||||
ray->side_dist_x += ray->delta_dist_x;
|
||||
ray->map_x += ray->step_x;
|
||||
ray->side = NORTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
ray->side_dist_y += ray->delta_dist_y;
|
||||
ray->map_y += ray->step_y;
|
||||
ray->side = SOUTH;
|
||||
}
|
||||
step_ray(ray);
|
||||
if (blocks_view(data->map, ray->map_x, ray->map_y))
|
||||
{
|
||||
if (x == WIDTH / 2)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/08/05 12:49:49 by kcolin #+# #+# */
|
||||
/* Updated: 2025/09/09 14:01:28 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/10/02 00:11:01 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
# include "../map/mapdata.h"
|
||||
# define BARRICADE_TICK 55000
|
||||
# include "../cub3d_data.h"
|
||||
|
||||
/*
|
||||
* plane - plan de camera (vectoriel)
|
||||
|
|
@ -53,4 +54,7 @@ typedef struct s_ray
|
|||
double wall_x;
|
||||
} t_ray;
|
||||
|
||||
void handle_door_ray(t_ray *ray, t_cub3d_data *data);
|
||||
void step_ray(t_ray *ray);
|
||||
|
||||
#endif // RAY_H
|
||||
|
|
|
|||
60
src/raycast/ray2.c
Normal file
60
src/raycast/ray2.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ray2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/02 00:09:16 by tchampio #+# #+# */
|
||||
/* Updated: 2025/10/02 00:11:51 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ray.h"
|
||||
#include "../../libft/includes/libft.h"
|
||||
#include "../player/pay.h"
|
||||
|
||||
void handle_door_ray(t_ray *ray, t_cub3d_data *data)
|
||||
{
|
||||
char current_tile;
|
||||
|
||||
current_tile = data->map->map[ray->map_y][ray->map_x];
|
||||
if (ft_strchr("diP", current_tile) && ray->wall_dist < 1.5)
|
||||
{
|
||||
data->player.closest_door[0] = ray->map_x;
|
||||
data->player.closest_door[1] = ray->map_y;
|
||||
data->player.can_open_door = true;
|
||||
if (data->keypresses.is_f_pressed)
|
||||
{
|
||||
data->keypresses.is_f_pressed = false;
|
||||
if (current_tile == 'd')
|
||||
data->map->map[ray->map_y][ray->map_x] = 'i';
|
||||
else if (current_tile == 'P' && pay(data, data->door_amount, true))
|
||||
data->map->map[ray->map_y][ray->map_x] = '0';
|
||||
else if (current_tile == 'i')
|
||||
data->map->map[ray->map_y][ray->map_x] = 'd';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data->player.closest_door[0] = -1;
|
||||
data->player.closest_door[1] = -1;
|
||||
data->player.can_open_door = false;
|
||||
}
|
||||
}
|
||||
|
||||
void step_ray(t_ray *ray)
|
||||
{
|
||||
if (ray->side_dist_x < ray->side_dist_y)
|
||||
{
|
||||
ray->side_dist_x += ray->delta_dist_x;
|
||||
ray->map_x += ray->step_x;
|
||||
ray->side = NORTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
ray->side_dist_y += ray->delta_dist_y;
|
||||
ray->map_y += ray->step_y;
|
||||
ray->side = SOUTH;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
|
||||
/* Updated: 2025/10/01 14:12:44 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/10/01 23:00:52 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ static int get_color(t_cub3d_data *data, t_ray *ray, int tex_y)
|
|||
if (ft_strchr("234567", data->map->map[ray->map_y][ray->map_x]))
|
||||
return (my_mlx_pixel_get(get_right_barricade(data,
|
||||
data->map->map[ray->map_y][ray->map_x]), tex_x, tex_y));
|
||||
if (data->map->map[ray->map_y][ray->map_x] == 'd' || data->map->map[ray->map_y][ray->map_x] == 'P')
|
||||
if (ft_strchr("dP", data->map->map[ray->map_y][ray->map_x]))
|
||||
return (my_mlx_pixel_get(data->door_texture, tex_x, tex_y));
|
||||
if (dir == NORTH)
|
||||
texture = data->no_texture;
|
||||
|
|
|
|||
|
|
@ -113,5 +113,6 @@ void init_cub3d_data(t_cub3d_data *data, char **argv)
|
|||
load_textures(data);
|
||||
data->sprite_list = ft_calloc(sizeof(t_sprite *), MAX_SPRITES);
|
||||
ft_memset(data->sprite_distances, -1, MAX_SPRITES);
|
||||
data->door_amount = 750;
|
||||
place_base_sprites(data, data->map->map);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue