#pragma once /** * @file engine.h * @author C. Hölzl * @brief engine header file */ #ifdef __cplusplus extern "C" { #endif #include #include #include "utils.h" /* * Macros */ /* * Type definitions */ typedef enum { QUIT = -1, // QUIT GAME RUN = 0, // RUNNING GAME CONNECT, //CONNECTION TO SERVER WAIT, // WAITING FOR SERVER // WAITING FOR ???? DEADLOCK, //SERVER BROKEN ???? LOAD, // LOADING LEVEL // WAITING FOR GEN TIMEOUT, // TIMEOUT FROM SERVER FINISHED //LOCAL GAME } gs_t; typedef enum {END = -1, START, MENU, SOLO, MULTI, GUIDE, CREDITS, RANKING} gt_t; //game state type typedef enum {UNKNOWN = -1, UP, DOWN, LEFT, RIGHT, INTERACT, INTERACT_PICKUP, INTERACT_DROP, INTERACT_EXIT, TAUNT } action_t; typedef enum { SWALL = 0b00000000000000000000000000000001, NWALL = 0b00000000000000000000000000000010, WWALL = 0b00000000000000000000000000000100, EWALL = 0b00000000000000000000000000001000, RTRAP = 0b00000000000000000000000000010000, RSLOT = 0b00000000111111110000000000000000, RPART = 0b11111111000000000000000000000000, REXIT = 0b00000000000000001000000000000000 } room_elements; #define BOX_ROOM (NWALL | SWALL | EWALL | WWALL | RTRAP | REXIT) typedef u8 part_t; typedef u32 room_t; typedef struct { room_t *list; u32 size; s32 slot_left; u32 level; } maze_t ; #define MAZE_SIZE 1 //Size of Maze To Generate #define DIFINC 2 //Size of Maze Increase Multiplier (exponential) #define MAX_MAZE_SIZE 8 //Max Size to Exit #define FOV 60 #define ROOM_SIZE 11 #define DOOR_SIZE (ROOM_SIZE/4) #define DOOR_OFFSET ((ROOM_SIZE-DOOR_SIZE)/2) #define ELEM_SIZE 4 typedef struct { float32 x; float32 y; float32 r; } position_t; typedef struct { s32 x; s32 y; position_t pos; room_t room; char name[NAME_LEN + 1]; part_t part; u8 taunt; } player_t; typedef struct { s8 x; s8 y; } net_position_t; typedef struct { s32 x; s32 y; net_position_t pos; room_t room; char name[NAME_LEN + 1]; part_t part; u8 taunt; } net_player_t; typedef struct { maze_t* maze; player_t* player; } game_t; /* * Functions */ u8 check_room_has_element(const room_t room, const room_elements element); u8 check_player_has_part(const player_t* const player); part_t get_slot_id(const room_t room); part_t get_part_id(const room_t room); void add_element_to_idx(maze_t* const maze, s16 x, s16 y, const room_elements element, const part_t p, const uint8_t c); room_t* get_room_from_idx(const maze_t* const maze, s32 x, s32 y); maze_t* maze_init(const s16 size, const u8 pop); maze_t* maze_init_wr(); void free_maze(maze_t* maze); maze_t* alloc_maze(s16 size); void print_maze(maze_t* maze, player_t* player, char* path); u8 apply_action_pos(maze_t* maze, player_t* player, action_t action, gs_t* status); //u8 check_room_has_element(room_t room, room_elements element); room_t* get_player_current_room(const maze_t* const maze, const player_t* const player); void update_player_room(maze_t* maze, player_t* player); void move_player_to_random_room(player_t* player, s16 size); u8 is_wall(const s16 x, const s16 y, const room_t room); room_elements is_door(const s16 x, const s16 y, const room_t room); player_t* player_alloc(); player_t* player_init(player_t* player, char* name, u32 maze_size); game_t* game_alloc(); void game_reset(game_t* game, u32 next_lvl, char* name, gs_t* status); game_t* game_init(game_t* game, u32 dims, char* name, gs_t* status); void game_end(game_t* game); #ifdef __cplusplus } #endif