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
|
// Asset loading helpers
|
||||||
Texture2D LoadTextureFromResource(int id);
|
Texture2D LoadTextureFromResource(int id);
|
||||||
Sound LoadSoundFromResource(int id);
|
Sound LoadSoundFromResource(int id);
|
||||||
|
void SetWindowIconFromResource(int id);
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class Ball;
|
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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="include\game.h" />
|
<ClInclude Include="include\game.h" />
|
||||||
|
<ClInclude Include="include\main.h" />
|
||||||
<ClInclude Include="include\menu.h" />
|
<ClInclude Include="include\menu.h" />
|
||||||
<ClInclude Include="include\raylib.h" />
|
<ClInclude Include="include\raylib.h" />
|
||||||
<ClInclude Include="include\raymath.h" />
|
<ClInclude Include="include\raymath.h" />
|
||||||
@@ -151,14 +152,13 @@
|
|||||||
<ResourceCompile Include="resources.rc" />
|
<ResourceCompile Include="resources.rc" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Image Include="assets\icon.ico" />
|
||||||
<Image Include="assets\textures\ball\basic_ball_5.png" />
|
<Image Include="assets\textures\ball\basic_ball_5.png" />
|
||||||
<Image Include="assets\textures\hud\line.png" />
|
<Image Include="assets\textures\hud\line.png" />
|
||||||
<Image Include="assets\textures\paddles\basic_paddle.png" />
|
<Image Include="assets\textures\paddles\basic_paddle.png" />
|
||||||
<Image Include="assets\textures\paddles\basic_paddle_2.png" />
|
<Image Include="assets\textures\paddles\basic_paddle_2.png" />
|
||||||
<Image Include="assets\textures\spaces\basic_space.png" />
|
<Image Include="assets\textures\spaces\basic_space.png" />
|
||||||
<Image Include="assets\textures\spaces\walls.png" />
|
<Image Include="assets\textures\spaces\walls.png" />
|
||||||
<Image Include="icon.ico" />
|
|
||||||
<Image Include="icon.jpg" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="assets\audio\banana_wall_hit.ogg" />
|
<None Include="assets\audio\banana_wall_hit.ogg" />
|
||||||
|
|||||||
@@ -56,6 +56,9 @@
|
|||||||
<ClInclude Include="include\resource.h">
|
<ClInclude Include="include\resource.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\main.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="assets\textures\ball\basic_ball_5.png">
|
<Image Include="assets\textures\ball\basic_ball_5.png">
|
||||||
@@ -76,10 +79,7 @@
|
|||||||
<Image Include="assets\textures\spaces\walls.png">
|
<Image Include="assets\textures\spaces\walls.png">
|
||||||
<Filter>Resource Files\textures</Filter>
|
<Filter>Resource Files\textures</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
<Image Include="icon.ico">
|
<Image Include="assets\icon.ico">
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Image>
|
|
||||||
<Image Include="icon.jpg">
|
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#include "include/resource.h"
|
#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_BASIC_SPACE RCDATA "assets/textures/spaces/basic_space.png"
|
||||||
IDR_TEX_WALLS RCDATA "assets/textures/spaces/walls.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 "game.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
// Global colors
|
#ifdef _WIN32
|
||||||
Color Green = Color{ 38, 185, 154, 255 };
|
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
||||||
Color Dark_Green = Color{ 20, 160, 133, 255 };
|
extern "C" {
|
||||||
Color Light_Green = Color{ 129, 204, 184, 255 };
|
int __stdcall AllocConsole();
|
||||||
Color Yellow = Color{ 243, 213, 91, 255 };
|
int __stdcall FreeConsole();
|
||||||
|
}
|
||||||
|
bool isConsoleVisible = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Starting game session" << std::endl;
|
std::cout << "Starting game session" << std::endl;
|
||||||
int screen_width = 1280;
|
int screen_width = 1280;
|
||||||
int screen_height = 800;
|
int screen_height = 800;
|
||||||
|
|
||||||
|
SetTraceLogCallback(CustomLogCallback);
|
||||||
InitWindow(screen_width, screen_height, "Pong Reloaded");
|
InitWindow(screen_width, screen_height, "Pong Reloaded");
|
||||||
|
SetWindowIconFromResource(IDI_ICON1);
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
@@ -61,16 +66,38 @@ int main() {
|
|||||||
screen_width = GetScreenWidth();
|
screen_width = GetScreenWidth();
|
||||||
screen_height = GetScreenHeight();
|
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
|
// Update loop
|
||||||
switch (ctx.currentState) {
|
switch (ctx.currentState) {
|
||||||
case GameState::MainMenu:
|
case GameState::MainMenu:
|
||||||
{
|
{
|
||||||
int selected = mainMenu.Update();
|
int selected = mainMenu.Update();
|
||||||
if (selected == 0) {
|
if (selected == 0) {
|
||||||
|
TraceLog(LOG_INFO, "State Transition: MainMenu -> DifficultySelect (Singleplayer)");
|
||||||
ctx.isMultiplayer = false;
|
ctx.isMultiplayer = false;
|
||||||
ctx.currentState = GameState::DifficultySelect;
|
ctx.currentState = GameState::DifficultySelect;
|
||||||
}
|
}
|
||||||
else if (selected == 1) {
|
else if (selected == 1) {
|
||||||
|
TraceLog(LOG_INFO, "State Transition: MainMenu -> MultiplayerLobby");
|
||||||
ctx.isMultiplayer = true;
|
ctx.isMultiplayer = true;
|
||||||
ctx.score.player_score = 0;
|
ctx.score.player_score = 0;
|
||||||
ctx.score.player2_score = 0;
|
ctx.score.player2_score = 0;
|
||||||
@@ -94,10 +121,11 @@ int main() {
|
|||||||
{
|
{
|
||||||
int selected = difficultyMenu.Update();
|
int selected = difficultyMenu.Update();
|
||||||
if (selected >= 0 && selected <= 2) {
|
if (selected >= 0 && selected <= 2) {
|
||||||
if (selected == 0) cpu.SetDifficulty(Difficulty::Easy);
|
if (selected == 0) { cpu.SetDifficulty(Difficulty::Easy); TraceLog(LOG_INFO, "CPU Difficulty set to: EASY"); }
|
||||||
else if (selected == 1) cpu.SetDifficulty(Difficulty::Normal);
|
else if (selected == 1) { cpu.SetDifficulty(Difficulty::Normal); TraceLog(LOG_INFO, "CPU Difficulty set to: NORMAL"); }
|
||||||
else if (selected == 2) cpu.SetDifficulty(Difficulty::Hard);
|
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.player_score = 0;
|
||||||
ctx.score.player2_score = 0;
|
ctx.score.player2_score = 0;
|
||||||
ctx.score.cpu_score = 0;
|
ctx.score.cpu_score = 0;
|
||||||
@@ -186,4 +214,33 @@ int main() {
|
|||||||
CloseAudioDevice();
|
CloseAudioDevice();
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
return 0;
|
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);
|
UnloadWave(wave);
|
||||||
return sound;
|
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