Add project files.
This commit is contained in:
+111
@@ -0,0 +1,111 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// Game States & Configurations
|
||||||
|
enum class GameState {
|
||||||
|
MainMenu,
|
||||||
|
Playing,
|
||||||
|
Paused,
|
||||||
|
GameOver
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Difficulty {
|
||||||
|
Easy,
|
||||||
|
Normal,
|
||||||
|
Hard
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr float CPU_SPEED_EASY = 3.0f;
|
||||||
|
constexpr float CPU_SPEED_NORMAL = 5.5f;
|
||||||
|
constexpr float CPU_SPEED_HARD = 8.0f;
|
||||||
|
|
||||||
|
// --- Base Entities ---
|
||||||
|
|
||||||
|
class GameObject {
|
||||||
|
public:
|
||||||
|
Vector2 position;
|
||||||
|
Color color;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GameObject(Vector2 pos, Color c) : position(pos), color(c) {}
|
||||||
|
virtual ~GameObject() = default;
|
||||||
|
|
||||||
|
virtual void Update() = 0;
|
||||||
|
virtual void Draw() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// --- Game Objects ---
|
||||||
|
|
||||||
|
class Paddle : public GameObject {
|
||||||
|
public:
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
|
||||||
|
Paddle(Vector2 pos, Color c, float w, float h)
|
||||||
|
: GameObject(pos, c), width(w), height(h) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() override;
|
||||||
|
void Draw() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Ball : public GameObject {
|
||||||
|
public:
|
||||||
|
float radius;
|
||||||
|
Vector2 velocity;
|
||||||
|
|
||||||
|
Ball(Vector2 pos, Color c, float r)
|
||||||
|
: GameObject(pos, c), radius(r), velocity({ 5.0f, 5.0f }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() override;
|
||||||
|
void Draw() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CpuPaddle : public Paddle {
|
||||||
|
private:
|
||||||
|
float speed;
|
||||||
|
Difficulty currentDifficulty;
|
||||||
|
|
||||||
|
public:
|
||||||
|
CpuPaddle(Vector2 pos, Color c, float w, float h, Difficulty diff = Difficulty::Normal)
|
||||||
|
: Paddle(pos, c, w, h) {
|
||||||
|
SetDifficulty(diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetDifficulty(Difficulty diff) {
|
||||||
|
currentDifficulty = diff;
|
||||||
|
switch (currentDifficulty) {
|
||||||
|
case Difficulty::Easy: speed = CPU_SPEED_EASY; break;
|
||||||
|
case Difficulty::Normal: speed = CPU_SPEED_NORMAL; break;
|
||||||
|
case Difficulty::Hard: speed = CPU_SPEED_HARD; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(float ball_y) {
|
||||||
|
float paddleCenter = position.y + (height / 2.0f);
|
||||||
|
|
||||||
|
if (paddleCenter > ball_y + speed) {
|
||||||
|
position.y -= speed;
|
||||||
|
}
|
||||||
|
else if (paddleCenter < ball_y - speed) {
|
||||||
|
position.y += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
LimitMovement();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() override {}
|
||||||
|
|
||||||
|
void LimitMovement() {
|
||||||
|
if (position.y <= 0) {
|
||||||
|
position.y = 0;
|
||||||
|
}
|
||||||
|
if (position.y + height >= GetScreenHeight()) {
|
||||||
|
position.y = GetScreenHeight() - height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "game.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
// --- UI / Systems ---
|
||||||
|
|
||||||
|
class Menu {
|
||||||
|
private:
|
||||||
|
std::string title;
|
||||||
|
std::vector<std::string> options;
|
||||||
|
int selectedIndex;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Menu(std::string menuTitle, std::vector<std::string> menuOptions)
|
||||||
|
: title(menuTitle), options(menuOptions), selectedIndex(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(GameState& currentState);
|
||||||
|
void Draw();
|
||||||
|
};
|
||||||
+1743
File diff suppressed because it is too large
Load Diff
+3139
File diff suppressed because it is too large
Load Diff
+5421
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.14.37301.10 d17.14
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pong-reloaded", "pong-reloaded.vcxproj", "{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Release|x64.Build.0 = Release|x64
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{5625F10E-21DC-4C81-AC0B-6AC3DCDBE093}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7E10DB46-7A14-42EE-B378-4BBC7259BCD9}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{5625f10e-21dc-4c81-ac0b-6ac3dcdbe093}</ProjectGuid>
|
||||||
|
<RootNamespace>pongreloaded</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>$(ProjectDir)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>raylib.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>$(ProjectDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>$(ProjectDir)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>raylib.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\game.cpp" />
|
||||||
|
<ClCompile Include="src\main.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>
|
||||||
|
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">stdcpp20</LanguageStandard>
|
||||||
|
<LanguageStandard Condition="'$(Configuration)|$(Platform)'=='Release|x64'">stdcpp20</LanguageStandard>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="include\game.h" />
|
||||||
|
<ClInclude Include="include\menu.h" />
|
||||||
|
<ClInclude Include="include\raylib.h" />
|
||||||
|
<ClInclude Include="include\raymath.h" />
|
||||||
|
<ClInclude Include="include\rlgl.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?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>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files\RayLib">
|
||||||
|
<UniqueIdentifier>{2f179593-5e9f-4095-be57-3f12f03a9705}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="src\main.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\game.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\menu.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="include\raylib.h">
|
||||||
|
<Filter>Header Files\RayLib</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\raymath.h">
|
||||||
|
<Filter>Header Files\RayLib</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\rlgl.h">
|
||||||
|
<Filter>Header Files\RayLib</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\game.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\menu.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
// --- Paddle Implementation ---
|
||||||
|
|
||||||
|
void Paddle::Update() {
|
||||||
|
float speed = 6.0f;
|
||||||
|
|
||||||
|
if (IsKeyDown(KEY_UP)) {
|
||||||
|
position.y -= speed;
|
||||||
|
}
|
||||||
|
if (IsKeyDown(KEY_DOWN)) {
|
||||||
|
position.y += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit movement
|
||||||
|
if (position.y <= 0) {
|
||||||
|
position.y = 0;
|
||||||
|
}
|
||||||
|
if (position.y + height >= GetScreenHeight()) {
|
||||||
|
position.y = GetScreenHeight() - height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Paddle::Draw() {
|
||||||
|
DrawRectangleRounded(Rectangle{ position.x, position.y, width, height }, 0.8f, 0, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// --- Ball Implementation ---
|
||||||
|
|
||||||
|
void Ball::Update() {
|
||||||
|
position.x += velocity.x;
|
||||||
|
position.y += velocity.y;
|
||||||
|
|
||||||
|
if (position.y + radius >= GetScreenHeight() || position.y - radius <= 0) {
|
||||||
|
velocity.y *= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ball::Draw() {
|
||||||
|
// Cast to int as DrawCircle expects integers for coordinates
|
||||||
|
DrawCircle((int)position.x, (int)position.y, radius, color);
|
||||||
|
}
|
||||||
+111
@@ -0,0 +1,111 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "game.h"
|
||||||
|
#include "menu.h"
|
||||||
|
|
||||||
|
// 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 };
|
||||||
|
|
||||||
|
int player_score = 0;
|
||||||
|
int cpu_score = 0;
|
||||||
|
|
||||||
|
// Helper function to reset the ball
|
||||||
|
void ResetBall(Ball& ball, int screenWidth, int screenHeight) {
|
||||||
|
ball.position.x = screenWidth / 2.0f;
|
||||||
|
ball.position.y = screenHeight / 2.0f;
|
||||||
|
|
||||||
|
int speed_choices[2] = { -1, 1 };
|
||||||
|
ball.velocity.x *= speed_choices[GetRandomValue(0, 1)];
|
||||||
|
ball.velocity.y *= speed_choices[GetRandomValue(0, 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << "Starting the game" << std::endl;
|
||||||
|
const int screen_width = 1280;
|
||||||
|
const int screen_height = 800;
|
||||||
|
InitWindow(screen_width, screen_height, "My Pong Game!");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
// --- Instantiate Objects using the new Constructors ---
|
||||||
|
|
||||||
|
Ball ball(Vector2{ screen_width / 2.0f, screen_height / 2.0f }, Yellow, 20.0f);
|
||||||
|
ball.velocity = Vector2{ 7.0f, 7.0f };
|
||||||
|
|
||||||
|
Paddle player(
|
||||||
|
Vector2{ screen_width - 35.0f, screen_height / 2.0f - 60.0f },
|
||||||
|
WHITE, 25.0f, 120.0f
|
||||||
|
);
|
||||||
|
|
||||||
|
CpuPaddle cpu(
|
||||||
|
Vector2{ 10.0f, screen_height / 2.0f - 60.0f },
|
||||||
|
WHITE, 25.0f, 120.0f,
|
||||||
|
Difficulty::Normal
|
||||||
|
);
|
||||||
|
|
||||||
|
// --- Setup Menu and Game State ---
|
||||||
|
|
||||||
|
GameState currentState = GameState::MainMenu;
|
||||||
|
Menu mainMenu("PONG RELOADED", { "Start Game", "Quit" });
|
||||||
|
|
||||||
|
// --- Main Game Loop ---
|
||||||
|
|
||||||
|
while (WindowShouldClose() == false && currentState != GameState::GameOver) {
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(Dark_Green);
|
||||||
|
|
||||||
|
switch (currentState) {
|
||||||
|
case GameState::MainMenu:
|
||||||
|
{
|
||||||
|
mainMenu.Update(currentState);
|
||||||
|
mainMenu.Draw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case GameState::Playing:
|
||||||
|
{
|
||||||
|
ball.Update();
|
||||||
|
player.Update();
|
||||||
|
cpu.Update(ball.position.y);
|
||||||
|
|
||||||
|
if (CheckCollisionCircleRec(ball.position, ball.radius, Rectangle{ player.position.x, player.position.y, player.width, player.height })) {
|
||||||
|
ball.velocity.x *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CheckCollisionCircleRec(ball.position, ball.radius, Rectangle{ cpu.position.x, cpu.position.y, cpu.width, cpu.height })) {
|
||||||
|
ball.velocity.x *= -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ball.position.x + ball.radius >= screen_width) {
|
||||||
|
cpu_score++;
|
||||||
|
ResetBall(ball, screen_width, screen_height);
|
||||||
|
}
|
||||||
|
if (ball.position.x - ball.radius <= 0) {
|
||||||
|
player_score++;
|
||||||
|
ResetBall(ball, screen_width, screen_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawRectangle(screen_width / 2, 0, screen_width / 2, screen_height, Green);
|
||||||
|
DrawCircle(screen_width / 2, screen_height / 2, 150, Light_Green);
|
||||||
|
DrawLine(screen_width / 2, 0, screen_width / 2, screen_height, WHITE);
|
||||||
|
|
||||||
|
DrawText(TextFormat("%i", cpu_score), screen_width / 4 - 20, 20, 80, WHITE);
|
||||||
|
DrawText(TextFormat("%i", player_score), 3 * screen_width / 4 - 20, 20, 80, WHITE);
|
||||||
|
|
||||||
|
ball.Draw();
|
||||||
|
cpu.Draw();
|
||||||
|
player.Draw();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include "menu.h"
|
||||||
|
|
||||||
|
void Menu::Update(GameState& currentState) {
|
||||||
|
// Handle Navigation
|
||||||
|
if (IsKeyPressed(KEY_DOWN)) {
|
||||||
|
selectedIndex++;
|
||||||
|
if (selectedIndex >= options.size()) selectedIndex = 0;
|
||||||
|
}
|
||||||
|
if (IsKeyPressed(KEY_UP)) {
|
||||||
|
selectedIndex--;
|
||||||
|
if (selectedIndex < 0) selectedIndex = options.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Selection
|
||||||
|
if (IsKeyPressed(KEY_ENTER)) {
|
||||||
|
if (options[selectedIndex] == "Start Game") {
|
||||||
|
currentState = GameState::Playing;
|
||||||
|
}
|
||||||
|
else if (options[selectedIndex] == "Quit") {
|
||||||
|
currentState = GameState::GameOver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Menu::Draw() {
|
||||||
|
int screenWidth = GetScreenWidth();
|
||||||
|
int screenHeight = GetScreenHeight();
|
||||||
|
|
||||||
|
// Draw Title
|
||||||
|
DrawText(title.c_str(), screenWidth / 2 - MeasureText(title.c_str(), 60) / 2, screenHeight / 4, 60, WHITE);
|
||||||
|
|
||||||
|
// Draw Options
|
||||||
|
for (int i = 0; i < options.size(); i++) {
|
||||||
|
Color textColor = (i == selectedIndex) ? YELLOW : WHITE;
|
||||||
|
DrawText(options[i].c_str(), screenWidth / 2 - MeasureText(options[i].c_str(), 40) / 2, screenHeight / 2 + (i * 60), 40, textColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user