DungeonCrawl
Loading...
Searching...
No Matches
map_output.h File Reference

Exposes functions for outputing to the screen while in the map mode. More...

#include "../../../common.h"
#include "../../../map/map.h"

Go to the source code of this file.

Functions

void draw_map_mode (const map_tile_t *arr, int height, int width, vector2d_t anchor, vector2d_t player_pos)
 Draws the map mode UI based on the given parameters.
void draw_player_info (int x, int y, vector2d_t player_pos)
 Draws the player information for the map mode.

Detailed Description

Exposes functions for outputing to the screen while in the map mode.

Definition in file map_output.h.

Function Documentation

◆ draw_map_mode()

void draw_map_mode ( const map_tile_t * arr,
int height,
int width,
vector2d_t anchor,
vector2d_t player_pos )

Draws the map mode UI based on the given parameters.

Parameters
arrThe map array to be drawn
heightThe height of the map
widthThe width of the map
anchorThe anchor position of the map mode, defined as the top left corner
player_posThe position of the player
Note
This function checks makes different checks to ensure the given parameters are valid. The checks are done in the following order:
  • check if the array is NULL
  • check if the height and width are greater than 0
  • check if the anchor position is greater or equal 0
  • check if the player position is within the bounds of the map If any of the checks fail, an error message is logged and the function returns.

Definition at line 14 of file map_output.c.

15 {
16 NULL_PTR_HANDLER_RETURN(arr, , "Draw Map Mode", "In draw_map_mode given array is NULL");
17 CHECK_ARG_RETURN(height <= 0 || width <= 0, , "Draw Map Mode",
18 "In draw_map_mode given height or width is zero or negative");
19 CHECK_ARG_RETURN(anchor.dx < 0 || anchor.dy < 0, , "Draw Map Mode", "In draw_map_mode given anchor is negative");
20 CHECK_ARG_RETURN(player_pos.dx < 0 || player_pos.dy < 0 || player_pos.dx >= width || player_pos.dy >= height, ,
21 "Draw Map Mode", "In draw_map_mode given player position is negative or out of bounds");
22
23 // Print the title using centralized IO handler
24 print_text(anchor.dy, anchor.dx + width / 2 - 7, "Dungeon Crawl", RED_TEXT_COLORS);
25
26 for (int y = 0; y < height; y++) {
27 for (int x = 0; x < width; x++) {
28 // Setup channels (colors)
29 uint64_t channels = 0;
30 const char* ch;
31
32 if (x == player_pos.dx && y == player_pos.dy) {
33 // Player character - using centralized print_text
34 print_text(y + anchor.dy, x + anchor.dx, "@", RED_TEXT_COLORS);
35 continue;
36 }
37
38 //calculated access index
39 const int access_idx = x * height + y;
40
41 switch (arr[access_idx]) {
42 case WALL:
43 channels = WALL_COLORS;
44 ch = "#";
45 break;
46 case FLOOR:
47 channels = FLOOR_COLORS;
48 ch = " ";
49 break;
50 case START_DOOR:
51 channels = START_DOOR_COLORS;
52 ch = "#";
53 break;
54 case EXIT_DOOR:
55 channels = EXIT_DOOR_COLORS;
56 ch = "#";
57 break;
58 case KEY:
59 channels = KEY_COLORS;
60 ch = "$";
61 break;
62 case LIFE_FOUNTAIN:
63 channels = LIFE_FOUNTAIN_COLORS;
64 ch = "+";
65 break;
66 case MANA_FOUNTAIN:
67 channels = MANA_FOUNTAIN_COLORS;
68 ch = "+";
69 break;
70 case GOBLIN:
71 channels = GOBLIN_COLORS;
72 ch = "!";
73 break;
74 case HIDDEN:
75 channels = HIDDEN_COLORS;
76 ch = " ";
77 break;
78 default:
79 log_msg(ERROR, "map_mode", "Unknown tile type: %d", arr[access_idx]);
80 ch = " ";
81 channels = DEFAULT_COLORS;
82 }
83
84 // Use centralized IO for printing
85 print_text(y + anchor.dy, x + anchor.dx, ch, channels);
86 }
87 }
88
89 // Draw player info
90 draw_player_info(anchor.dx, anchor.dy + height + 1, player_pos);
91
92 // Render the frame using centralized IO
94}
void log_msg(const log_level_t level, const char *module, const char *format,...)
Logs a formatted message with a specified log level and module.
Definition logger.c:246
void draw_player_info(int x, int y, const vector2d_t player_pos)
Draws the player information for the map mode.
Definition map_output.c:97
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
bool render_frame(void)
Render the current frame.

◆ draw_player_info()

void draw_player_info ( int x,
int y,
vector2d_t player_pos )

Draws the player information for the map mode.

This function renders player-related information such as health, position, and available commands.

Parameters
xThe x position of the player info to be drawn
yThe y position of the player info to be drawn
player_posThe current player position

Definition at line 97 of file map_output.c.

97 {
98 // Player information using centralized IO
99 print_text_default(y++, x, "Press 'M' for Menu");
100 print_text_default(y++, x, "Press 'L' for Stats");
101 print_text_default(y++, x, "Press 'I' for Inventory");
102
103 // Format player position string
104 char pos_str[64];
105 snprintf(pos_str, sizeof(pos_str), "Player Position: %d, %d", player_pos.dx, player_pos.dy);
106 print_text_default(y + 4, x, pos_str);
107}
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.