mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
added movement vector movement core
This commit is contained in:
parent
ba42e0d3e1
commit
a58783350d
3 changed files with 23 additions and 16 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/06/06 17:42:23 by tchampio #+# #+# */
|
/* Created: 2025/06/06 17:42:23 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/06/06 17:43:19 by tchampio ### ########.fr */
|
/* Updated: 2025/07/09 17:05:10 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,5 +16,6 @@
|
||||||
# define HEIGHT 800
|
# define HEIGHT 800
|
||||||
# define WIDTH 800
|
# define WIDTH 800
|
||||||
# define RESSOURCE_DIR "ressources"
|
# define RESSOURCE_DIR "ressources"
|
||||||
|
# define MOVEMENT_SPEED 10.0
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ typedef enum e_direction
|
||||||
WEST
|
WEST
|
||||||
} t_direction;
|
} t_direction;
|
||||||
|
|
||||||
|
typedef struct s_vec2
|
||||||
|
{
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
} t_vec2;
|
||||||
|
|
||||||
typedef struct s_mapdata
|
typedef struct s_mapdata
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
@ -52,20 +58,13 @@ typedef struct s_mapdata
|
||||||
char error[1024];
|
char error[1024];
|
||||||
} t_mapdata;
|
} t_mapdata;
|
||||||
|
|
||||||
struct s_playermove {
|
|
||||||
int is_w_pressed;
|
|
||||||
int is_a_pressed;
|
|
||||||
int is_s_pressed;
|
|
||||||
int is_d_pressed;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct s_player
|
typedef struct s_player
|
||||||
{
|
{
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
double yaw;
|
double yaw;
|
||||||
int health;
|
int health;
|
||||||
struct s_playermove playermove;
|
t_vec2 movement;
|
||||||
} t_player;
|
} t_player;
|
||||||
|
|
||||||
typedef struct s_cub3d_data
|
typedef struct s_cub3d_data
|
||||||
|
|
|
||||||
13
src/main.c
13
src/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||||
/* Updated: 2025/07/09 16:23:50 by tchampio ### ########.fr */
|
/* Updated: 2025/07/09 17:07:29 by tchampio ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "../includes/structs.h"
|
#include "../includes/structs.h"
|
||||||
#include "../mlx/mlx.h"
|
#include "../mlx/mlx.h"
|
||||||
#include "../includes/maputils.h"
|
#include "../includes/maputils.h"
|
||||||
|
#include "../includes/cub3d_consts.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
|
|
@ -67,8 +68,14 @@ int keypress_handler(int keycode, t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
if (keycode == XK_Escape)
|
if (keycode == XK_Escape)
|
||||||
destroy(data);
|
destroy(data);
|
||||||
else if (keycode == XK_w || keycode == XK_a || keycode == XK_s || keycode == XK_d)
|
else if (keycode == XK_a)
|
||||||
ft_printf("salut\n");
|
data->player.movement.x = -MOVEMENT_SPEED;
|
||||||
|
else if (keycode == XK_d)
|
||||||
|
data->player.movement.x = MOVEMENT_SPEED;
|
||||||
|
else if (keycode == XK_w)
|
||||||
|
data->player.movement.y = -MOVEMENT_SPEED;
|
||||||
|
else if (keycode == XK_s)
|
||||||
|
data->player.movement.y = MOVEMENT_SPEED;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue