DungeonCrawl
Loading...
Searching...
No Matches
wait_output.c
Go to the documentation of this file.
1
5#include "wait_output.h"
6
8#include "../../io_handler.h"
12
13#include <stdio.h>
14#include <string.h>
15
16// Include platform-specific headers for sleep functions
17#ifndef _WIN32
18 #include <unistd.h>// For usleep on Unix/Linux
19#else
20 #include <windows.h>// For Sleep on Windows
21#endif
22
23// Loading screen message buffer
24static char loading_message[256] = "";
25
26
27// TODO: Attention multiple pre-declaration! io_handler.h & wait_output.h
28void draw_loading_screen(const char* text) {
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}
64
65
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}
118
119
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)
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.
bool get_screen_dimensions(int *width, int *height)
Get the dimensions of the standard plane.
void clear_screen(void)
Clear the screen.
Exposes functions for outputting to the console.
Structure for advanced input events with context data.
Definition input_types.h:43
void draw_welcome_screen(void)
Draw the welcome screen with a message.
void draw_launch_screen(void)
Draw the launch screen with title and animation.
Definition wait_output.c:66
void draw_loading_screen(const char *text)
Draw a loading screen with animation.
Definition wait_output.c:28
Exposes functions for drawing the laoding screen.