DungeonCrawl
Loading...
Searching...
No Matches
combat_output.c
Go to the documentation of this file.
1
5#include "combat_output.h"
6
8#include "../../../common.h"
11#include "../../io_handler.h"
15
16#include <string.h>
17
18vector2d_t draw_combat_view(const vector2d_t anchor, const character_t* player, const character_t* enemy,
19 const char* enemy_sprite, const int sprite_height, const bool red_enemy_sprite) {
21
22 // Copy of the anchor
23 vector2d_t vec = {anchor.dx, anchor.dy};
24
25 // Draw title
26 print_text_default(vec.dy, anchor.dx + 20, "Combat Mode");
27 vec.dy += 2;
28
29 // Draw resource bars
30 vec.dy = draw_resource_bar(vec, player);
31 vec.dy = draw_resource_bar(vec, enemy);
32 vec.dy += 2;
33
34 // display goblin
35 // display image stretched to specific size
36 display_image_at(enemy_sprite, vec.dx + 10, vec.dy, sprite_height, 2 * sprite_height, SCALE_STRETCH);
37 vec.dy += sprite_height + 2;
38
39 // Render the frame
41
42 return vec;
43}
44
45void draw_combat_menu(const vector2d_t anchor, const char* menu_name, char** menu_options,
46 const int menu_option_count, const int selected_index, const char* tail_msg) {
47 if (menu_name == NULL || menu_options == NULL) {
48 log_msg(ERROR, "Combat Output", "Menu options are NULL");
49 return;
50 }
51 const vector2d_t vec = {anchor.dx, anchor.dy};
52
53 // Use centralized menu drawing function
54 print_menu_default(menu_name, menu_options, menu_option_count, selected_index, vec.dy, anchor.dx);
55
56 // Draw tail message if provided
57 if (tail_msg != NULL) {
58 print_text_default(anchor.dy + menu_option_count + 2, anchor.dx, tail_msg);
59 }
60
61 // Render the frame
63}
64
65void draw_combat_log(vector2d_t anchor, const char* combat_log_message) {
66 if (combat_log_message == NULL) {
67 log_msg(ERROR, "Combat Output", "Given combat log message is NULL");
68 return;
69 }
70
71 print_text_default(anchor.dy, anchor.dx, combat_log_message);
72 anchor.dy++;
73 print_text_default(anchor.dy, anchor.dx, "Press any key to continue...");
74 anchor.dy++;
76
77 // Use our input handler to get any key press
78 input_event_t input_event;
79 get_input_blocking(&input_event);
80}
81
82void draw_game_over(void) {
84
85 // Display game over message
86 print_text(1, 1, "Game over", RED_TEXT_COLORS);
87 print_text_default(2, 1, "Press any key to exit...");
89
90 // Use our input handler to get any key press
91 input_event_t input_event;
92 get_input_blocking(&input_event);
93}
94
96 if (c == NULL) {
97 log_msg(ERROR, "Combat Output", "Character is NULL");
98 return anchor.dy;
99 }
100
101 char c_info[MAX_STRING_LENGTH];
102 snprintf(c_info, sizeof(c_info), "%-20s | HP: %4d/%-4d | Mana: %4d/%-4d | Stamina: %4d/%-4d",
103 c->name,
104 c->current_resources.health, c->max_resources.health,
105 c->current_resources.mana, c->max_resources.mana,
106 c->current_resources.stamina, c->max_resources.stamina);
107
108 print_text_default(anchor.dy, anchor.dx, c_info);
109 anchor.dy++;
110 return anchor.dy;
111}
Exposes functions for working working with the character.
void draw_combat_log(vector2d_t anchor, const char *combat_log_message)
Draws the combat log.
void draw_combat_menu(const vector2d_t anchor, const char *menu_name, char **menu_options, const int menu_option_count, const int selected_index, const char *tail_msg)
Draws the combat menu.
vector2d_t draw_combat_view(const vector2d_t anchor, const character_t *player, const character_t *enemy, const char *enemy_sprite, const int sprite_height, const bool red_enemy_sprite)
Draws the combat view UI.
int draw_resource_bar(vector2d_t anchor, const character_t *c)
Draws the resource bar for a character.
void draw_game_over(void)
Draws the game over screen.
Exposes functions for outputing to the screen while in the combat mode.
Defines common macros, types, and global variables for color schemes and utilities.
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
Exposes functions for working with input.
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.
Defines the path and metadata to media files.
bool display_image_at(const char *filename, int x, int y, int height, int width, scale_type_t scale_type)
Display an image file at specified coordinates with scaling.
Exposes functions for drawing to the screen.
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.
void clear_screen(void)
Clear the screen.
void print_menu_default(const char *title, const char **options, int option_count, int selected_index, int y, int x)
Print a menu with selection highlighting using default colors.
Exposes functions for outputting to the console.
Structure for advanced input events with context data.
Definition input_types.h:43
2-dimensional vector struct
Definition common.h:164