feat: send single ray

This commit is contained in:
Khaïs COLIN 2025-07-28 12:16:26 +02:00 committed by freddy_vqr
parent ff07c5cea1
commit 805ddbab0b
4 changed files with 71 additions and 13 deletions

View file

@ -6,15 +6,17 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */
/* Updated: 2025/07/24 14:31:07 by tchampio ### ########.fr */
/* Updated: 2025/07/28 12:57:08 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft/includes/libft.h"
#include "../mlx/mlx.h"
#include "consts.h"
#include "draw/drawutils.h"
#include "map/map_checker.h"
#include "draw/draw_map.h"
#include "map/mapdata.h"
#include "utils/hooks.h"
#include "utils/frees.h"
#include <stdbool.h>
@ -27,8 +29,8 @@
void init_player(t_mapdata *mapdata, t_player *player)
{
player->health = 100;
player->x = mapdata->startx;
player->y = mapdata->starty;
player->x = mapdata->startx * SIZE;
player->y = mapdata->starty * SIZE;
if (mapdata->map[mapdata->starty][mapdata->startx] == 'N')
player->yaw = M_PI;
else if (mapdata->map[mapdata->starty][mapdata->startx] == 'S')
@ -39,10 +41,42 @@ void init_player(t_mapdata *mapdata, t_player *player)
player->yaw = 3 * M_PI / 2;
}
bool touch(float px, float py, t_mapdata *map)
{
int x;
int y;
x = px / SIZE;
y = py / SIZE;
if (map->map[y][x] == '1')
return (true);
return (false);
}
int game_loop(t_cub3d_data *data)
{
mlx_destroy_image(data->mlx, data->img_data->img);
data->img_data->img = mlx_new_image(data->mlx, WIDTH, HEIGHT);
int column = 0;
while (column < 1)
{
// calculate angle
double cos_angle = cos(data->player.yaw);
double sin_angle = sin(data->player.yaw);
double ray_x = data->player.x;
double ray_y = data->player.y;
while (!touch(ray_x, ray_y, data->map))
{
my_mlx_pixel_put(data->img_data, (int)(MAP_SIZE * (ray_x / SIZE)), (int)(MAP_SIZE * (ray_y / SIZE)), 0xFF0000);
ray_x += sin_angle;
ray_y += cos_angle;
}
// calculate distance
// draw
column++;
}
draw_map(data->map, &data->player, data->img_data);
mlx_put_image_to_window(data->mlx, data->mlx_win,
data->img_data->img, 0, 0);