diff options
author | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-01-23 18:11:10 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-01-23 18:11:10 +0100 |
commit | 85d3408331fe61d9dbbeb2231ff10ada1c73017e (patch) | |
tree | 03ae65eada7cf622c4d206c5fa4ad6f325720e67 /src | |
parent | window now closes (diff) | |
download | 42-cub3d-85d3408331fe61d9dbbeb2231ff10ada1c73017e.tar.gz 42-cub3d-85d3408331fe61d9dbbeb2231ff10ada1c73017e.tar.bz2 42-cub3d-85d3408331fe61d9dbbeb2231ff10ada1c73017e.tar.xz 42-cub3d-85d3408331fe61d9dbbeb2231ff10ada1c73017e.tar.zst 42-cub3d-85d3408331fe61d9dbbeb2231ff10ada1c73017e.zip |
Pretty good
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_init_lists.c | 5 | ||||
-rw-r--r-- | src/ft_key_events.c | 44 |
2 files changed, 43 insertions, 6 deletions
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index c61dd45..b6f2932 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -12,8 +12,9 @@ t_winlist wlist->x_size = 800; wlist->y_size = 600; wlist->wlx = mlx_init(); - wlist->winptr = (void*)malloc(800 * 600); - wlist->winptr = mlx_new_window(wlist->wlx, 800, 600, "Cub3D"); + wlist->winptr = (void*)malloc(wlist->x_size * wlist->y_size); + wlist->winptr = mlx_new_window(wlist->wlx, wlist->x_size, wlist->y_size, "Cub3D"); + ft_printf("Created window of size %dx%d\n", wlist->x_size, wlist->y_size); return (wlist); } diff --git a/src/ft_key_events.c b/src/ft_key_events.c index f333cd0..188a770 100644 --- a/src/ft_key_events.c +++ b/src/ft_key_events.c @@ -2,16 +2,52 @@ #include <cub3d.h> #include <stdlib.h> +static int +ft_w_key(void) +{ + ft_printf("w\n"); + return (0); +} + +static int +ft_a_key(void) +{ + ft_printf("a\n"); + return (0); +} + +static int +ft_s_key(void) +{ + ft_printf("s\n"); + return (0); +} + +static int +ft_d_key(void) +{ + ft_printf("d\n"); + return (0); +} + int ft_key_event(int keycode, void *param) { - (void)param; + int (*fun_ptr[4])(void); + + fun_ptr[0] = ft_a_key; + fun_ptr[1] = ft_s_key; + fun_ptr[2] = ft_d_key; + fun_ptr[3] = ft_w_key; ft_printf("Key [%d] pressed\n", keycode); + (keycode == 13) ? (keycode = 3) : 0; + (keycode <= 3) ? (*fun_ptr[keycode])() : 0; if (keycode == 53) { - /* ft_memdel(param->wlx); */ - /* ft_memdel(param->winptr); */ - /* ft_memdel(param); */ + ft_memdel(((t_winlist*)param)->wlx); + ft_memdel(((t_winlist*)param)->winptr); + ft_memdel(((t_winlist*)param)); + ft_printf("Exiting program\n"); exit(0); } return (0); |