diff --git a/Makefile b/Makefile index 2eed4a3..84cbb44 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ fclean: clean bonus: CFLAGS += -D BONUS=1 -bonus: re +bonus: all re: fclean all diff --git a/includes/structs.h b/includes/structs.h index bfafec5..25dffd1 100644 --- a/includes/structs.h +++ b/includes/structs.h @@ -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 diff --git a/ressources/good_maps/othermap.cub b/ressources/good_maps/othermap.cub new file mode 100644 index 0000000..3b5d433 --- /dev/null +++ b/ressources/good_maps/othermap.cub @@ -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 diff --git a/ressources/good_maps/testmap_bonus.cub b/ressources/good_maps/testmap_bonus.cub index 3038d01..d30e41e 100644 --- a/ressources/good_maps/testmap_bonus.cub +++ b/ressources/good_maps/testmap_bonus.cub @@ -17,6 +17,6 @@ C 225,30,0 110000001101010111M0000010001 10000000s00000001100000010001 10000000000000001101010010001 -11000001110101011111011110N0111 +11000001110101011111011110N01 11110111 1110101 101111010001 11111111 1111111 111111111111 diff --git a/src/main.c b/src/main.c index 81115fc..fa85950 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: tchampio +#include +#include #include #include @@ -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");