Skip to content

Commit

Permalink
Merge pull request #19 from ys-zm/minimap
Browse files Browse the repository at this point in the history
Minimap
  • Loading branch information
JopjeKnopje authored Jan 7, 2024
2 parents 5ca9183 + e2e3621 commit 9561955
Show file tree
Hide file tree
Showing 26 changed files with 10,533 additions and 281 deletions.
4 changes: 2 additions & 2 deletions MLX42/src/font/font.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* font.h :+: :+: */
/* font.h :+: :+: */
/* +:+ */
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/22 12:42:53 by W2Wizard #+# #+# */
/* Updated: 2022/03/03 13:05:57 by lde-la-h ######## odam.nl */
/* Updated: 2024/01/04 01:07:20 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down
4 changes: 2 additions & 2 deletions MLX42/src/font/mlx_font.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* mlx_font.c :+: :+: */
/* mlx_font.c :+: :+: */
/* +:+ */
/* By: W2Wizard <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/02/22 12:01:37 by W2Wizard #+# #+# */
/* Updated: 2022/06/27 19:53:36 by lde-la-h ######## odam.nl */
/* Updated: 2024/01/06 18:26:22 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif

NAME := app
RUN_CMD := ./$(NAME) test_maps/valid.cub
# RUN_CMD := ./$(NAME) test_maps/small.cub

# CFLAGS += -Wall -Wextra -Werror
CFLAGS += -Wall -Wextra
Expand All @@ -38,14 +39,18 @@ SRCS = parser/check_elements.c \
parser/utils_two.c \
utils/error.c \
utils/free.c \
utils/vec2d_utils.c \
utils/colors.c \
game/game.c \
game/draw.c \
game/keys.c \
game/player.c \
game/raycaster.c \
game/render.c \
game/render_minimap.c \
game/render_viewport.c \
game/font/font_renderer.c \
vector/vec2i.c \
vector/vec2d.c \
vector/vec_utils.c \
cub3d.c \
test_utils.c \
timer.c
Expand Down
96 changes: 70 additions & 26 deletions include/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: jboeve <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/11/01 20:07:37 by jboeve #+# #+# */
/* Updated: 2024/01/02 21:52:00 by joppe ######## odam.nl */
/* Updated: 2024/01/07 03:51:44 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,11 @@
#include "MLX42/MLX42.h"

#define UNUSED(x) (void)(x)
#define WARNING(message) \
do { \
fprintf(stderr, "\x1b[0m%s:%d: WARNING: %s\n", __FILE__, __LINE__, message); \
} while (0)

#define UNIMPLEMENTED(message) \
do { \
fprintf(stderr, "\x1b[0m%s:%d: UNIMPLEMENTED: %s\n", __FILE__, __LINE__, message); \
Expand All @@ -44,37 +49,45 @@

#define PI 3.1415926535

// Window settings

// Window
// #define WINDOW_WIDTH 1920
// #define WINDOW_HEIGHT 1080

#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720

#define WINDOW_TITLE "Gammoe"

#define TICK_RATE (1.0 / 60.0)

// TODO Move all this stuff to some kind of game.h
#define CELL_WIDTH 64
#define CELL_HEIGHT 64
#define CELL_SIZE 64

// Game
#define TICK_RATE (1.0 / 60.0)

#define PLAYER_MOVE_SPEED 5.0
#define PLAYER_RUN_MODIFIER 2.5
#define PLAYER_ROTATE_SPEED 5.0
#define PLAYER_ROTATE_MODIFIER 2.5


#define PLAYER_MOV_SPEED 0.08

#define COLOR_BACKGROUND 0x111111FF
#define COLOR_PLAYER 0xFFFFFFFF
#define MINIMAP_WIDTH 350
#define MINIMAP_HEIGHT 230
#define MINIMAP_INFO_HEIGHT 50
#define MINIMAP_COLOR_BACKGROUND 0x111111cc
#define MINIMAP_COLOR_BORDER 0x666666ff
#define MINIMAP_COLOR_PLAYER 0xd32a04FF
#define MINIMAP_PLAYER_SIZE 7
#define MINIMAP_CELL_SIZE 24

#define VIEWPORT_COLOR_CEILING 0x000000FF
#define VIEWPORT_COLOR_FLOOR 0xFFFFFFFF
#define VIEWPORT_COLOR_WALL_NS 0x4B0082FF
#define VIEWPORT_COLOR_WALL_EW 0x8A30E2FF

// #define FOV 0.66
#define FOV 0.85

typedef bool (t_ray_hitfunc) (void *p, uint32_t x, uint32_t y);
typedef bool (t_ray_hitfunc) (const void *p, uint32_t x, uint32_t y);

typedef struct s_meta t_meta;

typedef enum e_cell_type {
Expand All @@ -83,6 +96,24 @@ typedef enum e_cell_type {
MAP_SPACE,
} t_cell_type;

typedef enum e_font_family {
FONT_DEJAVU_14,
FONT_MLX,
FONT_COMICSANS_13,
FONT_COUNT,
} t_font_family;

typedef struct s_font_atlas
{
unsigned int width;
unsigned int height;
unsigned int font_w;
unsigned int font_h;
unsigned int bpp;
char *pixels;
} t_font_atlas;


typedef union s_rgba
{
uint32_t value;
Expand All @@ -103,12 +134,13 @@ typedef enum e_side {
} t_side;

typedef struct s_ray {
t_vec2d direction;
t_vec2d end;
t_side hit_side;
double length;
t_vec2d direction;
double wall_x;
} t_ray;


typedef struct s_player {
t_meta *meta;
t_ray rays[WINDOW_WIDTH];
Expand All @@ -135,10 +167,18 @@ typedef struct s_tex {
t_rgba ceiling_c;
} t_tex;

typedef struct s_minimap {
mlx_image_t *minimap_image;
mlx_image_t *ppos_image;
mlx_image_t *fps_image;
mlx_image_t *info_image;
} t_minimap;

typedef struct s_meta {
mlx_t *mlx;
mlx_image_t *image;
t_timer update_timer;
t_minimap minimap;
t_timer fps_timer;
t_player player;
uint32_t fps;
Expand All @@ -156,34 +196,38 @@ void game_init(t_meta *meta);
void game_loop(void* param);

// player.c
void player_move(t_player *p, t_vec2d transform);
void player_move(t_player *p, t_vec2d transform);
void player_turn(t_player *p, float radiant);
void player_raycast(t_player *p);

// keys.c
void mouse_hook(double xpos, double ypos, void* param);
void cursor_hook(double xpos, double ypos, void* param);
void keys_handle(t_meta *meta, double time_delta);

// render.c
void render_player_viewport(mlx_image_t *image, t_player *p);
void render_clear_bg(mlx_image_t *image);
void render_minimap(mlx_image_t *image, t_map *m);
// render_minimap.c
void render_minimap(t_minimap *minimap, const t_map *map, const t_player *p);

// render_viewport.c
void render_viewport(mlx_image_t *image, t_player *p);

// minimap.c
void minimap_update(mlx_image_t *image, t_player *p);

// draw.c
void draw_rect(mlx_image_t* image, uint32_t x_pos, uint32_t y_pos, uint32_t width, uint32_t height, uint32_t color);
void draw_line(mlx_image_t *image, t_vec2i start, t_vec2i end, t_rgba c);
void draw_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);

// font_renderer.c
const t_font_atlas *cube_get_font_atlas(t_font_family face);
mlx_image_t *cube_put_string(mlx_image_t *image, const char *s, const t_font_atlas *atlas);


// keys.c
void keys_update(mlx_key_data_t keydata, void *param);

// draw.c
void draw_square(mlx_image_t* image, uint32_t x_pos, uint32_t y_pos, uint32_t width, uint32_t height, uint32_t color);
void cube_put_pixel(mlx_image_t* image, uint32_t x, uint32_t y, uint32_t color);

// raycaster.c
t_ray raycaster_cast(t_meta *meta, t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit);
t_ray raycaster_cast(t_vec2d pp, t_vec2d dir, t_ray_hitfunc hit, const void *param);

// colors.c
int32_t set_color(int32_t r, int32_t g, int32_t b, int32_t a);
Expand Down
4 changes: 2 additions & 2 deletions include/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/02 19:56:05 by joppe #+# #+# */
/* Updated: 2024/01/02 21:08:34 by joppe ######## odam.nl */
/* Updated: 2024/01/02 23:20:17 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -22,6 +22,6 @@
void print_cell(t_cell_type cell);
void print_map(char *map, uint32_t w, uint32_t h);
void print_map_cell(t_cell_type *level, uint32_t w, uint32_t h);
void print_ray(const char *s, const t_ray *r);
void print_ray(const char *s, const t_ray *r);

#endif // !TEST_UTILS_H
26 changes: 17 additions & 9 deletions include/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: joppe <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/02 19:07:15 by joppe #+# #+# */
/* Updated: 2024/01/02 21:26:35 by joppe ######## odam.nl */
/* Updated: 2024/01/03 18:35:23 by joppe ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -15,7 +15,6 @@

#include <stdint.h>


typedef struct s_vec2d {
double x;
double y;
Expand All @@ -32,15 +31,24 @@ typedef struct s_vec2u {
} t_vec2u;


// vec2d_utils.c
void print_vec2d(char *str, t_vec2d vector);
// vec2d.c
t_vec2d vec2d_add(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_sub(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_scalar_product(t_vec2d vec, double scalar);
t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_rotate(t_vec2d old, double radiant);
t_vec2d vec2d_add(t_vec2d v1, t_vec2d v2);
t_vec2d vec2u_to_vec2d(t_vec2u v);
double deg_to_rad(float deg);
t_vec2d vec2d_mul(t_vec2d v1, t_vec2d v2);
t_vec2d vec2d_normalize(t_vec2d vec);
t_vec2d vec2d_normalize(t_vec2d vec);

// vec2i.c
t_vec2i vec2i_scalar_product(t_vec2i vec, double scalar);
t_vec2i vec2i_mul(t_vec2i v1, t_vec2i v2);
t_vec2i vec2i_add(t_vec2i v1, t_vec2i v2);

// vec_utils.c
t_vec2i vec2d_to_vec2i(t_vec2d v);
t_vec2d vec2i_to_vec2d(t_vec2i v);
t_vec2d vec2u_to_vec2d(t_vec2u v);
void print_vec2i(char *str, t_vec2i vector);
void print_vec2d(char *str, t_vec2d vector);

#endif // !VECTOR_H
Loading

0 comments on commit 9561955

Please sign in to comment.