mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
restarted movement core
This commit is contained in:
parent
a8abe903cb
commit
ba42e0d3e1
5 changed files with 57 additions and 37 deletions
2
Makefile
2
Makefile
|
|
@ -30,7 +30,7 @@ fclean: clean
|
|||
|
||||
bonus: CFLAGS += -D BONUS=1
|
||||
|
||||
bonus: re
|
||||
bonus: all
|
||||
|
||||
re: fclean all
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,20 @@ typedef struct s_mapdata
|
|||
char error[1024];
|
||||
} 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
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
double yaw;
|
||||
int health;
|
||||
float x;
|
||||
float y;
|
||||
double yaw;
|
||||
int health;
|
||||
struct s_playermove playermove;
|
||||
} t_player;
|
||||
|
||||
typedef struct s_cub3d_data
|
||||
|
|
|
|||
27
ressources/good_maps/othermap.cub
Normal file
27
ressources/good_maps/othermap.cub
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
NO ./path_to_the_north_texture
|
||||
SO ./path_to_the_south_texture
|
||||
WE ./path_to_the_west_texture
|
||||
EA ./path_to_the_east_texture
|
||||
|
||||
F 220,100,0
|
||||
C 225,30,0
|
||||
|
||||
|
||||
11111111 1111111
|
||||
10000001 1000001
|
||||
10000001 1000001
|
||||
10000001 1000001
|
||||
10000001 1000001
|
||||
10000001 1000001
|
||||
11111111 1111111
|
||||
1111111
|
||||
1000001
|
||||
1000001
|
||||
100N001
|
||||
1000001
|
||||
1000001
|
||||
1000001
|
||||
1000001
|
||||
1000001
|
||||
1000001
|
||||
1111111
|
||||
|
|
@ -17,6 +17,6 @@ C 225,30,0
|
|||
110000001101010111M0000010001
|
||||
10000000s00000001100000010001
|
||||
10000000000000001101010010001
|
||||
11000001110101011111011110N0111
|
||||
11000001110101011111011110N01
|
||||
11110111 1110101 101111010001
|
||||
11111111 1111111 111111111111
|
||||
|
|
|
|||
47
src/main.c
47
src/main.c
|
|
@ -6,7 +6,7 @@
|
|||
/* By: tchampio <tchampio@student.42lehavre. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 13:16:11 by tchampio #+# #+# */
|
||||
/* Updated: 2025/07/05 10:30:03 by tchampio ### ########.fr */
|
||||
/* Updated: 2025/07/09 16:23:50 by tchampio ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,6 +15,8 @@
|
|||
#include "../mlx/mlx.h"
|
||||
#include "../includes/maputils.h"
|
||||
#include <stdbool.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/X.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
|
@ -31,7 +33,7 @@ void draw_2d_wall(unsigned int color, t_mlx_data *data,
|
|||
{
|
||||
int i;
|
||||
int j;
|
||||
static int size = 20;
|
||||
static int size = 10;
|
||||
|
||||
i = 0;
|
||||
while (i < size)
|
||||
|
|
@ -61,10 +63,12 @@ int destroy(t_cub3d_data *data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int key_destroy(int keycode, t_cub3d_data *data)
|
||||
int keypress_handler(int keycode, t_cub3d_data *data)
|
||||
{
|
||||
if (keycode == 65307)
|
||||
if (keycode == XK_Escape)
|
||||
destroy(data);
|
||||
else if (keycode == XK_w || keycode == XK_a || keycode == XK_s || keycode == XK_d)
|
||||
ft_printf("salut\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -80,17 +84,17 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
|||
while (map->map[i][j])
|
||||
{
|
||||
if (map->map[i][j] == '1')
|
||||
draw_2d_wall(map->f_color, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(map->f_color, data, 10 * j, 10 * i);
|
||||
else if (map->map[i][j] == 'Z' || map->map[i][j] == 'z')
|
||||
draw_2d_wall(0x0008D9D6, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(0x0008D9D6, data, 10 * j, 10 * i);
|
||||
else if (map->map[i][j] == 'D' || map->map[i][j] == 'd')
|
||||
draw_2d_wall(0x00FF2E63, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(0x00FF2E63, data, 10 * j, 10 * i);
|
||||
else if (map->map[i][j] == 's')
|
||||
draw_2d_wall(0x00E84545, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(0x00E84545, data, 10 * j, 10 * i);
|
||||
else if (map->map[i][j] == 'M')
|
||||
draw_2d_wall(0x00F4CE14, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(0x00F4CE14, data, 10 * j, 10 * i);
|
||||
else if (ft_strchr("NSEW", map->map[i][j]))
|
||||
draw_2d_wall(0x00FF0000, data, 20 * j, 20 * i);
|
||||
draw_2d_wall(0x00FF0000, data, 10 * j, 10 * i);
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
|
|
@ -99,28 +103,9 @@ void draw_map(t_mapdata *map, t_mlx_data *data)
|
|||
|
||||
void init_player(t_mapdata *mapdata, t_player *player)
|
||||
{
|
||||
char facing;
|
||||
|
||||
facing = mapdata->map[mapdata->starty][mapdata->startx];
|
||||
player->health = 100;
|
||||
player->x = mapdata->startx;
|
||||
player->y = mapdata->starty;
|
||||
if (facing == 'N')
|
||||
player->yaw = 0;
|
||||
else if (facing == 'E')
|
||||
player->yaw = 90;
|
||||
else if (facing == 'S')
|
||||
player->yaw = 180;
|
||||
else if (facing == 'W')
|
||||
player->yaw = 270;
|
||||
else
|
||||
player->yaw = 0;
|
||||
}
|
||||
|
||||
void draw_player_pos(t_mapdata *map, t_mlx_data *data)
|
||||
{
|
||||
(void)data;
|
||||
ft_printf("position: %d %d\n", map->startx, map->starty);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
@ -140,8 +125,8 @@ int main(int argc, char **argv)
|
|||
mlx_hook(data.mlx_win, 17, 0L, destroy, &data);
|
||||
init_player(data.map, &(data.player));
|
||||
draw_map(data.map, data.mlx_data);
|
||||
draw_player_pos(data.map, data.mlx_data);
|
||||
mlx_key_hook(data.mlx_win, key_destroy, &data);
|
||||
mlx_hook(data.mlx_win, KeyPress, KeyPressMask, keypress_handler, &data);
|
||||
mlx_hook(data.mlx_win, KeyRelease, KeyReleaseMask, keypress_handler, &data);
|
||||
mlx_put_image_to_window(data.mlx, data.mlx_win, data.mlx_data->img, 0, 0);
|
||||
#ifdef BONUS
|
||||
mlx_string_put(data.mlx, data.mlx_win, 10, 10, 0x00FFFFFF, "compiled with bonuses");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue