Embed resources and update asset loading system
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 534 534" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;"><path id="rect1" d="M531.584,66.667l0,400c0,35.829 -29.089,64.918 -64.918,64.918l-400,0c-35.829,0 -64.918,-29.089 -64.918,-64.918l-0,-400c0,-35.829 29.089,-64.918 64.918,-64.918l400,-0c35.829,0 64.918,29.089 64.918,64.918Z" style="fill:#f15a22;stroke:#f37547;stroke-width:16.67px;"/><path id="rect7" d="M219.907,130.436l0,270.833c0,11.498 -9.335,20.833 -20.833,20.833l-62.5,0c-11.498,0 -20.833,-9.335 -20.833,-20.833l0,-270.833c0,-11.498 9.335,-20.833 20.833,-20.833l62.5,0c11.498,0 20.833,9.335 20.833,20.833Z" style="fill:#351103;"/><ellipse id="path8" cx="378.086" cy="132.055" rx="41.819" ry="41.667" style="fill:#351103;"/><path id="path9" d="M419.601,422.103l-166.667,-165.047l83.333,-83.333" style="fill:none;fill-rule:nonzero;stroke:#351103;stroke-width:20.83px;stroke-dasharray:20.833,20.833;"/><g id="Layer1"><path d="M299.642,464.615l102.254,0.439c58.476,0 76.672,-30.142 76.672,-89.976l0,-216.824c0,-59.834 -47.475,-108.412 -105.95,-108.412l-211.901,0c-58.476,0 -105.95,48.578 -105.95,108.412l0,216.824c0,59.834 47.475,108.412 105.95,108.412l0.891,0l0,32.558l-16.8,0c-67.256,0 -121.86,-55.872 -121.86,-124.691l-0,-249.382c0,-68.819 54.604,-124.691 121.86,-124.691l243.72,-0c67.256,0 121.86,55.872 121.86,124.691l0,249.382c0,68.077 -29.412,103.976 -95.669,105.163c-0.722,0.013 -15.591,0.315 -16.316,0.315l-111.682,0.323l0.002,-0.264l-11.062,0l0.211,12.303l-28.555,-29.218l28.555,-29.218l-0.633,13.598l24.403,0.255Z" style="fill:#351103;"/></g></svg>
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
+12
-8
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -131,6 +131,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\game.cpp" />
|
||||
<ClCompile Include="src\main.cpp" />
|
||||
<ClCompile Include="src\resource_loader.cpp" />
|
||||
<ClCompile Include="src\menu.cpp">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)/include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
@@ -143,8 +144,12 @@
|
||||
<ClInclude Include="include\menu.h" />
|
||||
<ClInclude Include="include\raylib.h" />
|
||||
<ClInclude Include="include\raymath.h" />
|
||||
<ClInclude Include="include\resource.h" />
|
||||
<ClInclude Include="include\rlgl.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="resources.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="assets\textures\ball\basic_ball_5.png" />
|
||||
<Image Include="assets\textures\hud\line.png" />
|
||||
@@ -152,6 +157,8 @@
|
||||
<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" />
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
@@ -22,6 +18,10 @@
|
||||
<Filter Include="Resource Files\audio">
|
||||
<UniqueIdentifier>{5f42ff18-01e2-4266-a4e0-6dc77ba54e75}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\main.cpp">
|
||||
@@ -33,6 +33,9 @@
|
||||
<ClCompile Include="src\menu.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\resource_loader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\raylib.h">
|
||||
@@ -50,6 +53,9 @@
|
||||
<ClInclude Include="include\menu.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="assets\textures\ball\basic_ball_5.png">
|
||||
@@ -70,6 +76,12 @@
|
||||
<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">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="assets\audio\banana_wall_hit.ogg">
|
||||
@@ -85,4 +97,9 @@
|
||||
<Filter>Resource Files\audio</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="resources.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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"
|
||||
+9
-2
@@ -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) {
|
||||
|
||||
+10
-9
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#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
|
||||
|
||||
@@ -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 <windows.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user