aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_basic_keys.c8
-rw-r--r--src/ft_extra_keys.c4
-rw-r--r--src/ft_hooks_and_loops.c4
-rw-r--r--src/ft_init_lists.c7
-rw-r--r--src/ft_key_events.c54
-rw-r--r--src/ft_raycasting.c13
6 files changed, 31 insertions, 59 deletions
diff --git a/src/ft_basic_keys.c b/src/ft_basic_keys.c
index d147486..ff74262 100644
--- a/src/ft_basic_keys.c
+++ b/src/ft_basic_keys.c
@@ -17,7 +17,7 @@ int
ft_w_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = 0.2;
+ const float move_speed = FT_MOVE_SPEED;
pl = clist->plist;
pl->pos_y += move_speed * pl->dir_x;
@@ -29,7 +29,7 @@ int
ft_a_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = 0.1;
+ const float move_speed = FT_STRAFE_SPEED;
pl = clist->plist;
pl->pos_y += move_speed * -pl->dir_y;
@@ -41,7 +41,7 @@ int
ft_s_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = 0.2;
+ const float move_speed = FT_MOVE_SPEED;
pl = clist->plist;
pl->pos_y += move_speed * -pl->dir_x;
@@ -53,7 +53,7 @@ int
ft_d_key(t_cub *clist)
{
t_player *pl;
- const float move_speed = 0.1;
+ const float move_speed = FT_STRAFE_SPEED;
pl = clist->plist;
pl->pos_y += move_speed * pl->dir_y;
diff --git a/src/ft_extra_keys.c b/src/ft_extra_keys.c
index bfa8386..39a297b 100644
--- a/src/ft_extra_keys.c
+++ b/src/ft_extra_keys.c
@@ -20,7 +20,7 @@ int
t_player *pl;
float sav_dir_x;
float sav_plane_x;
- const float rot_speed = 0.07;
+ const float rot_speed = FT_ROT_SPEED;
pl = clist->plist;
sav_dir_x = pl->dir_x;
@@ -38,7 +38,7 @@ int
t_player *pl;
float sav_dir_x;
float sav_plane_x;
- const float rot_speed = 0.07;
+ const float rot_speed = FT_ROT_SPEED;
pl = clist->plist;
sav_dir_x = pl->dir_x;
diff --git a/src/ft_hooks_and_loops.c b/src/ft_hooks_and_loops.c
index a494597..b8bdd36 100644
--- a/src/ft_hooks_and_loops.c
+++ b/src/ft_hooks_and_loops.c
@@ -17,7 +17,9 @@
void
ft_hooks_and_loops(t_win *wl, t_cub *cl)
{
- mlx_hook(wl->winptr, 2, 1L << 0, ft_key_event, cl);
+ mlx_hook(wl->winptr, 2, (1L << 0), ft_key_event, cl);
+ mlx_hook(wl->winptr, 3, (1L << 1), ft_key_release, cl);
+ mlx_loop_hook(wl->wlx, ft_key_loop, cl);
mlx_hook(wl->winptr, 17, 0L, ft_click_close, cl);
mlx_loop(wl->wlx);
}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 95f0488..90b8638 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -67,6 +67,7 @@ static t_cub
*ft_init_cub(void)
{
t_cub *clist;
+ uint8_t i;
if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
return (NULL);
@@ -74,6 +75,12 @@ static t_cub
!(clist->mlist = ft_init_map()))
return (NULL);
ft_bzero(clist->errmsg, 40);
+ i = 0;
+ while (i < 5)
+ {
+ clist->key_input[i] = -1;
+ i++;
+ }
clist->minimap = 0;
clist->f_rgb = ft_init_rgb();
clist->c_rgb = ft_init_rgb();
diff --git a/src/ft_key_events.c b/src/ft_key_events.c
index 395761e..317715d 100644
--- a/src/ft_key_events.c
+++ b/src/ft_key_events.c
@@ -15,59 +15,27 @@
#include <stdlib.h>
#include <stdint.h>
-static uint16_t
- ft_set_keycode(const uint16_t tmp_code)
-{
- uint16_t keycode;
-
- keycode = UINT16_MAX;
- (tmp_code == FT_W_KEY) ? (keycode = 0) : 0;
- (tmp_code == FT_A_KEY) ? (keycode = 1) : 0;
- (tmp_code == FT_S_KEY) ? (keycode = 2) : 0;
- (tmp_code == FT_D_KEY) ? (keycode = 3) : 0;
- (tmp_code == FT_L_ARR_KEY) ? (keycode = 4) : 0;
- (tmp_code == FT_R_ARR_KEY) ? (keycode = 5) : 0;
- (tmp_code == 3) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 4) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == 5) ? (keycode = UINT16_MAX) : 0;
- (tmp_code == FT_ESC_KEY) ? (keycode = FT_ESC_KEY) : 0;
- (tmp_code == FT_F1_KEY) ? (keycode = FT_F1_KEY) : 0;
- (tmp_code == FT_TAB_KEY) ? (keycode = FT_TAB_KEY) : 0;
- return (keycode);
-}
-
static void
- ft_secure_player_pos(t_player *pl, t_map *ml)
+ ft_insert_key(uint16_t keycode, t_cub *clist)
{
- (pl->pos_y < 1) ? (pl->pos_y = 1.1) : 0;
- (pl->pos_x < 1) ? (pl->pos_x = 1.1) : 0;
- (pl->pos_y > ml->map_h - 1.4) ? (pl->pos_y = ml->map_h - 1.4) : 0;
- (pl->pos_x > ml->map_w - 1.4) ? (pl->pos_x = ml->map_w - 1.4) : 0;
+ uint8_t i;
+
+ i = 0;
+ while (i < 5 && clist->key_input[i] != keycode && clist->key_input[i] != -1)
+ i++;
+ clist->key_input[i] = keycode;
}
int
ft_key_event(int keycode, t_cub *clist)
{
- int (*fun_ptr[6])(t_cub*);
- const uint16_t tmp_code = keycode;
+ const int32_t tmp_code = keycode;
- fun_ptr[0] = ft_w_key;
- fun_ptr[1] = ft_a_key;
- fun_ptr[2] = ft_s_key;
- fun_ptr[3] = ft_d_key;
- fun_ptr[4] = ft_left_key;
- fun_ptr[5] = ft_right_key;
- keycode = ft_set_keycode(tmp_code);
- if (keycode <= 5)
- {
- (*fun_ptr[keycode])(clist);
- ft_secure_player_pos(clist->plist, clist->mlist);
- ft_draw_scene(clist);
- return (0);
- }
- else if (keycode == FT_ESC_KEY)
+ keycode = ft_convert_keycode(tmp_code);
+ if (keycode == FT_ESC_KEY)
return (ft_exit(0, (clist)));
else if (keycode == FT_F1_KEY || keycode == FT_TAB_KEY)
return (ft_f1_key(clist));
+ ft_insert_key(keycode, clist);
return (0);
}
diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c
index e2530a1..ff73893 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -13,7 +13,6 @@
#include <libft.h>
#include <cub3d.h>
#include <stdint.h>
-#include <stdio.h>
#include <math.h>
void
@@ -29,15 +28,11 @@ void
clist->rlist.tex_x = (int)(clist->rlist.wall_hit_x *
(double)clist->tlist[clist->w_side].img_w);
if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0)
- {
- clist->rlist.tex_x = clist->tlist[clist->w_side].img_w - clist->rlist.tex_x - 1;
- }
+ clist->rlist.tex_x = clist->tlist[clist->w_side].img_w
+ - clist->rlist.tex_x - 1;
if (clist->rlist.side == 1 && clist->rlist.y_ray_dir < 0)
- {
- clist->rlist.tex_x = clist->tlist[clist->w_side].img_w - clist->rlist.tex_x - 1;
- }
- printf("wall_hit_x : %f\ntex_x : %d\nimg_w : %d\n",
- clist->rlist.wall_hit_x, clist->rlist.tex_x, clist->tlist[clist->w_side].img_w);
+ clist->rlist.tex_x = clist->tlist[clist->w_side].img_w
+ - clist->rlist.tex_x - 1;
}
static void