Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c8fa690d3 | |||
| fac5b95a82 | |||
| b7954e4234 |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -68,6 +68,7 @@ struct GameContext {
|
||||
// Asset loading helpers
|
||||
Texture2D LoadTextureFromResource(int id);
|
||||
Sound LoadSoundFromResource(int id);
|
||||
void SetWindowIconFromResource(int id);
|
||||
|
||||
// Forward declarations
|
||||
class Ball;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#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 };
|
||||
|
||||
// DevLog buffering & function prototype
|
||||
std::vector<std::string> logHistory;
|
||||
std::mutex logMutex;
|
||||
|
||||
void CustomLogCallback(int logLevel, const char* text, va_list args);
|
||||
@@ -141,6 +141,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\game.h" />
|
||||
<ClInclude Include="include\main.h" />
|
||||
<ClInclude Include="include\menu.h" />
|
||||
<ClInclude Include="include\raylib.h" />
|
||||
<ClInclude Include="include\raymath.h" />
|
||||
@@ -151,14 +152,13 @@
|
||||
<ResourceCompile Include="resources.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="assets\icon.ico" />
|
||||
<Image Include="assets\textures\ball\basic_ball_5.png" />
|
||||
<Image Include="assets\textures\hud\line.png" />
|
||||
<Image Include="assets\textures\paddles\basic_paddle.png" />
|
||||
<Image Include="assets\textures\paddles\basic_paddle_2.png" />
|
||||
<Image Include="assets\textures\spaces\basic_space.png" />
|
||||
<Image Include="assets\textures\spaces\walls.png" />
|
||||
<Image Include="icon.ico" />
|
||||
<Image Include="icon.jpg" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="assets\audio\banana_wall_hit.ogg" />
|
||||
|
||||
@@ -56,6 +56,9 @@
|
||||
<ClInclude Include="include\resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\main.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="assets\textures\ball\basic_ball_5.png">
|
||||
@@ -76,10 +79,7 @@
|
||||
<Image Include="assets\textures\spaces\walls.png">
|
||||
<Filter>Resource Files\textures</Filter>
|
||||
</Image>
|
||||
<Image Include="icon.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
<Image Include="icon.jpg">
|
||||
<Image Include="assets\icon.ico">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#include "include/resource.h"
|
||||
|
||||
IDI_ICON1 ICON "icon.ico"
|
||||
IDI_ICON1 ICON "assets/icon.ico"
|
||||
|
||||
IDR_TEX_BASIC_SPACE RCDATA "assets/textures/spaces/basic_space.png"
|
||||
IDR_TEX_WALLS RCDATA "assets/textures/spaces/walls.png"
|
||||
|
||||
+67
-10
@@ -1,20 +1,25 @@
|
||||
#include <iostream>
|
||||
#include "main.h"
|
||||
#include "game.h"
|
||||
#include "menu.h"
|
||||
#include "resource.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 };
|
||||
#ifdef _WIN32
|
||||
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
||||
extern "C" {
|
||||
int __stdcall AllocConsole();
|
||||
int __stdcall FreeConsole();
|
||||
}
|
||||
bool isConsoleVisible = false;
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
std::cout << "Starting game session" << std::endl;
|
||||
int screen_width = 1280;
|
||||
int screen_height = 800;
|
||||
|
||||
|
||||
SetTraceLogCallback(CustomLogCallback);
|
||||
InitWindow(screen_width, screen_height, "Pong Reloaded");
|
||||
SetWindowIconFromResource(IDI_ICON1);
|
||||
SetTargetFPS(60);
|
||||
InitAudioDevice();
|
||||
|
||||
@@ -61,16 +66,38 @@ int main() {
|
||||
screen_width = GetScreenWidth();
|
||||
screen_height = GetScreenHeight();
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsKeyPressed(KEY_F7)) {
|
||||
isConsoleVisible = !isConsoleVisible;
|
||||
if (isConsoleVisible) {
|
||||
AllocConsole();
|
||||
FILE* dummy;
|
||||
freopen_s(&dummy, "CONOUT$", "w", stdout);
|
||||
freopen_s(&dummy, "CONOUT$", "w", stderr);
|
||||
|
||||
// Dump history
|
||||
std::lock_guard<std::mutex> lock(logMutex);
|
||||
for (const auto& log : logHistory) {
|
||||
printf("%s", log.c_str());
|
||||
}
|
||||
} else {
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update loop
|
||||
switch (ctx.currentState) {
|
||||
case GameState::MainMenu:
|
||||
{
|
||||
int selected = mainMenu.Update();
|
||||
if (selected == 0) {
|
||||
TraceLog(LOG_INFO, "State Transition: MainMenu -> DifficultySelect (Singleplayer)");
|
||||
ctx.isMultiplayer = false;
|
||||
ctx.currentState = GameState::DifficultySelect;
|
||||
}
|
||||
else if (selected == 1) {
|
||||
TraceLog(LOG_INFO, "State Transition: MainMenu -> MultiplayerLobby");
|
||||
ctx.isMultiplayer = true;
|
||||
ctx.score.player_score = 0;
|
||||
ctx.score.player2_score = 0;
|
||||
@@ -94,10 +121,11 @@ int main() {
|
||||
{
|
||||
int selected = difficultyMenu.Update();
|
||||
if (selected >= 0 && selected <= 2) {
|
||||
if (selected == 0) cpu.SetDifficulty(Difficulty::Easy);
|
||||
else if (selected == 1) cpu.SetDifficulty(Difficulty::Normal);
|
||||
else if (selected == 2) cpu.SetDifficulty(Difficulty::Hard);
|
||||
if (selected == 0) { cpu.SetDifficulty(Difficulty::Easy); TraceLog(LOG_INFO, "CPU Difficulty set to: EASY"); }
|
||||
else if (selected == 1) { cpu.SetDifficulty(Difficulty::Normal); TraceLog(LOG_INFO, "CPU Difficulty set to: NORMAL"); }
|
||||
else if (selected == 2) { cpu.SetDifficulty(Difficulty::Hard); TraceLog(LOG_INFO, "CPU Difficulty set to: HARD"); }
|
||||
|
||||
TraceLog(LOG_INFO, "State Transition: DifficultySelect -> Playing");
|
||||
ctx.score.player_score = 0;
|
||||
ctx.score.player2_score = 0;
|
||||
ctx.score.cpu_score = 0;
|
||||
@@ -186,4 +214,33 @@ int main() {
|
||||
CloseAudioDevice();
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CustomLogCallback(int logLevel, const char* text, va_list args) {
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), text, args);
|
||||
|
||||
std::string logStr;
|
||||
switch (logLevel) {
|
||||
case LOG_TRACE: logStr = "TRACE: "; break;
|
||||
case LOG_DEBUG: logStr = "DEBUG: "; break;
|
||||
case LOG_INFO: logStr = "INFO: "; break;
|
||||
case LOG_WARNING: logStr = "WARNING: "; break;
|
||||
case LOG_ERROR: logStr = "ERROR: "; break;
|
||||
case LOG_FATAL: logStr = "FATAL: "; break;
|
||||
default: logStr = "LOG: "; break;
|
||||
}
|
||||
logStr += buffer;
|
||||
logStr += "\n";
|
||||
|
||||
std::lock_guard<std::mutex> lock(logMutex);
|
||||
logHistory.push_back(logStr);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (isConsoleVisible) {
|
||||
printf("%s", logStr.c_str());
|
||||
}
|
||||
#else
|
||||
printf("%s", logStr.c_str());
|
||||
#endif
|
||||
}
|
||||
@@ -50,3 +50,14 @@ Sound LoadSoundFromResource(int id) {
|
||||
UnloadWave(wave);
|
||||
return sound;
|
||||
}
|
||||
|
||||
void SetWindowIconFromResource(int id) {
|
||||
HWND hwnd = (HWND)GetWindowHandle();
|
||||
if (!hwnd) return;
|
||||
|
||||
HICON hIcon = LoadIconA(GetModuleHandle(NULL), MAKEINTRESOURCEA(id));
|
||||
if (hIcon) {
|
||||
SendMessageA(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
|
||||
SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user