219 lines
4.2 KiB
C
219 lines
4.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* types.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/04/15 15:52:44 by qmennen #+# #+# */
|
|
/* Updated: 2025/06/11 16:56:03 by qmennen ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef TYPES_H
|
|
# define TYPES_H
|
|
|
|
# include "cub3d.h"
|
|
|
|
typedef enum TILE
|
|
{
|
|
TILE_VISITED = -2,
|
|
TILE_VOID = -1,
|
|
TILE_EMPTY = 0,
|
|
TILE_WALL = 1,
|
|
TILE_PLAYER = 2,
|
|
TILE_DOOR = 3,
|
|
TILE_DOOR_OPEN = 4,
|
|
} t_tile;
|
|
|
|
typedef enum SPRITE_TYPE
|
|
{
|
|
SPRITE_TYPE_DEFAULT = 0,
|
|
SPRITE_TYPE_COLLECTIBLE = 1,
|
|
SPRITE_TYPE_COLLECTED = 2,
|
|
SPRITE_TYPE_ENEMY = 3,
|
|
SPRITE_TYPE_DISABLED = 4,
|
|
} t_sprite_type;
|
|
|
|
typedef struct s_vec2
|
|
{
|
|
double x;
|
|
double y;
|
|
} t_vec2;
|
|
|
|
typedef struct s_vec2_int
|
|
{
|
|
int x;
|
|
int y;
|
|
} t_vec2_int;
|
|
|
|
typedef struct s_range
|
|
{
|
|
int start;
|
|
int end;
|
|
} t_range;
|
|
|
|
typedef struct s_vec2_line
|
|
{
|
|
t_vec2 support;
|
|
t_vec2 dir;
|
|
} t_vec2_line;
|
|
|
|
typedef struct s_player
|
|
{
|
|
t_vec2 pos;
|
|
t_vec2 dir;
|
|
t_vec2 camera;
|
|
double speed;
|
|
int is_moving;
|
|
float hit_timer;
|
|
float battery;
|
|
} t_player;
|
|
|
|
typedef struct s_sprite
|
|
{
|
|
int n_frames;
|
|
int animation_speed;
|
|
double dist;
|
|
double cam_frac;
|
|
int alpha;
|
|
mlx_texture_t *texture;
|
|
t_sprite_type type;
|
|
t_vec2 pos;
|
|
} t_sprite;
|
|
|
|
typedef struct s_sprite_lib
|
|
{
|
|
mlx_texture_t *texture;
|
|
t_sprite_type type;
|
|
int collectible;
|
|
} t_sprite_lib;
|
|
|
|
typedef struct s_map
|
|
{
|
|
unsigned int width;
|
|
unsigned int height;
|
|
t_tile **grid;
|
|
mlx_texture_t *texture_floor;
|
|
mlx_texture_t *texture_ceiling;
|
|
mlx_texture_t *textures[5];
|
|
t_sprite *sprites;
|
|
t_sprite_lib *sprite_lib;
|
|
unsigned int n_sprites;
|
|
unsigned int n_sprites_max;
|
|
unsigned int floor_color;
|
|
unsigned int ceiling_color;
|
|
} t_map;
|
|
|
|
typedef int (*t_token_handler)(char *token, t_map *map);
|
|
|
|
typedef struct s_keyboard
|
|
{
|
|
int keys[NUM_KEYS];
|
|
int last_keys[NUM_KEYS];
|
|
} t_keyboard;
|
|
|
|
typedef struct s_screen
|
|
{
|
|
mlx_t *mlx;
|
|
mlx_image_t *img;
|
|
mlx_image_t *minimap;
|
|
mlx_image_t *background;
|
|
mlx_image_t *hud;
|
|
unsigned int width;
|
|
unsigned int height;
|
|
int u_time_location;
|
|
int u_battery_location;
|
|
int u_resolution_location;
|
|
int u_hit_timer_location;
|
|
int u_enabled_location;
|
|
int u_bobtime_location;
|
|
int u_ismoving_location;
|
|
int flash;
|
|
} t_screen;
|
|
|
|
typedef enum e_side
|
|
{
|
|
SIDE_NORTH,
|
|
SIDE_SOUTH,
|
|
SIDE_WEST,
|
|
SIDE_EAST,
|
|
SIDE_DOOR,
|
|
} t_side;
|
|
|
|
typedef enum e_game_state
|
|
{
|
|
GAME_STATE_MENU,
|
|
GAME_STATE_PLAYING,
|
|
GAME_STATE_END_SCREEN,
|
|
} t_game_state;
|
|
|
|
typedef struct s_render
|
|
{
|
|
double perp_dist;
|
|
int sign;
|
|
int door;
|
|
t_side side;
|
|
double wall_x;
|
|
} t_render;
|
|
|
|
typedef struct s_sprite_column
|
|
{
|
|
t_vec2_int start;
|
|
t_vec2_int end;
|
|
int x;
|
|
} t_sprite_column;
|
|
|
|
typedef struct s_scoreboard
|
|
{
|
|
int tiles_visited;
|
|
int total_tiles;
|
|
int collectibles;
|
|
int enemies;
|
|
int start_time;
|
|
int end_time;
|
|
mlx_image_t *texts[5];
|
|
} t_scoreboard;
|
|
|
|
typedef struct s_game
|
|
{
|
|
t_map *map;
|
|
t_player *player;
|
|
t_screen *screen;
|
|
t_keyboard *keyboard;
|
|
t_scoreboard *scoreboard;
|
|
mlx_image_t *screenshots[MAX_SCREENSHOTS];
|
|
struct s_game_manager *manager;
|
|
int fps;
|
|
int screenshot_idx;
|
|
} t_game;
|
|
|
|
typedef struct s_game_manager
|
|
{
|
|
t_game_state state;
|
|
t_game *game;
|
|
struct s_menu *menu;
|
|
struct s_menu *end_screen;
|
|
struct s_menu **active_menu;
|
|
} t_game_manager;
|
|
|
|
typedef struct s_menu_item
|
|
{
|
|
char *text;
|
|
mlx_image_t *image;
|
|
void (*act)(struct s_menu_item *item, t_game_manager *manager);
|
|
} t_menu_item;
|
|
|
|
typedef struct s_menu
|
|
{
|
|
int selected_option;
|
|
int num_options;
|
|
int hidden;
|
|
t_menu_item *items[MAX_MENU_OPTIONS];
|
|
mlx_image_t *selector;
|
|
mlx_image_t *background;
|
|
|
|
} t_menu;
|
|
|
|
#endif
|