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

@ -0,0 +1,22 @@
NO ./path_to_the_north_texture
SO ./path_to_the_south_texture
WE ./path_to_the_west_texture
EA ./path_to_the_east_texture
F 220,100,0
C 225,30,0
1111111111111111111111111
1000000000110000000000001
1011000001110000001000001
1001000000000000010000001
111111111011000001110000100000001
100000000011000001110111110111111
11110111111111011100000010001
11110111111111011101010010001
11000000110101011100000010001
10000000000000001100000010001
10000000000000001101010010001
11000001110101011111011110N0111
11110111 1110101 101111010001
11111111 1111111 111111111111

View file

@ -15,8 +15,10 @@
# define HEIGHT 800
# define WIDTH 800
# define SIZE 64
# define MAP_SIZE 10
# define RESSOURCE_DIR "ressources"
# define MOVEMENT_SPEED 0.1
# define MOVEMENT_SPEED 6.4
# define ROTATION_SPEED 0.1
# ifdef BONUS
# define COMPILED_TEXT "Compiled with bonuses"

View file

@ -13,19 +13,19 @@
#include "../map/mapdata.h"
#include "../player/player.h"
#include "drawutils.h"
#include "../consts.h"
void draw_2d_wall(unsigned int color, t_img_data *data,
int x, int y)
{
int i;
int j;
static int size = 10;
i = 0;
while (i < size)
while (i < MAP_SIZE)
{
j = 0;
while (j < size)
while (j < MAP_SIZE)
{
my_mlx_pixel_put(data, x + i, y + j, color);
j++;
@ -46,18 +46,18 @@ void draw_map(t_mapdata *map, t_player *player, t_img_data *data)
while (map->map[i][j])
{
if (map->map[i][j] == '1')
draw_2d_wall(map->f_color, data, 10 * j, 10 * i);
draw_2d_wall(map->f_color, data, MAP_SIZE * j, MAP_SIZE * i);
else if (map->map[i][j] == 'Z' || map->map[i][j] == 'z')
draw_2d_wall(0x0008D9D6, data, 10 * j, 10 * i);
draw_2d_wall(0x0008D9D6, data, MAP_SIZE * j, MAP_SIZE * i);
else if (map->map[i][j] == 'D' || map->map[i][j] == 'd')
draw_2d_wall(0x00FF2E63, data, 10 * j, 10 * i);
draw_2d_wall(0x00FF2E63, data, MAP_SIZE * j, MAP_SIZE * i);
else if (map->map[i][j] == 's')
draw_2d_wall(0x00E84545, data, 10 * j, 10 * i);
draw_2d_wall(0x00E84545, data, MAP_SIZE * j, MAP_SIZE * i);
else if (map->map[i][j] == 'M')
draw_2d_wall(0x00F4CE14, data, 10 * j, 10 * i);
draw_2d_wall(0x00F4CE14, data, MAP_SIZE * j, MAP_SIZE * i);
j++;
}
i++;
}
draw_2d_wall(0x00FF0000, data, 10 * player->x, 10 * player->y);
draw_2d_wall(0x00FF0000, data, MAP_SIZE * (player->x / SIZE), MAP_SIZE * (player->y / SIZE));
}

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);