v1.0 - normed texture system, multiple keypress, fixes on parsing, removed trailing maps
This commit is contained in:
parent
e581c72b02
commit
3f43074d05
35 changed files with 474 additions and 438 deletions
|
|
@ -6,44 +6,38 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:12:25 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/01 18:46:32 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/12/16 14:16:17 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
#include "mlx_functions.h"
|
||||
|
||||
#include "ft_char.h"
|
||||
#include <X11/keysym.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int key_hook(int keycode, t_info *data)
|
||||
static void update_pos_i(t_player *player)
|
||||
{
|
||||
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)
|
||||
player->pos_i.x = (int)player->pos.x;
|
||||
player->pos_i.y = (int)player->pos.y;
|
||||
}
|
||||
|
||||
int displacement_hook(t_info *data)
|
||||
{
|
||||
data->redraw = true;
|
||||
update_pos_i(&data->player);
|
||||
if (data->kb.forward && !data->kb.backward)
|
||||
move_straight(data);
|
||||
if (keycode == XK_s)
|
||||
if (data->kb.backward && !data->kb.forward)
|
||||
move_backward(data);
|
||||
if (keycode == XK_a)
|
||||
if (data->kb.left && !data->kb.right)
|
||||
move_left(data);
|
||||
if (keycode == XK_d)
|
||||
if (data->kb.right && !data->kb.left)
|
||||
move_right(data);
|
||||
if (keycode == XK_Left)
|
||||
if (data->kb.l_left && !data->kb.l_right)
|
||||
look_left(data);
|
||||
if (keycode == XK_Right)
|
||||
if (data->kb.l_right && !data->kb.l_left)
|
||||
look_right(data);
|
||||
update_pos_i(&data->player);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
63
mlx_layer/keys_event.c
Normal file
63
mlx_layer/keys_event.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* keys_event.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/16 14:40:02 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/16 14:41:40 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d_struct.h"
|
||||
#include "mlx_functions.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
void set_kb(t_keyboard *kb, int keycode)
|
||||
{
|
||||
if (keycode == XK_w)
|
||||
kb->forward = true;
|
||||
if (keycode == XK_s)
|
||||
kb->backward = true;
|
||||
if (keycode == XK_a)
|
||||
kb->left = true;
|
||||
if (keycode == XK_d)
|
||||
kb->right = true;
|
||||
if (keycode == XK_Right)
|
||||
kb->l_right = true;
|
||||
if (keycode == XK_Left)
|
||||
kb->l_left = true;
|
||||
}
|
||||
|
||||
void unset_kb(t_keyboard *kb, int keycode)
|
||||
{
|
||||
if (keycode == XK_w)
|
||||
kb->forward = false;
|
||||
if (keycode == XK_s)
|
||||
kb->backward = false;
|
||||
if (keycode == XK_a)
|
||||
kb->left = false;
|
||||
if (keycode == XK_d)
|
||||
kb->right = false;
|
||||
if (keycode == XK_Left)
|
||||
kb->l_left = false;
|
||||
if (keycode == XK_Right)
|
||||
kb->l_right = false;
|
||||
}
|
||||
|
||||
int keypress_feature(int keycode, t_info *data)
|
||||
{
|
||||
if (keycode == XK_Escape)
|
||||
mlx_loop_end(data->mlx_ptr);
|
||||
set_kb(&data->kb, keycode);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int keyrelease_feature(int keycode, t_info *data)
|
||||
{
|
||||
unset_kb(&data->kb, keycode);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -6,25 +6,22 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/11 19:53:42 by rparodi #+# #+# */
|
||||
/* Updated: 2024/12/05 16:55:30 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/12/16 14:40:55 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "cub3d_struct.h"
|
||||
|
||||
#include "mlx_functions.h"
|
||||
#include "mlx_structs.h"
|
||||
#include "ft_string.h"
|
||||
|
||||
#include "ft_math.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
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)
|
||||
{
|
||||
if (keycode == XK_Escape || keycode == 65307)
|
||||
|
|
@ -41,8 +38,8 @@ 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);
|
||||
/*info->screen_size.x *= WIN_COEF;*/
|
||||
/*info->screen_size.y *= WIN_COEF;*/
|
||||
info->screen_size.x *= WIN_COEF;
|
||||
info->screen_size.y *= WIN_COEF;
|
||||
ft_clamp(info->screen_size.x, 0, 1920);
|
||||
ft_clamp(info->screen_size.y, 0, 1080);
|
||||
return (\
|
||||
|
|
@ -58,7 +55,9 @@ int init_mlx_env(t_info *info)
|
|||
info->win_ptr = c3_init_mlx_window(info);
|
||||
if (!info->win_ptr)
|
||||
return (ERROR_MLX);
|
||||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, key_hook, info);
|
||||
mlx_hook(info->win_ptr, KeyPress, KeyPressMask, keypress_feature, info);
|
||||
mlx_hook(info->win_ptr, KeyRelease, KeyReleaseMask, keyrelease_feature, \
|
||||
info);
|
||||
mlx_hook(info->win_ptr, DestroyNotify, StructureNotifyMask, \
|
||||
c3_redcross, info);
|
||||
mlx_loop_hook(info->mlx_ptr, (int (*)())shelves_launch, info);
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mlx_load_texture.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/20 12:25:45 by rparodi #+# #+# */
|
||||
/* Updated: 2024/12/05 17:01:12 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cub3d.h"
|
||||
#include "mlx_functions.h"
|
||||
|
||||
t_img *mlx_load_image(t_info *info, char *path)
|
||||
{
|
||||
t_img *image;
|
||||
int size;
|
||||
|
||||
size = TILES_SIZE;
|
||||
image = mlx_xpm_file_to_image(info->mlx_ptr, path, &size, &size);
|
||||
if (!image)
|
||||
return (NULL);
|
||||
return (image);
|
||||
}
|
||||
|
||||
bool mlx_load_all_textures(t_info *info)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
info->map.texture[0] = mlx_load_image(info, "../textures/wasteland_32.xpm");
|
||||
info->map.texture[1] = mlx_load_image(info, "../textures/b.xpm");
|
||||
info->map.texture[2] = mlx_load_image(info, "../textures/sandy_32.xpm");
|
||||
info->map.texture[3] = mlx_load_image(info, "../textures/cobblestone_32.xpm");
|
||||
|
||||
while (i < 4)
|
||||
{
|
||||
if (!info->map.texture[i])
|
||||
return (false);
|
||||
i++;
|
||||
}
|
||||
return (true);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/28 14:10:44 by bgoulard #+# #+# */
|
||||
/* Updated: 2024/12/01 18:36:26 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/12/16 08:36:17 by bgoulard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,12 +14,6 @@
|
|||
#include "cub3d_struct.h"
|
||||
#include "cub3d_parsing.h"
|
||||
|
||||
void update_pos_i(t_player *player)
|
||||
{
|
||||
player->pos_i.x = (int)player->pos.x;
|
||||
player->pos_i.y = (int)player->pos.y;
|
||||
}
|
||||
|
||||
void move_straight(t_info *data)
|
||||
{
|
||||
t_tile *tile_x;
|
||||
|
|
@ -35,7 +29,6 @@ void move_straight(t_info *data)
|
|||
+ 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);
|
||||
}
|
||||
|
||||
void move_backward(t_info *data)
|
||||
|
|
@ -53,7 +46,6 @@ void move_backward(t_info *data)
|
|||
- 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);
|
||||
}
|
||||
|
||||
void move_left(t_info *data)
|
||||
|
|
@ -74,7 +66,6 @@ void move_left(t_info *data)
|
|||
pplayer.y * MOVE_SPEED)});
|
||||
if (tile_y->tile_type == EMPTY)
|
||||
data->player.pos.y += pplayer.y * MOVE_SPEED;
|
||||
update_pos_i(&data->player);
|
||||
}
|
||||
|
||||
void move_right(t_info *data)
|
||||
|
|
@ -95,5 +86,4 @@ void move_right(t_info *data)
|
|||
* 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