「🏗️」 wip: Player on minimap working
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,5 +9,3 @@ libft/**/*.o
|
|||||||
libft/**/*.a
|
libft/**/*.a
|
||||||
src/main.c
|
src/main.c
|
||||||
vgcore.*
|
vgcore.*
|
||||||
Makefile
|
|
||||||
src/cub3d.c
|
|
||||||
|
7
Makefile
7
Makefile
@ -16,12 +16,7 @@ MACRO_DIR = MacroLibX/
|
|||||||
|
|
||||||
INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR)
|
INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) -I $(MACRO_DIR)/$(I_DIR)
|
||||||
|
|
||||||
SRCS = src/utils/mess_error.c \
|
SRCS = $(shell find src -name *.c)
|
||||||
src/utils/parse_utils.c \
|
|
||||||
src/parsing/check_map.c \
|
|
||||||
src/parsing/check_arg.c \
|
|
||||||
src/parsing/principal_pars.c \
|
|
||||||
src/cub3d.c
|
|
||||||
|
|
||||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o))
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
@ -6,27 +6,33 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
|
/* Created: 2024/09/11 16:38:40 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/09/12 17:04:59 by adjoly ### ########.fr */
|
/* Updated: 2024/09/16 13:36:04 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
# define GAME_H
|
# define GAME_H
|
||||||
|
|
||||||
|
# include "parsing.h"
|
||||||
|
# include <stdint.h>
|
||||||
|
|
||||||
typedef struct s_cub
|
typedef struct s_cub
|
||||||
{
|
{
|
||||||
void *mlx;
|
void *mlx;
|
||||||
void *win;
|
void *win;
|
||||||
void *images;
|
void *images;
|
||||||
char **map;
|
char **map;
|
||||||
|
t_coord p_coord;
|
||||||
} t_cub;
|
} t_cub;
|
||||||
|
|
||||||
#define ESCAPE_KEY 41
|
# define ESCAPE_KEY 41
|
||||||
#define W_KEY 26
|
# define W_KEY 26
|
||||||
#define S_KEY 22
|
# define S_KEY 22
|
||||||
#define A_KEY 4
|
# define A_KEY 4
|
||||||
#define D_KEY 7
|
# define D_KEY 7
|
||||||
#define WHITE 0xFFFFFFFF
|
# define WHITE 0xFFFFFFFF
|
||||||
|
# define WINDOW_Y 900
|
||||||
|
# define WINDOW_X 1600
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is used to handle keypress
|
* @brief This function is used to handle keypress
|
||||||
@ -36,6 +42,14 @@ typedef struct s_cub
|
|||||||
*
|
*
|
||||||
* @return Minilibx go brrrr(useless always 0)
|
* @return Minilibx go brrrr(useless always 0)
|
||||||
*/
|
*/
|
||||||
int key_hook(int key, void *mlx);
|
int key_hook(int key, void *param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is used to create an image with the player position
|
||||||
|
*
|
||||||
|
* @param cub The address of a t_cub struct filled with mlx data and other thing
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void *get_player_image(t_cub *cub, uint8_t key_pressed);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
37
src/cub3d.c
Normal file
37
src/cub3d.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cub3d.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/16 18:39:38 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cub3d.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "mlx.h"
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
t_cub cub;
|
||||||
|
|
||||||
|
(void)ac;
|
||||||
|
(void)av;
|
||||||
|
cub.mlx = mlx_init();
|
||||||
|
cub.win = mlx_new_window(cub.mlx, 400, 400, "WTF");
|
||||||
|
cub.p_coord.x = 100;
|
||||||
|
cub.p_coord.y = 100;
|
||||||
|
|
||||||
|
mlx_put_image_to_window(cub.mlx, cub.win, get_player_image(&cub, 0), 0, 0);
|
||||||
|
|
||||||
|
mlx_on_event(cub.mlx, cub.win, MLX_KEYDOWN, key_hook, &cub);
|
||||||
|
|
||||||
|
mlx_loop(cub.mlx);
|
||||||
|
|
||||||
|
mlx_destroy_window(cub.mlx, cub.win);
|
||||||
|
mlx_destroy_display(cub.mlx);
|
||||||
|
return (0);
|
||||||
|
}
|
@ -6,29 +6,29 @@
|
|||||||
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
|
/* Created: 2024/09/12 12:44:52 by madumerg #+# #+# */
|
||||||
/* Updated: 2024/09/12 16:49:20 by madumerg ### ########.fr */
|
/* Updated: 2024/09/13 10:43:50 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cub3d.h"
|
#include "cub3d.h"
|
||||||
|
|
||||||
int check_info(char **l)
|
//int check_info(char **l)
|
||||||
{
|
//{
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
||||||
int verif_info_map(char *av)
|
//int verif_info_map(char *av)
|
||||||
{
|
//{
|
||||||
char **map;
|
// char **map;
|
||||||
char **f_part;
|
// char **f_part;
|
||||||
|
//
|
||||||
map = parse_map(av);
|
// map = parse_map(av);
|
||||||
f_part = info_map(map);
|
// f_part = info_map(map);
|
||||||
if (check_info(f_part) == 1)
|
// if (check_info(f_part) == 1)
|
||||||
return (1);
|
// return (1);
|
||||||
if (verif_all_map(map) == 1)
|
// if (verif_all_map(map) == 1)
|
||||||
return (1);
|
// return (1);
|
||||||
}
|
//}
|
||||||
|
|
||||||
int verif_all_map(char **map)
|
int verif_all_map(char **map)
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/11 16:37:56 by adjoly #+# #+# */
|
/* Created: 2024/09/11 16:37:56 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/09/12 14:40:22 by adjoly ### ########.fr */
|
/* Updated: 2024/09/16 18:47:09 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,18 +14,37 @@
|
|||||||
#include "mlx.h"
|
#include "mlx.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
int key_hook(int key, t_cub *cub)
|
int key_hook(int key, void *param)
|
||||||
{
|
{
|
||||||
(void)mlx;
|
t_cub *cub;
|
||||||
|
|
||||||
|
cub = (t_cub *)param;
|
||||||
|
(void)cub;
|
||||||
if (key == ESCAPE_KEY)
|
if (key == ESCAPE_KEY)
|
||||||
mlx_loop_end(cub->mlx);
|
mlx_loop_end(cub->mlx);
|
||||||
if (key == W_KEY)
|
if (key == W_KEY)
|
||||||
|
{
|
||||||
printf("UP\n");
|
printf("UP\n");
|
||||||
|
mlx_clear_window(cub->mlx, cub->win);
|
||||||
|
mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0);
|
||||||
|
}
|
||||||
if (key == S_KEY)
|
if (key == S_KEY)
|
||||||
|
{
|
||||||
printf("DOWN\n");
|
printf("DOWN\n");
|
||||||
|
mlx_clear_window(cub->mlx, cub->win);
|
||||||
|
mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0);
|
||||||
|
}
|
||||||
if (key == D_KEY)
|
if (key == D_KEY)
|
||||||
|
{
|
||||||
printf("RIGHT\n");
|
printf("RIGHT\n");
|
||||||
|
mlx_clear_window(cub->mlx, cub->win);
|
||||||
|
mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0);
|
||||||
|
}
|
||||||
if (key == A_KEY)
|
if (key == A_KEY)
|
||||||
|
{
|
||||||
printf("LEFT\n");
|
printf("LEFT\n");
|
||||||
|
mlx_clear_window(cub->mlx, cub->win);
|
||||||
|
mlx_put_image_to_window(cub->mlx, cub->win, get_player_image(cub, key), 0, 0);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
33
src/raycasting/player_print.c
Normal file
33
src/raycasting/player_print.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* player_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/13 11:05:02 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/09/16 18:49:37 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "game.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "mlx.h"
|
||||||
|
|
||||||
|
void *get_player_image(t_cub *cub, uint8_t key_pressed)
|
||||||
|
{
|
||||||
|
void *img;
|
||||||
|
|
||||||
|
img = mlx_new_image(cub->mlx, WINDOW_X, WINDOW_Y);
|
||||||
|
|
||||||
|
if (key_pressed == W_KEY)
|
||||||
|
cub->p_coord.y--;
|
||||||
|
else if (key_pressed == S_KEY)
|
||||||
|
cub->p_coord.y++;
|
||||||
|
else if (key_pressed == D_KEY)
|
||||||
|
cub->p_coord.x++;
|
||||||
|
else if (key_pressed == A_KEY)
|
||||||
|
cub->p_coord.x--;
|
||||||
|
mlx_set_image_pixel(cub->mlx, img, cub->p_coord.x, cub->p_coord.y, WHITE);
|
||||||
|
return (img);
|
||||||
|
}
|
Reference in New Issue
Block a user