better struct and files organization, and still only half raycast on map but no view created
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
# define SCREEN_DIST 50
|
||||
# define SCREEN_SIZE 100
|
||||
# define SCREEN_DEF 50
|
||||
# define PLR_MV 5
|
||||
# define CELL 20
|
||||
|
||||
# define ARROW_LEFT 65361
|
||||
# define ARROW_UP 65362
|
||||
|
||||
@@ -27,17 +27,16 @@ void init_parsing(int ac, char **av, t_game *game);
|
||||
// SRC/HOOK
|
||||
// -------------------------------
|
||||
// keyhook.c
|
||||
int keypress(int keycode, t_game *game);
|
||||
int keyrelease(int keycode, t_game *game);
|
||||
// key_do_action.c
|
||||
void keypress_do_action(t_game *game);
|
||||
// key_is_action_1.c
|
||||
int keypress(int keycode, t_game *game);
|
||||
int keyrelease(int keycode, t_game *game);
|
||||
int hook_action(t_game *game);
|
||||
// key_action_1.c
|
||||
int is_esc(int *k_hook, int *is_action);
|
||||
int is_go_left(int *k_hook, int *is_action);
|
||||
int is_go_right(int *k_hook, int *is_action);
|
||||
int is_go_forward(int *k_hook, int *is_action);
|
||||
int is_go_backward(int *k_hook, int *is_action);
|
||||
// key_is_action_2.c
|
||||
// key_action_2.c
|
||||
int is_turn_left(int *k_hook, int *is_action);
|
||||
int is_turn_right(int *k_hook, int *is_action);
|
||||
|
||||
@@ -46,13 +45,15 @@ int is_turn_right(int *k_hook, int *is_action);
|
||||
// SRC/PLAYER
|
||||
// -------------------------------
|
||||
// player_moves.c
|
||||
void plr_posx_decrement(t_game *game);
|
||||
void plr_posy_decrement(t_game *game);
|
||||
void plr_posx_increment(t_game *game);
|
||||
void plr_posy_increment(t_game *game);
|
||||
void plr_posx_decrement(t_game *game, t_plr *plr);
|
||||
void plr_posy_decrement(t_game *game, t_plr *plr);
|
||||
void plr_posx_increment(t_game *game, t_plr *plr);
|
||||
void plr_posy_increment(t_game *game, t_plr *plr);
|
||||
// player_rotates.c
|
||||
void plr_turn_right(t_game *game);
|
||||
void plr_turn_left(t_game *game);
|
||||
void rotate(t_plr *plr, t_coord *coord);
|
||||
void rotate_double(t_plr *plr, t_d_coord *coord);
|
||||
void plr_turn_right(t_plr *plr);
|
||||
void plr_turn_left(t_plr *plr);
|
||||
// player_limits.c
|
||||
int plr_out_limits(t_game *game, int x, int y);
|
||||
int is_wall(t_game *game, int cell_x, int cell_y);
|
||||
@@ -62,12 +63,11 @@ int is_wall(t_game *game, int cell_x, int cell_y);
|
||||
// -------------------------------
|
||||
// draw.c
|
||||
void draw_pixel(t_game *game, int x, int y, int color);
|
||||
void rotate(t_game *game, int *x, int *y);
|
||||
void rotate_double(t_game *game, double *x, double *y);
|
||||
void draw_line(t_game *game, int start_x, int start_y, int end_x, int end_y, int color);
|
||||
void draw_line(t_game *game, t_vec vec, int color);
|
||||
void draw(t_game *game);
|
||||
// draw_window.c
|
||||
void draw_rays(t_game *game);
|
||||
void draw_map(t_game *game);
|
||||
// raycast.c
|
||||
void raycast(t_game *game, t_rcast *rcast);
|
||||
// ray_intersect.c
|
||||
void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,52 +1,129 @@
|
||||
#ifndef CUBE3D_STRUCT_H
|
||||
# define CUBE3D_STRUCT_H
|
||||
|
||||
/*
|
||||
* 3 structs with coordinates for
|
||||
* - simple precision point
|
||||
* - double precision point
|
||||
* - vector (two points)
|
||||
*/
|
||||
|
||||
typedef struct s_d_coord
|
||||
{
|
||||
double x;
|
||||
double y;
|
||||
} t_d_coord;
|
||||
|
||||
typedef struct s_coord
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} t_coord;
|
||||
|
||||
typedef struct s_vec
|
||||
{
|
||||
int start_x;
|
||||
int start_y;
|
||||
int end_x;
|
||||
int end_y;
|
||||
t_coord start;
|
||||
t_coord end;
|
||||
} t_vec;
|
||||
|
||||
typedef struct s_game
|
||||
/*
|
||||
* struct with all elements for raycasting
|
||||
*/
|
||||
|
||||
typedef struct s_rcast
|
||||
{
|
||||
// window
|
||||
void *mlx_ptr;
|
||||
void *win_ptr;
|
||||
int win_size_x;
|
||||
int win_size_y;
|
||||
// rays
|
||||
t_vec screen_dist;
|
||||
t_vec screen_size;
|
||||
t_vec ray;
|
||||
// tmp
|
||||
int ray_highlight;
|
||||
int ray_activ;
|
||||
// map
|
||||
int map_size_x;
|
||||
int map_size_y;
|
||||
char **map;
|
||||
int cell;
|
||||
int cell_x;
|
||||
int cell_y;
|
||||
int slope_x;
|
||||
int slope_y;
|
||||
int ray_sign_x;
|
||||
int ray_sign_y;
|
||||
int first_next_x;
|
||||
int first_next_y;
|
||||
int next_x;
|
||||
int next_y;
|
||||
int next_cell_x;
|
||||
int next_cell_y;
|
||||
int ray_step_x;
|
||||
int ray_step_y;
|
||||
int is_x;
|
||||
int ray_nb;
|
||||
int wall_height;
|
||||
double ratio;
|
||||
} t_rcast;
|
||||
|
||||
/*
|
||||
* structs for windows, and images associated
|
||||
*/
|
||||
|
||||
typedef struct s_win
|
||||
{
|
||||
void *ptr;
|
||||
int size_x;
|
||||
int size_y;
|
||||
} t_win;
|
||||
|
||||
typedef struct s_img
|
||||
{
|
||||
void *ptr;
|
||||
char *data;
|
||||
int bpp;
|
||||
int sizel;
|
||||
int endian;
|
||||
} t_img;
|
||||
|
||||
/*
|
||||
* structs for the map
|
||||
*/
|
||||
|
||||
typedef struct s_map
|
||||
{
|
||||
char **content;
|
||||
int size_x;
|
||||
int size_y;
|
||||
} t_map;
|
||||
|
||||
/*
|
||||
* structs for the player and its moves
|
||||
*/
|
||||
|
||||
typedef struct s_plr
|
||||
{
|
||||
// player
|
||||
t_d_coord exact;
|
||||
t_coord pos;
|
||||
// rot
|
||||
int rot;
|
||||
double cosi;
|
||||
double cosj;
|
||||
double sini;
|
||||
double sinj;
|
||||
} t_plr;
|
||||
|
||||
/*
|
||||
* struct with all elements for the project
|
||||
*/
|
||||
|
||||
typedef struct s_game
|
||||
{
|
||||
void *mlx_ptr;
|
||||
// map window
|
||||
t_win map_win;
|
||||
t_img map_img;
|
||||
// game window
|
||||
// t_win win;
|
||||
// t_img img;
|
||||
// player
|
||||
double plr_exact_x;
|
||||
double plr_exact_y;
|
||||
int plr_x;
|
||||
int plr_y;
|
||||
t_plr plr;
|
||||
// rays
|
||||
t_rcast rcast;
|
||||
// map
|
||||
t_map map;
|
||||
// key hook
|
||||
int k_hook[MAX_NB_KEY];
|
||||
// image
|
||||
void *img_ptr;
|
||||
char *img_data;
|
||||
int bpp;
|
||||
int sizel;
|
||||
int endian;
|
||||
} t_game;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user