tmp push merge resolution not finished

This commit is contained in:
Baptiste GOULARD 2024-11-28 16:02:06 +01:00
parent 2568aa69a6
commit 00dc0e9e67
16 changed files with 454 additions and 59 deletions

38
mlx_layer/hooks.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 14:12:25 by bgoulard #+# #+# */
/* Updated: 2024/11/28 14:57:01 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "cub3d_struct.h"
#include "mlx_functions.h"
#include <X11/keysym.h>
int key_hook(int keycode, t_info *data)
{
if (keycode == XK_Escape)
mlx_loop_end(data->mlx_ptr);
if (keycode == XK_w)
move_straight(data);
if (keycode == XK_s)
move_backward(data);
if (keycode == XK_a)
move_right(data);
if (keycode == XK_d)
move_left(data);
if (keycode == XK_Left)
look_left(data);
if (keycode == XK_Right)
look_right(data);
return (0);
}

26
mlx_layer/looks.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* looks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 14:11:28 by bgoulard #+# #+# */
/* Updated: 2024/11/28 14:51:53 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "cub3d_struct.h"
void look_left(t_info *data)
{
rotate_plane(&data->player.dir, ROT_SPEED);
rotate_plane(&data->player.plane, ROT_SPEED);
}
void look_right(t_info *data)
{
rotate_plane(&data->player.dir, -ROT_SPEED);
rotate_plane(&data->player.plane, -ROT_SPEED);
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
/* Updated: 2024/11/28 13:55:09 by bgoulard ### ########.fr */
/* Updated: 2024/11/28 14:06:03 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,6 +55,5 @@ int init_mlx_env(t_info *info)
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, c3_keyhook, info);
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
mlx_loop_hook(info->mlx_ptr, (int (*)())shelves_launch, &info);
mlx_loop_hook(info->mlx_ptr, c3_frame_update, info);
return (NO_ERROR);
}

80
mlx_layer/mooves.c Normal file
View file

@ -0,0 +1,80 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mooves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/28 14:10:44 by bgoulard #+# #+# */
/* Updated: 2024/11/28 14:50:48 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "cub3d_struct.h"
void move_straight(t_info *data)
{
t_tile *tile_x;
t_tile *tile_y;
tile_x = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)(data->player.pos.x + data->player.dir.x * MOVE_SPEED), (int)data->player.pos.y});
if (tile_x->tile_type == EMPTY)
data->player.pos.x += data->player.dir.x * MOVE_SPEED;
tile_y = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y + data->player.dir.y * MOVE_SPEED)});
if (tile_y->tile_type == EMPTY)
data->player.pos.y += data->player.dir.y * MOVE_SPEED;
}
void move_backward(t_info *data)
{
t_tile *tile_x;
t_tile *tile_y;
tile_x = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)(data->player.pos.x - data->player.dir.x * MOVE_SPEED), (int)data->player.pos.y});
if (tile_x->tile_type == EMPTY)
data->player.pos.x -= data->player.dir.x * MOVE_SPEED;
tile_y = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y - data->player.dir.y * MOVE_SPEED)});
if (tile_y->tile_type == EMPTY)
data->player.pos.y -= data->player.dir.y * MOVE_SPEED;
}
void move_left(t_info *data)
{
t_dpoint pplayer;
t_tile *tile_x;
t_tile *tile_y;
pplayer.x = -data->player.dir.y;
pplayer.y = data->player.dir.x;
tile_x = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)(data->player.pos.x + pplayer.x * MOVE_SPEED), (int)data->player.pos.y});
if (tile_x->tile_type == EMPTY)
data->player.pos.x += pplayer.x * MOVE_SPEED;
tile_y = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y + pplayer.y * MOVE_SPEED)});
if (tile_y->tile_type == EMPTY)
data->player.pos.y += pplayer.y * MOVE_SPEED;
}
void move_right(t_info *data)
{
t_dpoint pplayer;
t_tile *tile_x;
t_tile *tile_y;
pplayer.x = -data->player.dir.y;
pplayer.y = data->player.dir.x;
tile_x = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)(data->player.pos.x - pplayer.x * MOVE_SPEED), (int)data->player.pos.y});
if (tile_x->tile_type == EMPTY)
data->player.pos.x -= pplayer.x * MOVE_SPEED;
tile_y = c3_get_cell(data->map.map, data->map.size,
(t_ipoint){(int)data->player.pos.x, (int)(data->player.pos.y - pplayer.y * MOVE_SPEED)});
if (tile_y->tile_type == EMPTY)
data->player.pos.y -= pplayer.y * MOVE_SPEED;
}