style: normed all the repo (except the debug function and the too_many_args
This commit is contained in:
parent
57c7893501
commit
954c5f76d6
12 changed files with 244 additions and 207 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:12:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/01 17:27:45 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/12/01 18:46:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,12 +15,22 @@
|
|||
|
||||
#include "mlx_functions.h"
|
||||
|
||||
#include "ft_char.h"
|
||||
#include <X11/keysym.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int key_hook(int keycode, t_info *data)
|
||||
{
|
||||
printf("Event detected: %d\n", keycode);
|
||||
if (ft_isalpha(keycode))
|
||||
printf("Event detected: %d\t(%c)\n", keycode, keycode);
|
||||
else if (keycode == 65361)
|
||||
printf("Event detected: %d\t(Left Arrow)\n", keycode);
|
||||
else if (keycode == 65363)
|
||||
printf("Event detected: %d\t(Right Arrow)\n", keycode);
|
||||
else if (keycode == 65307)
|
||||
printf("Event detected: %d\t(Echap)\n", keycode);
|
||||
else
|
||||
printf("Event detected: %d\n", keycode);
|
||||
if (keycode == XK_Escape)
|
||||
mlx_loop_end(data->mlx_ptr);
|
||||
if (keycode == XK_w)
|
||||
|
|
@ -37,4 +47,3 @@ int key_hook(int keycode, t_info *data)
|
|||
look_right(data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
|
||||
/* Updated: 2024/12/01 17:33:00 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/12/01 18:02:27 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
int c3_frame_update(void *inf_ptr);
|
||||
|
||||
int key_hook(int keycode, t_info *data);
|
||||
|
||||
/* move player w keys and call to redraw screen */
|
||||
int c3_keyhook(int keycode, t_info *info)
|
||||
{
|
||||
|
|
@ -38,7 +39,8 @@ int c3_redcross(t_info *info)
|
|||
|
||||
t_win_list *c3_init_mlx_window(t_info *info)
|
||||
{
|
||||
mlx_get_screen_size(info->mlx_ptr, &info->screen_size.x, &info->screen_size.y);
|
||||
mlx_get_screen_size(info->mlx_ptr, \
|
||||
&info->screen_size.x, &info->screen_size.y);
|
||||
info->screen_size.x *= WIN_COEF;
|
||||
info->screen_size.y *= WIN_COEF;
|
||||
ft_clamp(info->screen_size.x, 0, 1920);
|
||||
|
|
@ -57,7 +59,8 @@ int init_mlx_env(t_info *info)
|
|||
if (!info->win_ptr)
|
||||
return (ERROR_MLX);
|
||||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, key_hook, info);
|
||||
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, c3_redcross, info);
|
||||
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, \
|
||||
c3_redcross, info);
|
||||
mlx_loop_hook(info->mlx_ptr, (int (*)())shelves_launch, info);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:10:44 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/01 17:15:27 by bgoulard ### ########.fr */
|
||||
/* Updated: 2024/12/01 18:36:26 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
#include "cub3d_parsing.h"
|
||||
|
||||
void update_pos_i(t_player *player)
|
||||
{
|
||||
|
|
@ -21,15 +22,17 @@ void update_pos_i(t_player *player)
|
|||
|
||||
void move_straight(t_info *data)
|
||||
{
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
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});
|
||||
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)});
|
||||
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;
|
||||
update_pos_i(&data->player);
|
||||
|
|
@ -37,15 +40,17 @@ void move_straight(t_info *data)
|
|||
|
||||
void move_backward(t_info *data)
|
||||
{
|
||||
t_tile *tile_x;
|
||||
t_tile *tile_y;
|
||||
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});
|
||||
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)});
|
||||
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;
|
||||
update_pos_i(&data->player);
|
||||
|
|
@ -59,12 +64,14 @@ void move_left(t_info *data)
|
|||
|
||||
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});
|
||||
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)});
|
||||
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;
|
||||
update_pos_i(&data->player);
|
||||
|
|
@ -78,12 +85,14 @@ void move_right(t_info *data)
|
|||
|
||||
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});
|
||||
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)});
|
||||
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;
|
||||
update_pos_i(&data->player);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue