Refactor global variable declarations and usage

This commit is contained in:
2026-05-27 00:18:54 +03:00
parent 6c8fa690d3
commit cc718ee511
4 changed files with 24 additions and 13 deletions
+8 -8
View File
@@ -7,15 +7,15 @@
#include <cstdarg>
#include <raylib.h>
// Global colors
Color Green = Color{ 38, 185, 154, 255 };
Color Dark_Green = Color{ 20, 160, 133, 255 };
Color Light_Green = Color{ 129, 204, 184, 255 };
Color Yellow = Color{ 243, 213, 91, 255 };
extern Color Green;
extern Color Dark_Green;
extern Color Light_Green;
extern Color Yellow;
// DevLog buffering & function prototype
std::vector<std::string> logHistory;
std::mutex logMutex;
// DevLog buffering & global variables
extern std::vector<std::string> logHistory;
extern std::mutex logMutex;
extern bool isConsoleVisible;
void CustomLogCallback(int logLevel, const char* text, va_list args);
+3 -2
View File
@@ -1,4 +1,5 @@
#include "game.h"
#include "main.h"
// Paddle implementation
bool Paddle::Update() {
@@ -321,7 +322,7 @@ void DrawGameOverState(const GameContext& ctx, int screenWidth, int screenHeight
if (ctx.isMultiplayer) {
if (ctx.score.player_score > ctx.score.player2_score) {
winnerText = "PLAYER 1 WINS!";
winnerColor = Color{ 38, 185, 154, 255 };
winnerColor = Green;
}
else if (ctx.score.player2_score > ctx.score.player_score) {
winnerText = "PLAYER 2 WINS!";
@@ -333,7 +334,7 @@ void DrawGameOverState(const GameContext& ctx, int screenWidth, int screenHeight
else {
if (ctx.score.player_score > ctx.score.cpu_score) {
winnerText = "YOU WIN!";
winnerColor = Color{ 38, 185, 154, 255 };
winnerColor = Green;
}
else if (ctx.score.cpu_score > ctx.score.player_score) {
winnerText = "CPU WINS!";
+10 -1
View File
@@ -3,13 +3,22 @@
#include "menu.h"
#include "resource.h"
// Define global variables
Color Green = Color{ 38, 185, 154, 255 };
Color Dark_Green = Color{ 20, 160, 133, 255 };
Color Light_Green = Color{ 129, 204, 184, 255 };
Color Yellow = Color{ 243, 213, 91, 255 };
std::vector<std::string> logHistory;
std::mutex logMutex;
bool isConsoleVisible = false;
#ifdef _WIN32
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
extern "C" {
int __stdcall AllocConsole();
int __stdcall FreeConsole();
}
bool isConsoleVisible = false;
#endif
int main() {
+3 -2
View File
@@ -1,4 +1,5 @@
#include "menu.h"
#include "main.h"
int Menu::Update() {
// Menu navigation
@@ -219,7 +220,7 @@ void DrawLobbyState(const GameContext& ctx, int screenWidth, int screenHeight) {
DrawText("Press 'W' to toggle ready", p1X, p1Y + 75, 18, GRAY);
if (ctx.p1Ready) {
DrawRectangle(p1X, p1Y + 115, 220, 50, GREEN);
DrawRectangle(p1X, p1Y + 115, 220, 50, Green);
DrawText("READY", p1X + 110 - MeasureText("READY", 20)/2, p1Y + 130, 20, BLACK);
} else {
DrawRectangle(p1X, p1Y + 115, 220, 50, RED);
@@ -234,7 +235,7 @@ void DrawLobbyState(const GameContext& ctx, int screenWidth, int screenHeight) {
DrawText("Press 'UP' to toggle ready", p2X, p2Y + 75, 18, GRAY);
if (ctx.p2Ready) {
DrawRectangle(p2X, p2Y + 115, 220, 50, GREEN);
DrawRectangle(p2X, p2Y + 115, 220, 50, Green);
DrawText("READY", p2X + 110 - MeasureText("READY", 20)/2, p2Y + 130, 20, BLACK);
} else {
DrawRectangle(p2X, p2Y + 115, 220, 50, RED);