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

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

#include "../../../character/character_fw.h"
#include "../../../common.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Functions

vector2d_t draw_combat_view (vector2d_t anchor, const character_t *player, const character_t *enemy, const char *enemy_sprite, int sprite_height, bool red_enemy_sprite)
 Draws the combat view UI.
void draw_combat_menu (vector2d_t anchor, const char *menu_name, char **menu_options, int menu_option_count, int selected_index, const char *tail_msg)
 Draws the combat menu.
void draw_combat_log (vector2d_t anchor, const char *combat_log_message)
 Draws the combat log.
void draw_game_over (void)
 Draws the game over screen.
int draw_resource_bar (vector2d_t anchor, const character_t *c)
 Draws the resource bar for a character.

Detailed Description

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

Definition in file combat_output.h.

Function Documentation

◆ draw_combat_log()

void draw_combat_log ( vector2d_t anchor,
const char * combat_log_message )

Draws the combat log.

This function displays a combat log message and waits for user input before continuing.

Parameters
anchorThe anchor point of the combat log, representing the top-left corner
combat_log_messageThe message to be displayed in the combat log

Definition at line 65 of file combat_output.c.

65 {
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}
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
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 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.
Structure for advanced input events with context data.
Definition input_types.h:43

◆ draw_combat_menu()

void draw_combat_menu ( vector2d_t anchor,
const char * menu_name,
char ** menu_options,
int menu_option_count,
int selected_index,
const char * tail_msg )

Draws the combat menu.

This function renders a menu for the combat mode with selectable options.

Parameters
anchorThe anchor point of the combat menu, representing the top left corner
menu_nameThe name of the menu
menu_optionsThe options of the menu
menu_option_countThe number of options in the menu
selected_indexThe index of the selected option
tail_msgThe message to be displayed at the bottom of the menu. If the message is NULL, it will not be displayed.

Definition at line 45 of file combat_output.c.

46 {
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}
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.
2-dimensional vector struct
Definition common.h:164

◆ draw_combat_view()

vector2d_t draw_combat_view ( vector2d_t anchor,
const character_t * player,
const character_t * enemy,
const char * enemy_sprite,
int sprite_height,
bool red_enemy_sprite )

Draws the combat view UI.

This function renders the combat view including player and enemy information, as well as the enemy sprite.

Parameters
anchorThe anchor point of the combat view, representing the top left corner
playerThe player character
enemyThe enemy character
enemy_spriteThe sprite of the enemy
sprite_heightThe height of the enemy sprite
red_enemy_spriteIf true, the enemy sprite will be drawn in red
Returns
The new anchor point after drawing the combat view

Definition at line 18 of file combat_output.c.

19 {
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}
int draw_resource_bar(vector2d_t anchor, const character_t *c)
Draws the resource bar for a character.
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.
void clear_screen(void)
Clear the screen.

◆ draw_game_over()

void draw_game_over ( void )

Draws the game over screen.

This function displays a game over message and waits for user input.

Definition at line 82 of file combat_output.c.

82 {
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}
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.

◆ draw_resource_bar()

int draw_resource_bar ( vector2d_t anchor,
const character_t * c )

Draws the resource bar for a character.

This function displays the character's name, health, mana, and stamina in a formatted bar.

Parameters
anchorThe anchor point for the resource bar, representing the top-left corner
cA pointer to the character whose resources are to be displayed
Returns
The updated y-coordinate after drawing the resource bar

Definition at line 95 of file combat_output.c.

95 {
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}