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