DungeonCrawl
Loading...
Searching...
No Matches
map_output.c
Go to the documentation of this file.
1
5#include "map_output.h"
6
8#include "../../../common.h"
10#include "../../io_handler.h"
12
13
14void draw_map_mode(const map_tile_t* arr, const int height, const int width, const vector2d_t anchor,
15 const vector2d_t player_pos) {
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}
95
96
97void draw_player_info(int x, int y, const vector2d_t player_pos) {
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}
Exposes ascii art strings and metadata for those strings.
Defines common macros, types, and global variables for color schemes and utilities.
Exposes functions for the IO-Handler.
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
Header file for logging functionality of the game.
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 draw_map_mode(const map_tile_t *arr, const int height, const int width, const vector2d_t anchor, const vector2d_t player_pos)
Draws the map mode UI based on the given parameters.
Definition map_output.c:14
Exposes functions for outputing to the screen while in the map mode.
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.
bool render_frame(void)
Render the current frame.
Exposes functions for outputting to the console.
2-dimensional vector struct
Definition common.h:164