diff --git a/icon.ico b/icon.ico new file mode 100644 index 0000000..1aded3f Binary files /dev/null and b/icon.ico differ diff --git a/icon.jpg b/icon.jpg new file mode 100644 index 0000000..8539071 Binary files /dev/null and b/icon.jpg differ diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..b82794d --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/include/game.h b/include/game.h index 8d6059a..1938abe 100644 --- a/include/game.h +++ b/include/game.h @@ -65,6 +65,10 @@ struct GameContext { Sound scoreSound = { 0 }; }; +// Asset loading helpers +Texture2D LoadTextureFromResource(int id); +Sound LoadSoundFromResource(int id); + // Forward declarations class Ball; class Paddle; @@ -99,10 +103,10 @@ public: float width; float height; Texture2D texture; - Paddle(Vector2 pos, Color c, float w, float h, const std::string& texturePath = "") + Paddle(Vector2 pos, Color c, float w, float h, int textureId = 0) : GameObject(pos, c), width(w), height(h) { - if (!texturePath.empty()) { - texture = LoadTexture(texturePath.c_str()); + if (textureId > 0) { + texture = LoadTextureFromResource(textureId); } else { texture = { 0 }; } @@ -125,10 +129,10 @@ public: Texture2D texture; public: - Ball(Vector2 pos, Color c, float r, const std::string& texturePath = "") + Ball(Vector2 pos, Color c, float r, int textureId = 0) : GameObject(pos, c), radius(r), velocity({ 5.0f, 5.0f }) { - if (!texturePath.empty()) { - texture = LoadTexture(texturePath.c_str()); + if (textureId > 0) { + texture = LoadTextureFromResource(textureId); } else { texture = { 0 }; } @@ -150,8 +154,8 @@ private: Difficulty currentDifficulty; public: - CpuPaddle(Vector2 pos, Color c, float w, float h, Difficulty diff = Difficulty::Normal, const std::string& texturePath = "") - : Paddle(pos, c, w, h, texturePath) { + CpuPaddle(Vector2 pos, Color c, float w, float h, Difficulty diff = Difficulty::Normal, int textureId = 0) + : Paddle(pos, c, w, h, textureId) { SetDifficulty(diff); } diff --git a/include/raylib.h b/include/raylib.h index bdca643..fc27e85 100644 --- a/include/raylib.h +++ b/include/raylib.h @@ -1333,7 +1333,7 @@ RLAPI Vector2 GetSplinePointBezierCubic(Vector2 p1, Vector2 c2, Vector2 c3, Vect // Basic shapes collision detection functions RLAPI bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2); // Check collision between two rectangles RLAPI bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, float radius2); // Check collision between two circles -RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle +RLAPI bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec); // Check collision between circle and rectangle` RLAPI bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Vector2 p2); // Check if circle collides with a line created betweeen two points [p1] and [p2] RLAPI bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle RLAPI bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius); // Check if point is inside circle diff --git a/include/resource.h b/include/resource.h new file mode 100644 index 0000000..2acf0be --- /dev/null +++ b/include/resource.h @@ -0,0 +1,15 @@ +#pragma once + +#define IDI_ICON1 100 + +#define IDR_TEX_BASIC_SPACE 101 +#define IDR_TEX_WALLS 102 +#define IDR_TEX_LINE 103 +#define IDR_TEX_BALL 104 +#define IDR_TEX_PADDLE 105 +#define IDR_TEX_PADDLE2 106 + +#define IDR_SND_PADDLE_HIT 201 +#define IDR_SND_WALL_HIT 202 +#define IDR_SND_SCORE 203 +#define IDR_SND_BANANA 204 diff --git a/pong-reloaded.vcxproj b/pong-reloaded.vcxproj index ec1dc7c..6edd521 100644 --- a/pong-reloaded.vcxproj +++ b/pong-reloaded.vcxproj @@ -131,6 +131,7 @@ + $(ProjectDir)/include;%(AdditionalIncludeDirectories) $(ProjectDir)/include;%(AdditionalIncludeDirectories) @@ -143,8 +144,12 @@ + + + + @@ -152,6 +157,8 @@ + + diff --git a/pong-reloaded.vcxproj.filters b/pong-reloaded.vcxproj.filters index 7387a9c..bf8fd42 100644 --- a/pong-reloaded.vcxproj.filters +++ b/pong-reloaded.vcxproj.filters @@ -1,10 +1,6 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - {93995380-89BD-4b04-88EB-625FBE52EBFB} h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd @@ -22,6 +18,10 @@ {5f42ff18-01e2-4266-a4e0-6dc77ba54e75} + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + @@ -33,6 +33,9 @@ Source Files + + Source Files + @@ -50,6 +53,9 @@ Header Files + + Header Files + @@ -70,6 +76,12 @@ Resource Files\textures + + Resource Files + + + Resource Files + @@ -85,4 +97,9 @@ Resource Files\audio + + + Resource Files + + \ No newline at end of file diff --git a/resources.rc b/resources.rc new file mode 100644 index 0000000..896ecd1 --- /dev/null +++ b/resources.rc @@ -0,0 +1,15 @@ +#include "include/resource.h" + +IDI_ICON1 ICON "icon.ico" + +IDR_TEX_BASIC_SPACE RCDATA "assets/textures/spaces/basic_space.png" +IDR_TEX_WALLS RCDATA "assets/textures/spaces/walls.png" +IDR_TEX_LINE RCDATA "assets/textures/hud/line.png" +IDR_TEX_BALL RCDATA "assets/textures/ball/basic_ball_5.png" +IDR_TEX_PADDLE RCDATA "assets/textures/paddles/basic_paddle.png" +IDR_TEX_PADDLE2 RCDATA "assets/textures/paddles/basic_paddle_2.png" + +IDR_SND_PADDLE_HIT RCDATA "assets/audio/paddle_hit.ogg" +IDR_SND_WALL_HIT RCDATA "assets/audio/wall_hit.ogg" +IDR_SND_SCORE RCDATA "assets/audio/score.ogg" +IDR_SND_BANANA RCDATA "assets/audio/banana_wall_hit.ogg" diff --git a/src/game.cpp b/src/game.cpp index b54c815..62ad13c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -112,6 +112,13 @@ void DrawCourt(const GameContext& ctx, int screenWidth, int screenHeight) { lineY += ctx.lineTexture.height; } + // Solid background for walls to prevent transparent edge bleeding + Color wallBg = Color{ 72, 85, 107, 255 }; + DrawRectangle(0, 0, screenWidth, 20, wallBg); + DrawRectangle(0, screenHeight - 20, screenWidth, 20, wallBg); + DrawRectangle(0, 0, 20, screenHeight, wallBg); + DrawRectangle(screenWidth - 20, 0, 20, screenHeight, wallBg); + // Border walls (top, bottom, left, right) DrawTexturePro(ctx.wallsTexture, Rectangle{ 0.0f, 0.0f, (float)ctx.wallsTexture.width, (float)ctx.wallsTexture.height }, Rectangle{ 0.0f, 0.0f, (float)screenWidth, 20.0f }, Vector2{ 0.0f, 0.0f }, 0.0f, WHITE); DrawTexturePro(ctx.wallsTexture, Rectangle{ 0.0f, 0.0f, (float)ctx.wallsTexture.width, (float)ctx.wallsTexture.height }, Rectangle{ 0.0f, (float)screenHeight - 20.0f, (float)screenWidth, 20.0f }, Vector2{ 0.0f, 0.0f }, 0.0f, WHITE); @@ -167,7 +174,7 @@ void UpdatePlayingState(GameContext& ctx, Ball& ball, Paddle& player, CpuPaddle& } } } -} +} void DrawPlayingState(const GameContext& ctx, Ball& ball, Paddle& player, CpuPaddle& cpu, int screenWidth, int screenHeight) { DrawCourt(ctx, screenWidth, screenHeight); @@ -238,7 +245,7 @@ void UpdateMultiplayerState(GameContext& ctx, Ball& ball, Paddle& player, CpuPad // Scoring rules int screen_width = GetScreenWidth(); - if (ball.position.x + ball.radius >= screen_width - 20.0f) { + if (ball.position.x + ball.radius >= screen_width - 30.0f) { ctx.score.player2_score++; if (ctx.config.sfxEnabled) PlaySound(ctx.scoreSound); if (ctx.score.player2_score >= ctx.config.maxScore) { diff --git a/src/main.cpp b/src/main.cpp index b0726a6..53167c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include "game.h" #include "menu.h" +#include "resource.h" // Global colors Color Green = Color{ 38, 185, 154, 255 }; @@ -21,34 +22,34 @@ int main() { GameContext ctx; // Asset textures loading - ctx.courtBackground = LoadTexture("assets/textures/spaces/basic_space.png"); - ctx.wallsTexture = LoadTexture("assets/textures/spaces/walls.png"); - ctx.lineTexture = LoadTexture("assets/textures/hud/line.png"); + ctx.courtBackground = LoadTextureFromResource(IDR_TEX_BASIC_SPACE); + ctx.wallsTexture = LoadTextureFromResource(IDR_TEX_WALLS); + ctx.lineTexture = LoadTextureFromResource(IDR_TEX_LINE); // Audio assets loading - ctx.paddleHitSound = LoadSound("assets/audio/paddle_hit.ogg"); - ctx.wallHitSound = LoadSound("assets/audio/wall_hit.ogg"); - ctx.scoreSound = LoadSound("assets/audio/score.ogg"); + ctx.paddleHitSound = LoadSoundFromResource(IDR_SND_PADDLE_HIT); + ctx.wallHitSound = LoadSoundFromResource(IDR_SND_WALL_HIT); + ctx.scoreSound = LoadSoundFromResource(IDR_SND_SCORE); // Entities instantiation Ball ball( Vector2{ screen_width / 2.0f, screen_height / 2.0f }, Yellow, 20.0f, - "assets/textures/ball/basic_ball_5.png" + IDR_TEX_BALL ); ResetBall(ball); Paddle player( Vector2{ screen_width - 20.0f - 10.0f - 25.0f, screen_height / 2.0f - 60.0f }, WHITE, 25.0f, 120.0f, - "assets/textures/paddles/basic_paddle.png" + IDR_TEX_PADDLE ); CpuPaddle cpu( Vector2{ 20.0f + 10.0f, screen_height / 2.0f - 60.0f }, WHITE, 25.0f, 120.0f, Difficulty::Normal, - "assets/textures/paddles/basic_paddle_2.png" + IDR_TEX_PADDLE2 ); // Menu instantiation diff --git a/src/resource_loader.cpp b/src/resource_loader.cpp new file mode 100644 index 0000000..94e78b9 --- /dev/null +++ b/src/resource_loader.cpp @@ -0,0 +1,52 @@ +#define CloseWindow Win32_CloseWindow +#define ShowCursor Win32_ShowCursor +#define Rectangle Win32_Rectangle +#define PlaySound Win32_PlaySound +#define LoadImage Win32_LoadImage +#define DrawText Win32_DrawText +#define DrawTextEx Win32_DrawTextEx + +#define WIN32_LEAN_AND_MEAN +#include + +#undef CloseWindow +#undef ShowCursor +#undef Rectangle +#undef PlaySound +#undef LoadImage +#undef DrawText +#undef DrawTextEx + +#include "game.h" + +Texture2D LoadTextureFromResource(int id) { + Texture2D texture = { 0 }; + HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(id), RT_RCDATA); + if (!hResInfo) return texture; + HGLOBAL hResData = LoadResource(NULL, hResInfo); + if (!hResData) return texture; + int size = SizeofResource(NULL, hResInfo); + unsigned char* data = (unsigned char*)LockResource(hResData); + if (!data) return texture; + + Image img = LoadImageFromMemory(".png", data, size); + texture = LoadTextureFromImage(img); + UnloadImage(img); + return texture; +} + +Sound LoadSoundFromResource(int id) { + Sound sound = { 0 }; + HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(id), RT_RCDATA); + if (!hResInfo) return sound; + HGLOBAL hResData = LoadResource(NULL, hResInfo); + if (!hResData) return sound; + int size = SizeofResource(NULL, hResInfo); + unsigned char* data = (unsigned char*)LockResource(hResData); + if (!data) return sound; + + Wave wave = LoadWaveFromMemory(".ogg", data, size); + sound = LoadSoundFromWave(wave); + UnloadWave(wave); + return sound; +}