manqueunefonctionnorme

This commit is contained in:
2024-01-29 20:26:06 +01:00
parent fcbbe51d52
commit 7d67dfd452
121 changed files with 996 additions and 2858 deletions

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 20:19:01 by fgras-ca #+# #+# */
/* Updated: 2024/01/25 18:36:59 by fgras-ca ### ########.fr */
/* Updated: 2024/01/29 15:47:34 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,7 +21,7 @@ void draw_map_line(t_structure_main *w, int y, int lineLength)
x = 0;
while (x < lineLength)
{
index = y * w->s_map.mapX + x;
index = y * w->s_map.map_x + x;
if (w->s_map.map[index] == '1')
color = 0xFFFFFF;
else if (w->s_map.map[index] == '0')
@@ -48,12 +48,12 @@ void draw_map(t_structure_main *w)
printf("Erreur: La carte n'a pas été chargée correctement.\n");
return ;
}
while (y < w->s_map.mapY)
while (y < w->s_map.map_y)
{
linelength = 0;
while (linelength < w->s_map.mapX
&& w->s_map.map[y * w->s_map.mapX + linelength]
!= '\n' && w->s_map.map[y * w->s_map.mapX + linelength] != '\0')
while (linelength < w->s_map.map_x
&& w->s_map.map[y * w->s_map.map_x + linelength]
!= '\n' && w->s_map.map[y * w->s_map.map_x + linelength] != '\0')
{
linelength++;
}

View File

@@ -6,29 +6,34 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 20:09:23 by fgras-ca #+# #+# */
/* Updated: 2024/01/23 18:38:11 by fgras-ca ### ########.fr */
/* Updated: 2024/01/29 20:21:37 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "../cub3d.h"
void init_player(t_structure_main *w) {
w->s_player.px = w->s_map.player_x;
w->s_player.py = w->s_map.player_y;
// Remplacer le switch par des if
if (w->s_map.player_direction == 'N') {
w->s_player.pa = M_PI;
} else if (w->s_map.player_direction == 'S') {
w->s_player.pa = 0;
} else if (w->s_map.player_direction == 'E') {
w->s_player.pa = M_PI / 2;
} else if (w->s_map.player_direction == 'W') {
w->s_player.pa = 3 * M_PI / 2;
}
w->s_player.pdx = cos(w->s_player.pa) * 5;
w->s_player.pdy = sin(w->s_player.pa) * 5;
void init_player(t_structure_main *w)
{
w->s_player.px = w->s_map.player_x;
w->s_player.py = w->s_map.player_y;
if (w->s_map.player_direction == 'N')
{
w->s_player.pa = M_PI;
}
else if (w->s_map.player_direction == 'S')
{
w->s_player.pa = 0;
}
else if (w->s_map.player_direction == 'E')
{
w->s_player.pa = M_PI / 2;
}
else if (w->s_map.player_direction == 'W')
{
w->s_player.pa = 3 * M_PI / 2;
}
w->s_player.pdx = cos(w->s_player.pa) * 5;
w->s_player.pdy = sin(w->s_player.pa) * 5;
}
void init_mlx_and_window(t_structure_main *w)

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/15 19:50:24 by fgras-ca #+# #+# */
/* Updated: 2024/01/28 22:04:52 by fgras-ca ### ########.fr */
/* Updated: 2024/01/29 20:23:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,10 +19,10 @@ void rescale_sprite(t_structure_main *w, t_state *state)
params.original_img = w->s_img.roomadslam[state->jkl];
params.original_width = 112;
params.original_height = 112;
params.new_width = w->s_map.mapS;
params.new_height = w->s_map.mapS;
params.px = w->s_player.px - w->s_map.mapS / 2;
params.py = w->s_player.py - w->s_map.mapS / 2;
params.new_width = w->s_map.map_s;
params.new_height = w->s_map.map_s;
params.px = w->s_player.px - w->s_map.map_s / 2;
params.py = w->s_player.py - w->s_map.map_s / 2;
rescale_image(&params, w);
}
@@ -35,8 +35,6 @@ void refresh_window(t_structure_main *w, t_state *state)
&(w->s_img.bpp), &(w->s_img.line_len), &(w->s_img.endian));
draw_map(w);
drawrays2d(w);
update_sprite_frame(&w->sprite);
draw_sprite(&w->sprite, w->s_win.mlx, w->s_win.win, w->s_win.width, w->s_win.height);
mlx_put_image_to_window(w->s_win.mlx, w->s_win.win, w->s_img.buffer, 0, 0);
rescale_sprite(w, state);
}
@@ -48,11 +46,11 @@ void handle_mouse_movement(t_structure_main *w)
mlx_mouse_get_pos(w->s_win.mlx, w->s_win.win, &x, &y);
if ((x > 0 && x < w->s_win.width) && (y > 0 && y < w->s_win.height))
{
if (x < w->s_win.width/2-40)
deal_key(65361,w);
else if (x > w->s_win.width/2+40)
deal_key(65363,w);
{
if (x < w->s_win.width / 2 - 40)
deal_key(65361, w);
else if (x > w->s_win.width / 2 + 40)
deal_key(65363, w);
}
}

View File

@@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/14 19:15:53 by fgras-ca #+# #+# */
/* Updated: 2024/01/28 21:57:21 by fgras-ca ### ########.fr */
/* Updated: 2024/01/29 15:47:48 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
@@ -76,12 +76,12 @@ void calculate_map_scale(t_structure_main *w)
int maps_x;
int maps_y;
maps_x = w->s_win.width / (w->s_map.mapX * 4);
maps_y = w->s_win.height / (w->s_map.mapY * 2);
maps_x = w->s_win.width / (w->s_map.map_x * 4);
maps_y = w->s_win.height / (w->s_map.map_y * 2);
if (maps_x < maps_y)
w->s_map.mapS = maps_x;
w->s_map.map_s = maps_x;
else
w->s_map.mapS = maps_y;
w->s_map.map_s = maps_y;
}
void init_windows(t_structure_main *w)
@@ -93,7 +93,6 @@ void init_windows(t_structure_main *w)
load_textures(w, &temp);
init_buffer(w);
load_wall_textures(w);
load_sprite_frames(&w->sprite, w->s_win.mlx);
printf("Window Dimensions: Width = %d, Height = %d\n",
w->s_win.width, w->s_win.height);
printf("Texture Dimensions: Width = %d, Height = %d\n",