player rotates and moves, rays for raycasting on map
This commit is contained in:
@@ -3,15 +3,41 @@
|
||||
// temp, to test keypress hook
|
||||
void keypress_do_action(t_game *game)
|
||||
{
|
||||
if (is_esc(game->k_hook))
|
||||
int is_action;
|
||||
|
||||
is_action = 0;
|
||||
if (is_esc(game->k_hook, &is_action))
|
||||
shut_down(game);
|
||||
if (is_go_left(game->k_hook))
|
||||
if (is_go_left(game->k_hook, &is_action))
|
||||
plr_posx_decrement(game);
|
||||
if (is_go_right(game->k_hook))
|
||||
if (is_go_right(game->k_hook, &is_action))
|
||||
plr_posx_increment(game);
|
||||
if (is_go_forward(game->k_hook))
|
||||
if (is_go_forward(game->k_hook, &is_action))
|
||||
plr_posy_decrement(game);
|
||||
if (is_go_backward(game->k_hook))
|
||||
if (is_go_backward(game->k_hook, &is_action))
|
||||
plr_posy_increment(game);
|
||||
draw(game);
|
||||
if (is_turn_left(game->k_hook, &is_action))
|
||||
plr_turn_left(game);
|
||||
if (is_turn_right(game->k_hook, &is_action))
|
||||
plr_turn_right(game);
|
||||
// temp display one ray with infos
|
||||
if (!ft_arrintchr(game->k_hook, 65364, MAX_NB_KEY))
|
||||
{
|
||||
if (game->ray_highlight <= SCREEN_DEF)
|
||||
game->ray_highlight++;
|
||||
else
|
||||
game->ray_highlight = -1;
|
||||
is_action = 1;
|
||||
}
|
||||
if (!ft_arrintchr(game->k_hook, 65362, MAX_NB_KEY))
|
||||
{
|
||||
if (game->ray_highlight >= 0)
|
||||
game->ray_highlight--;
|
||||
else
|
||||
game->ray_highlight = SCREEN_DEF;
|
||||
is_action = 1;
|
||||
}
|
||||
// temp end
|
||||
if (is_action)
|
||||
draw(game);
|
||||
}
|
||||
|
||||
@@ -1,41 +1,61 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
int is_esc(int *k_hook)
|
||||
int is_esc(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, KEY_ESC, 3))
|
||||
if (!ft_arrintchr(k_hook, KEY_ESC, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_go_left(int *k_hook)
|
||||
int is_go_left(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, KEY_A, 3))
|
||||
if (!ft_arrintchr(k_hook, KEY_A, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
if (!ft_arrintchr(k_hook, KEY_Q, 3))
|
||||
}
|
||||
if (!ft_arrintchr(k_hook, KEY_Q, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_go_right(int *k_hook)
|
||||
int is_go_right(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, KEY_D, 3))
|
||||
if (!ft_arrintchr(k_hook, KEY_D, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_go_forward(int *k_hook)
|
||||
int is_go_forward(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, KEY_W, 3))
|
||||
if (!ft_arrintchr(k_hook, KEY_W, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
if (!ft_arrintchr(k_hook, KEY_Z, 3))
|
||||
}
|
||||
if (!ft_arrintchr(k_hook, KEY_Z, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_go_backward(int *k_hook)
|
||||
int is_go_backward(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, KEY_S, 3))
|
||||
if (!ft_arrintchr(k_hook, KEY_S, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
21
srcs/hook/key_is_action_2.c
Normal file
21
srcs/hook/key_is_action_2.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "cube3d.h"
|
||||
|
||||
int is_turn_left(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, ARROW_LEFT, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_turn_right(int *k_hook, int *is_action)
|
||||
{
|
||||
if (!ft_arrintchr(k_hook, ARROW_RIGHT, MAX_NB_KEY))
|
||||
{
|
||||
*is_action = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ int keypress(int keycode, t_game *game)
|
||||
|
||||
// temp
|
||||
print_keycode(keycode);
|
||||
// temp end
|
||||
|
||||
i = 0;
|
||||
while (i < MAX_NB_KEY && game->k_hook[i] != 0 && game->k_hook[i] != keycode)
|
||||
|
||||
Reference in New Issue
Block a user