add textures and more fluidity
This commit is contained in:
parent
a2ecf32195
commit
9fba725d19
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 16:30:59 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/11 20:33:40 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/13 23:22:21 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -39,6 +39,7 @@ typedef struct ray_info{
|
||||
int index;
|
||||
int wall_type;
|
||||
int pixel;
|
||||
char texture_type;
|
||||
|
||||
} ray;
|
||||
|
||||
@ -77,6 +78,9 @@ typedef struct player_position
|
||||
double angle;
|
||||
double vx;
|
||||
double vy;
|
||||
int front;
|
||||
int side;
|
||||
int angle_side;
|
||||
} player;
|
||||
|
||||
typedef struct s_data {
|
||||
|
||||
17
map/real_subject.cub
Normal file
17
map/real_subject.cub
Normal file
@ -0,0 +1,17 @@
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
20
map/subject_magma.cub
Normal file
20
map/subject_magma.cub
Normal file
@ -0,0 +1,20 @@
|
||||
NO ./sprite/magma_shade.ppm
|
||||
SO ./sprite/magma_shade.ppm
|
||||
EA ./sprite/magma_shade.ppm
|
||||
WE ./sprite/magma_shade.ppm
|
||||
|
||||
|
||||
1111111111111111111111111
|
||||
1000000000110000000000001
|
||||
1011000001110000000000001
|
||||
1001000000000000000000001
|
||||
111111111011000001110000000000001
|
||||
100000000011000001110111111111111
|
||||
11110111111111011100000010001
|
||||
11110111111111011101010010001
|
||||
11000000110101011100000010001
|
||||
10000000000000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
@ -1,7 +1,7 @@
|
||||
NO ./sprite/brick_wall.ppm
|
||||
SO ./sprite/brick_wall.ppm
|
||||
EA ./sprite/brick_wall.ppm
|
||||
WE ./sprite/brick_wall.ppm
|
||||
SO ./sprite/magma.ppm
|
||||
EA ./sprite/obsidian.ppm
|
||||
WE ./sprite/glowstone.ppm
|
||||
|
||||
|
||||
1111111111111111111111111
|
||||
|
||||
12290
sprite/cobblestone.ppm
Normal file
12290
sprite/cobblestone.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/glowstone.ppm
Normal file
12290
sprite/glowstone.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/magma.ppm
Normal file
12290
sprite/magma.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/magma_shade.ppm
Normal file
12290
sprite/magma_shade.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/mossy_cobblestone.ppm
Normal file
12290
sprite/mossy_cobblestone.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/mossy_stone_bricks.ppm
Normal file
12290
sprite/mossy_stone_bricks.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/obsidian.ppm
Normal file
12290
sprite/obsidian.ppm
Normal file
File diff suppressed because it is too large
Load Diff
12290
sprite/stone_bricks.ppm
Normal file
12290
sprite/stone_bricks.ppm
Normal file
File diff suppressed because it is too large
Load Diff
@ -148,26 +148,43 @@ void draw_ray3d(t_data *img, ray ray)
|
||||
my = (int)myy;//gap;
|
||||
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
||||
x = -1;
|
||||
if (ray.pixel >= 12290)//here read
|
||||
color = 0;
|
||||
if (ray.pixel >= 12290 || ray.pixel < 0)//here read
|
||||
return ;
|
||||
else if (ray.pixel > 0)
|
||||
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);//here read
|
||||
{
|
||||
if (ray.texture_type == 'N' && img->map.texture.north)
|
||||
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);
|
||||
else if (ray.texture_type == 'S' && img->map.texture.south)
|
||||
color = get_color(img->map.texture.south[ray.pixel], img->map.texture.south[ray.pixel + 1], img->map.texture.south[ray.pixel + 2]);
|
||||
else if (ray.texture_type == 'W' && img->map.texture.west)
|
||||
color = get_color(img->map.texture.west[ray.pixel], img->map.texture.west[ray.pixel + 1], img->map.texture.west[ray.pixel + 2]);
|
||||
else if (ray.texture_type == 'E' && img->map.texture.east)
|
||||
color = get_color(img->map.texture.east[ray.pixel], img->map.texture.east[ray.pixel + 1], img->map.texture.east[ray.pixel + 2]);
|
||||
else
|
||||
color = get_color(img->map.texture.basic[ray.pixel], img->map.texture.basic[ray.pixel + 1], img->map.texture.basic[ray.pixel + 2]);//here read
|
||||
}
|
||||
else
|
||||
color = 0;
|
||||
while (++x < /*img->map.x / 2*/4)
|
||||
{
|
||||
if (ray.wall_type)//here read
|
||||
{
|
||||
//if (ray.wall_type)//here read
|
||||
//{
|
||||
//mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , color);
|
||||
set_pixel(img, color, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
|
||||
//set_pixel(img, color, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
//mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , (color >> 1) & 8355711);
|
||||
set_pixel(img, (color >> 1) & 8355711, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
|
||||
//set_pixel(img, (color >> 1) & 8355711, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
}
|
||||
//}
|
||||
// if (ray.wall_type)//here read
|
||||
// {
|
||||
// //mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , color);
|
||||
// set_pixel(img, color, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
|
||||
// //set_pixel(img, color, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //mlx_pixel_put(img->mlx, img->mlx_win, ray.index * 4 + x, y + line_offset , (color >> 1) & 8355711);
|
||||
// set_pixel(img, (color >> 1) & 8355711, ray.index * /*(img->map.x / 2)*/4 + x, y + line_offset);
|
||||
// //set_pixel(img, (color >> 1) & 8355711, ray.index * (img->map.x / 2) + x, y + line_offset);
|
||||
// }
|
||||
}
|
||||
y++;
|
||||
}
|
||||
@ -192,6 +209,9 @@ void draw_ray(t_data *img)
|
||||
int my = 0;
|
||||
int mx = 0;
|
||||
int mp = 0;
|
||||
char vertical_type;
|
||||
char horizontal_type;
|
||||
//char texture_type;
|
||||
|
||||
void *new_img;
|
||||
int bits_per_pixel = 0;
|
||||
@ -233,6 +253,7 @@ void draw_ray(t_data *img)
|
||||
ray_y = (img->player.x - ray_x) * aTan + img->player.y;
|
||||
next_x = 64;
|
||||
next_y = -next_x * aTan;
|
||||
vertical_type = 'W';
|
||||
}
|
||||
else if (cos(deg_to_rad(ray_angle)) < -0.001)//looking right
|
||||
{
|
||||
@ -240,6 +261,7 @@ void draw_ray(t_data *img)
|
||||
ray_y = (img->player.x - ray_x) * aTan + img->player.y;
|
||||
next_x = -64;
|
||||
next_y = -next_x * aTan;
|
||||
vertical_type = 'E';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -281,6 +303,7 @@ void draw_ray(t_data *img)
|
||||
ray_x = (img->player.y - ray_y) * aTan + img->player.x;
|
||||
next_y = -64;
|
||||
next_x = -next_y * aTan;
|
||||
horizontal_type = 'N';
|
||||
}
|
||||
else if (sin(deg_to_rad(ray_angle))<-0.001)//looking down
|
||||
{
|
||||
@ -288,6 +311,7 @@ void draw_ray(t_data *img)
|
||||
ray_x = (img->player.y - ray_y) * aTan + img->player.x;
|
||||
next_y = 64;
|
||||
next_x = -next_y * aTan;
|
||||
horizontal_type = 'S';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -317,6 +341,7 @@ void draw_ray(t_data *img)
|
||||
ray ray_info;
|
||||
|
||||
wall_type = 0;
|
||||
ray_info.texture_type = 0;
|
||||
if (dist_h != -1 && (dist_h < dist_v || dist_v == -1))
|
||||
{
|
||||
//print_ray2(img, cos(deg_to_rad(ray_angle)), -sin(deg_to_rad(ray_angle)), fabs(dist_h));
|
||||
@ -324,6 +349,7 @@ void draw_ray(t_data *img)
|
||||
//printf("rx= %f ry= %f\n", ray_x, ray_y);
|
||||
ray_info.mp = ray_x;
|
||||
wall_type = 0;
|
||||
ray_info.texture_type = horizontal_type;
|
||||
}
|
||||
else if (dist_v != -1)
|
||||
{
|
||||
@ -334,6 +360,7 @@ void draw_ray(t_data *img)
|
||||
ray_info.mp = vy;
|
||||
//print_ray2(img, cos(deg_to_rad(ray_angle)), -sin(deg_to_rad(ray_angle)), fabs(dist_v));
|
||||
wall_type = 1;
|
||||
ray_info.texture_type = vertical_type;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -346,8 +373,9 @@ void draw_ray(t_data *img)
|
||||
ray_info.index = nb_ray;
|
||||
ray_info.wall_type = wall_type;
|
||||
int ca = reset_angle(img->player.angle - ray_angle); //fisheye
|
||||
dist_f = dist_f * cos(deg_to_rad(ca));
|
||||
ray_info.dist = dist_f; //fisheye
|
||||
dist_f = dist_f * cos(deg_to_rad(ca)); //fisheye
|
||||
ray_info.dist = dist_f;
|
||||
if (dist_f > 0)
|
||||
draw_ray3d(img, ray_info);
|
||||
ray_angle = reset_angle(ray_angle - 0.25);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/06 16:10:11 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/13 01:49:43 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/13 20:41:01 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -89,7 +89,7 @@ unsigned char *get_texture(char type, char *path, t_data *img)
|
||||
// printf("c= %d ", ret[count]);
|
||||
count++;
|
||||
}
|
||||
printf("texture size = %d\n", count);
|
||||
//printf("texture size = %d\n", count);
|
||||
close(fd);
|
||||
put_texture_in_struct(type, ret, img);
|
||||
return (ret);
|
||||
|
||||
57
srcs/main.c
57
srcs/main.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 16:42:55 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/12 21:54:23 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/14 00:10:50 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -50,7 +50,7 @@ void set_map(t_data *img)
|
||||
mlx_destroy_image(img->mlx_test, buffer);
|
||||
}
|
||||
|
||||
/*void print_map(map_info map, t_data *img)
|
||||
void print_map(map_info map, t_data *img)
|
||||
{
|
||||
int i = 0;
|
||||
int j;
|
||||
@ -91,6 +91,47 @@ void print_line(t_data *img, double x, double y)
|
||||
mlx_destroy_image(img->mlx_test, buffer);
|
||||
}*/
|
||||
|
||||
int key_pressed(int type, t_data *img)
|
||||
{
|
||||
if (type == 'w')
|
||||
img->player.front = 1;
|
||||
else if (type == 's')
|
||||
img->player.front = -1;
|
||||
else if (type == 'a')
|
||||
img->player.side = -1;
|
||||
else if (type == 'd')
|
||||
img->player.side = 1;
|
||||
else if (type == 65361)//fleche gauche
|
||||
img->player.angle_side = -1;
|
||||
else if (type == 65363)//fleche droite
|
||||
img->player.angle_side = 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int key_released(int type, t_data *img)
|
||||
{
|
||||
if (type == 'w')
|
||||
img->player.front = 0;
|
||||
else if (type == 's')
|
||||
img->player.front = 0;
|
||||
else if (type == 'a')
|
||||
img->player.side = 0;
|
||||
else if (type == 'd')
|
||||
img->player.side = 0;
|
||||
else if (type == 65361)//fleche gauche
|
||||
img->player.angle_side = 0;
|
||||
else if (type == 65363)//fleche droite
|
||||
img->player.angle_side = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int loop(t_data *img)
|
||||
{
|
||||
update_pos(img);
|
||||
draw_ray(img);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
t_data img;
|
||||
@ -108,20 +149,26 @@ int main(int argc, char **argv)
|
||||
set_map(&img);
|
||||
if (check_map(argv, &img))
|
||||
return (0);
|
||||
img.map.texture.basic = get_texture(0, 0, &img);
|
||||
printf("size= %d\n", img.map.size);
|
||||
img.mlx = mlx_init();
|
||||
if (!img.mlx)
|
||||
ft_error("Error: mlx_init fail");
|
||||
img.mlx_win = mlx_new_window(img.mlx, 960, 512, "Cub3D");
|
||||
img.player.x = 64 * 3 + 16;
|
||||
img.player.y = 64 + 16;
|
||||
img.player.x = 64 * 3 + 32;
|
||||
img.player.y = 64 + 32;
|
||||
img.player.angle = 90;
|
||||
img.player.vx = cos(deg_to_rad(img.player.angle));
|
||||
img.player.vy = sin(deg_to_rad(img.player.angle));
|
||||
//print_map(img.map, &img);
|
||||
//print_player(img.player, &img);
|
||||
//print_ray(&img);
|
||||
mlx_hook(img.mlx_win, 2, 1L << 0, &key_press, &img);
|
||||
|
||||
|
||||
mlx_hook(img.mlx_win, 2, 1L << 0, key_pressed, &img);
|
||||
mlx_hook(img.mlx_win, 3, 1L << 1, key_released, &img);
|
||||
mlx_loop_hook(img.mlx, loop, &img);
|
||||
mlx_hook(img.mlx_win, 17, 0L, &quit_game, &img);
|
||||
|
||||
mlx_loop(img.mlx);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/13 12:12:48 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/13 20:50:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -42,7 +42,7 @@ char *transform_map(char **double_map, t_data *img)
|
||||
|
||||
i = -1;
|
||||
index = 0;
|
||||
print_double_fd(double_map, 1);
|
||||
//print_double_fd(double_map, 1);
|
||||
img->map.size = img->map.x * img->map.y;
|
||||
printf("x= %d y= %d\n", img->map.x, img->map.y);
|
||||
map = ft_calloc(sizeof(char), img->map.size + 1);
|
||||
@ -60,9 +60,8 @@ char *transform_map(char **double_map, t_data *img)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
img->map.simple_map = map;
|
||||
printf("map = -%s-\n", map);
|
||||
//printf("map = -%s-\n", map);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -91,7 +90,7 @@ void set_texture_file(char *str, t_data *img, char c)
|
||||
if (str[index + 1] != 'A' || str[index + 2] != ' ')
|
||||
ft_exit("Error\nBad syntax in map file\n");
|
||||
}
|
||||
printf("path= -%s-\n", str + index + 3);
|
||||
//printf("path= -%s-\n", str + index + 3);
|
||||
get_texture(c, str + index + 3, img);
|
||||
}
|
||||
|
||||
@ -118,13 +117,13 @@ int check_texture_color(char **tab, t_data *img)
|
||||
{
|
||||
int next;
|
||||
int index;
|
||||
char line;
|
||||
//char line;
|
||||
|
||||
index = 0;
|
||||
next = 0;
|
||||
int i = 0;
|
||||
while (tab[i])
|
||||
printf("%s\n", tab[i++]);
|
||||
//int i = 0;
|
||||
//while (tab[i])
|
||||
// printf("%s\n", tab[i++]);
|
||||
while (next_space(tab[next], 0) != '1' && tab[next])
|
||||
next++;
|
||||
if (!tab[next])
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/06/13 12:25:51 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/13 20:51:12 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -49,12 +49,10 @@ void size_line(char *str, t_data *img)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (str[i])
|
||||
i++;
|
||||
if (i > img->map.x)
|
||||
img->map.x = i;
|
||||
printf("sizelie= %s, size= %d\n", str, i);
|
||||
}
|
||||
|
||||
char *charge_new(t_data *img)
|
||||
@ -238,6 +236,8 @@ char **isafile(char **av, t_data *img)
|
||||
line = NULL;
|
||||
}
|
||||
split = ft_split(str, '\n');
|
||||
//printf("this is it\n");
|
||||
//print_double_fd(split, 1);
|
||||
free(line);
|
||||
free(str);
|
||||
close(fd);
|
||||
@ -252,20 +252,16 @@ char **isafile(char **av, t_data *img)
|
||||
|
||||
int check_map(char **av, t_data *img)
|
||||
{
|
||||
char **map;
|
||||
|
||||
img->map.x = 0;
|
||||
img->map.y = 0;
|
||||
img->map.error = 0;
|
||||
|
||||
map = NULL;
|
||||
if (reverse_comp(av[1], ".cub") || (ft_strlen(av[1]) == ft_strlen(".cub")))
|
||||
{
|
||||
ft_putstr_fd("Error: Not a valid file \".cub\"\n", 2);
|
||||
return (1);
|
||||
}
|
||||
map = isafile(av, img);
|
||||
|
||||
isafile(av, img);
|
||||
if (img->map.x > img->map.y)
|
||||
img->map.max = img->map.x;
|
||||
else
|
||||
|
||||
130
srcs/utils.c
130
srcs/utils.c
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
||||
/* Updated: 2022/06/13 12:39:15 by apommier ### ########.fr */
|
||||
/* Updated: 2022/06/14 00:09:06 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,6 +22,8 @@ void free_texture(t_data *img)
|
||||
free(img->map.texture.east);
|
||||
if (img->map.texture.west)
|
||||
free(img->map.texture.west);
|
||||
if (img->map.texture.basic)
|
||||
free(img->map.texture.basic);
|
||||
}
|
||||
|
||||
int quit_game(t_data *img)
|
||||
@ -60,48 +62,86 @@ void ft_error(char *error_msg)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int is_good(t_data *img, int type)
|
||||
int update_pos(t_data *img)
|
||||
{
|
||||
if (type == 'w')
|
||||
if (img->player.front == 1)
|
||||
{
|
||||
img->player.x += img->player.vx * 5;
|
||||
img->player.y += img->player.vy * 5;
|
||||
img->player.x += img->player.vx * 2;
|
||||
img->player.y += img->player.vy * 2;
|
||||
}
|
||||
else if (type == 's')
|
||||
else if (img->player.front == -1)
|
||||
{
|
||||
img->player.x -= img->player.vx * 5;
|
||||
img->player.y -= img->player.vy * 5;
|
||||
img->player.x -= img->player.vx * 2;
|
||||
img->player.y -= img->player.vy * 2;
|
||||
}
|
||||
else if (type == 'a')
|
||||
if (img->player.side == 1)
|
||||
{
|
||||
img->player.x += img->player.vy * 5;
|
||||
img->player.y -= img->player.vx * 5;
|
||||
img->player.x -= img->player.vy ;
|
||||
img->player.y += img->player.vx ;
|
||||
}
|
||||
else if (type == 'd')
|
||||
else if (img->player.side == -1)
|
||||
{
|
||||
img->player.x -= img->player.vy * 5;
|
||||
img->player.y += img->player.vx * 5;
|
||||
img->player.x += img->player.vy; //* 5;
|
||||
img->player.y -= img->player.vx; //* 5;
|
||||
}
|
||||
else if (type == 65361)//fleche gauche
|
||||
if (img->player.angle_side == -1)//fleche gauche
|
||||
{
|
||||
img->player.angle += 5;
|
||||
img->player.angle += 1;
|
||||
img->player.angle = reset_angle(img->player.angle);
|
||||
img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
}
|
||||
else if (type == 65363)//fleche droite
|
||||
else if (img->player.angle_side == 1)//fleche droite
|
||||
{
|
||||
img->player.angle -= 5;
|
||||
img->player.angle -= 1;
|
||||
img->player.angle = reset_angle(img->player.angle);
|
||||
img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
}
|
||||
else
|
||||
return (0);
|
||||
//printf("after player: x= %d y= %d\n", img->player.x, img->player.y);
|
||||
return (1);
|
||||
}
|
||||
|
||||
// int is_good(t_data *img, int type)
|
||||
// {
|
||||
// if (type == 'w')
|
||||
// {
|
||||
// img->player.x += img->player.vx * 5;
|
||||
// img->player.y += img->player.vy * 5;
|
||||
// }
|
||||
// else if (type == 's')
|
||||
// {
|
||||
// img->player.x -= img->player.vx * 5;
|
||||
// img->player.y -= img->player.vy * 5;
|
||||
// }
|
||||
// else if (type == 'a')
|
||||
// {
|
||||
// img->player.x += img->player.vy * 5;
|
||||
// img->player.y -= img->player.vx * 5;
|
||||
// }
|
||||
// else if (type == 'd')
|
||||
// {
|
||||
// img->player.x -= img->player.vy * 5;
|
||||
// img->player.y += img->player.vx * 5;
|
||||
// }
|
||||
// else if (type == 65361)//fleche gauche
|
||||
// {
|
||||
// img->player.angle += 5;
|
||||
// img->player.angle = reset_angle(img->player.angle);
|
||||
// img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
// img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
// }
|
||||
// else if (type == 65363)//fleche droite
|
||||
// {
|
||||
// img->player.angle -= 5;
|
||||
// img->player.angle = reset_angle(img->player.angle);
|
||||
// img->player.vx = cos(deg_to_rad(img->player.angle));
|
||||
// img->player.vy = -sin(deg_to_rad(img->player.angle));
|
||||
// }
|
||||
// else
|
||||
// return (0);
|
||||
// //printf("after player: x= %d y= %d\n", img->player.x, img->player.y);
|
||||
// return (1);
|
||||
// }
|
||||
|
||||
/*int create_trgb(int t, int r, int g, int b)
|
||||
{
|
||||
return (t << 24 | r << 16 | g << 8 | b);
|
||||
@ -156,17 +196,23 @@ void set_back(t_data *img)
|
||||
while (x < 512 * 960 * 4)
|
||||
{
|
||||
if (x > 512 * 960 * 2)
|
||||
{
|
||||
if (img->map.floor.b)
|
||||
{
|
||||
img->buffer[x + 0] = img->map.floor.b;
|
||||
img->buffer[x + 1] = img->map.floor.g;
|
||||
img->buffer[x + 2] =img->map.floor.r;
|
||||
img->buffer[x + 3] = 0;
|
||||
}
|
||||
//tmp = create_trgb(128, 128, 128, 0);
|
||||
else
|
||||
{
|
||||
img->buffer[x + 0] = 128;
|
||||
img->buffer[x + 1] = 128;
|
||||
img->buffer[x + 2] = 128;
|
||||
img->buffer[x + 3] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
img->buffer[x + 0] = img->map.sky.b;
|
||||
@ -196,23 +242,23 @@ void set_back(t_data *img)
|
||||
}*/
|
||||
}
|
||||
|
||||
int key_press(int code, t_data *img)
|
||||
{
|
||||
//printf("touche ");
|
||||
if (code == 65307)
|
||||
quit_game(img);
|
||||
else
|
||||
{
|
||||
if (is_good(img, code))
|
||||
{
|
||||
//printf("code = %d\n", code);
|
||||
//mlx_clear_window(img->mlx, img->mlx_win);
|
||||
//print_map(img->map, img);
|
||||
//print_player(img->player, img);
|
||||
//set_back(img);
|
||||
draw_ray(img);
|
||||
//print_ray(img);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
// int key_press(int code, t_data *img)
|
||||
// {
|
||||
// //printf("touche ");
|
||||
// if (code == 65307)
|
||||
// quit_game(img);
|
||||
// else
|
||||
// {
|
||||
// if (is_good(img, code))
|
||||
// {
|
||||
// //printf("code = %d\n", code);
|
||||
// //mlx_clear_window(img->mlx, img->mlx_win);
|
||||
// //print_map(img->map, img);
|
||||
// //print_player(img->player, img);
|
||||
// //set_back(img);
|
||||
// draw_ray(img);
|
||||
// //print_ray(img);
|
||||
// }
|
||||
// }
|
||||
// return (1);
|
||||
//}
|
||||
Loading…
Reference in New Issue
Block a user