2023-04-26 09:45:21 -04:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* game.h :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2023/04/26 15:29:34 by erey-bet #+# #+# */
|
2023-05-11 10:25:29 -04:00
|
|
|
/* Updated: 2023/05/11 15:28:26 by erey-bet ### ########.fr */
|
2023-04-26 09:45:21 -04:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#ifndef GAME_H
|
|
|
|
# define GAME_H
|
|
|
|
|
2023-04-27 09:13:32 -04:00
|
|
|
# include "../cube3D.h"
|
2023-05-02 09:39:16 -04:00
|
|
|
# include <math.h>
|
2023-05-03 11:48:36 -04:00
|
|
|
# include <stdlib.h>
|
|
|
|
|
2023-05-02 09:39:16 -04:00
|
|
|
# define WIDTH 1920
|
|
|
|
# define HEIGHT 1080
|
2023-05-04 08:42:39 -04:00
|
|
|
# define MOVESPEED 0.10
|
|
|
|
# define ROTATIONSPEED 60
|
2023-04-27 09:13:32 -04:00
|
|
|
|
2023-04-26 09:45:21 -04:00
|
|
|
typedef struct s_player
|
|
|
|
{
|
|
|
|
double pos_x;
|
|
|
|
double pos_y;
|
2023-05-02 09:39:16 -04:00
|
|
|
double dir_x;
|
|
|
|
double dir_y;
|
|
|
|
double pla_x;
|
|
|
|
double pla_y;
|
2023-04-26 09:45:21 -04:00
|
|
|
} t_ply;
|
|
|
|
|
2023-05-02 09:39:16 -04:00
|
|
|
typedef struct s_raycast
|
|
|
|
{
|
2023-05-02 10:58:55 -04:00
|
|
|
double dir_x;
|
|
|
|
double dir_y;
|
2023-05-02 09:39:16 -04:00
|
|
|
} t_ray;
|
|
|
|
|
2023-05-02 10:58:55 -04:00
|
|
|
typedef struct s_dda
|
|
|
|
{
|
|
|
|
int map_x;
|
|
|
|
int map_y;
|
|
|
|
double side_dist_x;
|
|
|
|
double side_dist_y;
|
|
|
|
double delta_dist_x;
|
|
|
|
double delta_dist_y;
|
|
|
|
double perp_wall_dist;
|
|
|
|
int step_x;
|
|
|
|
int step_y;
|
|
|
|
int hit;
|
|
|
|
int side;
|
2023-05-03 06:45:40 -04:00
|
|
|
int line_height;
|
|
|
|
int draw_start;
|
|
|
|
int draw_end;
|
2023-05-02 10:58:55 -04:00
|
|
|
} t_dda;
|
|
|
|
|
2023-05-09 08:46:49 -04:00
|
|
|
typedef struct s_texture_draw
|
|
|
|
{
|
|
|
|
mlx_texture_t *texture;
|
|
|
|
double wall_x;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
double pos;
|
|
|
|
double step;
|
|
|
|
} t_texture_draw;
|
|
|
|
|
2023-04-26 09:45:21 -04:00
|
|
|
typedef struct s_game
|
|
|
|
{
|
2023-05-11 10:25:29 -04:00
|
|
|
mlx_t *mlx;
|
|
|
|
mlx_image_t *window;
|
2023-05-09 08:46:49 -04:00
|
|
|
mlx_texture_t *textures[4];
|
2023-05-11 10:25:29 -04:00
|
|
|
t_ply ply;
|
|
|
|
t_map map;
|
|
|
|
t_ray ray;
|
2023-04-26 09:45:21 -04:00
|
|
|
} t_game;
|
|
|
|
|
2023-04-27 09:13:32 -04:00
|
|
|
/* INIT */
|
2023-05-11 10:25:29 -04:00
|
|
|
int init(t_map map, t_game *game);
|
2023-04-27 09:13:32 -04:00
|
|
|
|
|
|
|
/* MANAGE */
|
2023-05-11 10:25:29 -04:00
|
|
|
void manage(mlx_key_data_t keydata, void *param);
|
2023-04-27 09:13:32 -04:00
|
|
|
|
|
|
|
/* KEYS */
|
2023-05-11 10:25:29 -04:00
|
|
|
int manage_keys(mlx_key_data_t keydata, t_game *game);
|
2023-04-27 09:13:32 -04:00
|
|
|
|
|
|
|
/* RAYCASTING */
|
2023-05-11 10:25:29 -04:00
|
|
|
int raycasting(t_game *game);
|
2023-04-27 09:13:32 -04:00
|
|
|
|
2023-05-03 11:48:36 -04:00
|
|
|
/* DDA ALGO */
|
2023-05-11 10:25:29 -04:00
|
|
|
void dda(t_game *game, int x);
|
|
|
|
|
|
|
|
/* UTILS */
|
|
|
|
double ft_abs(double nb);
|
|
|
|
unsigned int get_rgba(int r, int g, int b, int a);
|
|
|
|
uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y);
|
|
|
|
int get_texture_side(t_dda *dda);
|
|
|
|
|
|
|
|
/* DRAW */
|
|
|
|
void draw(t_game *game, t_dda *dda, int x);
|
2023-04-26 09:45:21 -04:00
|
|
|
#endif
|