DungeonCrawl
Loading...
Searching...
No Matches
wait_output.c File Reference

Implementation for drawing the loading screen. More...

#include "wait_output.h"
#include "../../../logging/logger.h"
#include "../../io_handler.h"
#include "../common/output_handler.h"
#include "../media/media_files.h"
#include "../media/media_output.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

Go to the source code of this file.

Functions

void draw_loading_screen (const char *text)
 Draw a loading screen with animation.
void draw_launch_screen (void)
 Draw the launch screen with title and animation.
void draw_welcome_screen (void)
 Draw the welcome screen with a message.

Detailed Description

Implementation for drawing the loading screen.

Definition in file wait_output.c.

Function Documentation

◆ draw_launch_screen()

void draw_launch_screen ( void )

Draw the launch screen with title and animation.

This function displays the game launch screen with title, version, copyright information, and a loading animation.

Definition at line 66 of file wait_output.c.

66 {
67 // Get screen dimensions
68 int width, height;
69 get_screen_dimensions(&width, &height);
70
71 // Clear the screen
73
74 // Draw game title
75 const char* title = "DUNGEON CRAWL";
76 int title_len = strlen(title);
77 int title_x = (width - title_len) / 2;
78 int title_y = height / 3;
79
80 // Draw the title with a special color
81 print_text(title_y, title_x, title, RED_TEXT_COLORS);
82
83 // Draw version and copyright
84 const char* version = "Version 1.0";
85 const char* copyright = "(C) 2025 DungeonCrawl Team";
86
87 int version_len = strlen(version);
88 int copyright_len = strlen(copyright);
89
90 int version_x = (width - version_len) / 2;
91 int copyright_x = (width - copyright_len) / 2;
92
93 print_text_default(title_y + 2, version_x, version);
94 print_text_default(title_y + 3, copyright_x, copyright);
95
96 // Draw a loading message
97 const char* loading_msg = "Loading game...";
98 int loading_len = strlen(loading_msg);
99
100 // Show simple animation
101 static int frame = 0;
102 frame = (frame + 1) % 4;
103 char anim[5] = "|/-\\";
104 char animation_str[32];
105 snprintf(animation_str, sizeof(animation_str), "%s %c", loading_msg, anim[frame]);
106
107 print_text_default(height - 5, (width - loading_len - 2) / 2, animation_str);
108
109 // Render the frame using centralized IO handler
110 render_frame();
111// Sleep for a short duration to control the animation speed
112#ifdef _WIN32
113 Sleep(50);
114#else
115 usleep(50000);// 50ms
116#endif
117}
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.
bool get_screen_dimensions(int *width, int *height)
Get the dimensions of the standard plane.
void clear_screen(void)
Clear the screen.

◆ draw_loading_screen()

void draw_loading_screen ( const char * text)

Draw a loading screen with animation.

This function displays a loading screen with the specified message and a simple animation to indicate progress.

Parameters
textThe message to display on the loading screen

Definition at line 28 of file wait_output.c.

28 {
29 if (!text) {
30 log_msg(ERROR, "Wait Output", "Loading screen text is NULL");
31 return;
32 }
33
34 // Store the message
35 strncpy(loading_message, text, sizeof(loading_message) - 1);
36 loading_message[sizeof(loading_message) - 1] = '\0';
37
38 // Get screen dimensions
39 int width, height;
40 get_screen_dimensions(&width, &height);
41
42 // Clear the screen
44
45 // Draw loading message
46 int msg_len = strlen(loading_message);
47 int msg_x = (width - msg_len) / 2;
48 int msg_y = height / 2 - 1;
49
50 print_text_default(msg_y, msg_x, loading_message);
51
52 // Draw a simple loading animation based on the current frame
53 static int frame = 0;
54 frame = (frame + 1) % 4;
55
56 char anim[10] = "|/-\\|/-\\";
57 char animation_str[2] = {anim[frame], '\0'};
58
59 print_text_default(msg_y + 2, width / 2, animation_str);
60
61 // Render the frame using centralized IO handler
63}
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

◆ draw_welcome_screen()

void draw_welcome_screen ( void )

Draw the welcome screen with a message.

This function displays a welcome message on the screen and prompts the user to press any key to continue. It's typically shown after the launch screen animation completes.

Definition at line 120 of file wait_output.c.

120 {
121 // Get screen dimensions
122 int width, height;
123 get_screen_dimensions(&width, &height);
124
125 // Clear the screen
126 clear_screen();
127
128 // Draw welcome message
129 const char* welcome_msg = "Welcome to Dungeon Crawl! Press any key to continue...";
130 int msg_len = strlen(welcome_msg);
131 int msg_x = (width - msg_len) / 2;
132 int msg_y = height / 2;
133
134 print_text_default(msg_y, msg_x, welcome_msg);
135
136 // display image stretched to specific size
137 display_image_at(GOBLIN_PNG, 20, msg_y - 10, 20, 25, SCALE_STRETCH);
138
139 // Render the frame using centralized IO handler
140 render_frame();
141
142 // Wait for user input
143 input_event_t input_event;
144 get_input_blocking(&input_event);
145
146 // Clear the screen after input
147 media_cleanup();
148}
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
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.
Structure for advanced input events with context data.
Definition input_types.h:43