better struct and files organization, and still only half raycast on map but no view created

This commit is contained in:
hugogogo
2022-04-22 17:38:29 +02:00
parent 00c9dfd6b8
commit fac1f78230
17 changed files with 602 additions and 505 deletions

View File

@@ -2,7 +2,7 @@
int is_esc(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, KEY_ESC, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_ESC, MAX_NB_KEY))
{
*is_action = 1;
return 1;
@@ -12,12 +12,12 @@ int is_esc(int *k_hook, int *is_action)
int is_go_left(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, KEY_A, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_A, MAX_NB_KEY))
{
*is_action = 1;
return 1;
}
if (!ft_arrintchr(k_hook, KEY_Q, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_Q, MAX_NB_KEY))
{
*is_action = 1;
return 1;
@@ -27,7 +27,7 @@ int is_go_left(int *k_hook, int *is_action)
int is_go_right(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, KEY_D, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_D, MAX_NB_KEY))
{
*is_action = 1;
return 1;
@@ -37,12 +37,12 @@ int is_go_right(int *k_hook, int *is_action)
int is_go_forward(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, KEY_W, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_W, MAX_NB_KEY))
{
*is_action = 1;
return 1;
}
if (!ft_arrintchr(k_hook, KEY_Z, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_Z, MAX_NB_KEY))
{
*is_action = 1;
return 1;
@@ -52,7 +52,7 @@ int is_go_forward(int *k_hook, int *is_action)
int is_go_backward(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, KEY_S, MAX_NB_KEY))
if (!ft_arrint(k_hook, KEY_S, MAX_NB_KEY))
{
*is_action = 1;
return 1;

View File

@@ -2,7 +2,7 @@
int is_turn_left(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, ARROW_LEFT, MAX_NB_KEY))
if (!ft_arrint(k_hook, ARROW_LEFT, MAX_NB_KEY))
{
*is_action = 1;
return 1;
@@ -12,7 +12,7 @@ int is_turn_left(int *k_hook, int *is_action)
int is_turn_right(int *k_hook, int *is_action)
{
if (!ft_arrintchr(k_hook, ARROW_RIGHT, MAX_NB_KEY))
if (!ft_arrint(k_hook, ARROW_RIGHT, MAX_NB_KEY))
{
*is_action = 1;
return 1;

View File

@@ -1,43 +0,0 @@
#include "cube3d.h"
// temp, to test keypress hook
void keypress_do_action(t_game *game)
{
int is_action;
is_action = 0;
if (is_esc(game->k_hook, &is_action))
shut_down(game);
if (is_go_left(game->k_hook, &is_action))
plr_posx_decrement(game);
if (is_go_right(game->k_hook, &is_action))
plr_posx_increment(game);
if (is_go_forward(game->k_hook, &is_action))
plr_posy_decrement(game);
if (is_go_backward(game->k_hook, &is_action))
plr_posy_increment(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);
}

View File

@@ -1,14 +1,38 @@
#include "cube3d.h"
// temp, to map all the keys on linux and mac
static int print_keycode(int keycode)
{
ft_putnbr_fd(keycode, 1);
ft_putchar_fd('\n', 1);
return(0);
}
static int print_keycode(int keycode)
{
ft_putnbr_fd(keycode, 1);
ft_putchar_fd('\n', 1);
return(0);
}
// temp end
int hook_action(t_game *game)
{
int is_action;
is_action = 0;
if (is_esc(game->k_hook, &is_action))
shut_down();
if (is_go_left(game->k_hook, &is_action))
plr_posx_decrement(game, &(game->plr));
if (is_go_right(game->k_hook, &is_action))
plr_posx_increment(game, &(game->plr));
if (is_go_forward(game->k_hook, &is_action))
plr_posy_decrement(game, &(game->plr));
if (is_go_backward(game->k_hook, &is_action))
plr_posy_increment(game, &(game->plr));
if (is_turn_left(game->k_hook, &is_action))
plr_turn_left(&(game->plr));
if (is_turn_right(game->k_hook, &is_action))
plr_turn_right(&(game->plr));
if (is_action)
draw(game);
return(0);
}
int keypress(int keycode, t_game *game)
{
unsigned i;
@@ -24,8 +48,7 @@ int keypress(int keycode, t_game *game)
game->k_hook[i] = 0;
else if (i < MAX_NB_KEY)
game->k_hook[i] = keycode;
keypress_do_action(game);
hook_action(game);
return (0);
}
@@ -38,6 +61,5 @@ int keyrelease(int keycode, t_game *game)
i++;
if (i < MAX_NB_KEY)
game->k_hook[i] = 0;
return (0);
}