Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f11bbe
Adding all the Setup File.
Sourav328 Jul 18, 2025
0f12d48
Merge pull request #1 from Sourav328/Feature-1_Project-Setup
Sourav328 Jul 18, 2025
500259a
Add GameWindowManager for window handling
Sourav328 Jul 22, 2025
4facefa
Merge pull request #2 from Sourav328/Feature-2_Game-Window
Sourav328 Jul 22, 2025
d6766f7
Update game window to fullscreen and change clear color
Sourav328 Jul 22, 2025
d529794
Merge pull request #3 from Sourav328/Feature-2_Game-Window
Sourav328 Jul 22, 2025
0431b14
Add EventManager for handling window events
Sourav328 Jul 24, 2025
cc008dc
Merge pull request #4 from Sourav328/Feature-2_Game-Window
Sourav328 Jul 24, 2025
3420830
Add left mouse button click handling to EventManager
Sourav328 Jul 25, 2025
e17dfc3
Merge pull request #5 from Sourav328/Feature-3_Fetch-Player-Input
Sourav328 Jul 25, 2025
c93f393
Add GameLoop class and refactor main loop structure
Sourav328 Jul 25, 2025
cd47fc0
Merge pull request #6 from Sourav328/Feature-4_Game-Loop
Sourav328 Jul 25, 2025
72d8d11
Add basic gameplay classes for Pong
Sourav328 Jul 26, 2025
076ba18
Merge pull request #7 from Sourav328/Feature-5_Paddle-And-Ball
Sourav328 Jul 26, 2025
81aa6b4
Refactor Ball to use textured sprite
Sourav328 Jul 27, 2025
e1f5a2c
Merge pull request #8 from Sourav328/Feature-5_Paddle-And-Ball
Sourav328 Jul 27, 2025
671978b
Refactor game architecture and improve rendering
Sourav328 Jul 27, 2025
c3f479d
Update Ball.h
Sourav328 Jul 27, 2025
e285b2b
Update Ball.cpp
Sourav328 Jul 27, 2025
fb61d56
Add boundary rendering to gameplay
Sourav328 Jul 27, 2025
93c41e9
Add ball-paddle collision and ball movement logic
Sourav328 Jul 27, 2025
5b8aa52
New
Sourav328 Nov 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Header/Core/GameLoop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// GameLoop.h
#pragma once
#include "GameWindowManager.h"
#include "../../Header/Event/EventManager.h"
#include "../../Header/Gameplay/GameplayManager.h"

namespace Core
{
class GameLoop {
private:
GameWindowManager* game_window_manager;
GameEvent::EventManager* event_manager;
Gameplay::GameplayManager* gameplay_manager;

public:
void initialize();
void pollEvent();
void update();
void render();
bool isGameRunning();
};
}
24 changes: 24 additions & 0 deletions Header/Core/GameWindowManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#pragma once
#include <SFML/Graphics.hpp>

namespace Core
{
class GameWindowManager
{
private:
sf::RenderWindow game_window;
int game_window_width = 1280;
int game_window_height = 720;
std::string game_title = "PING PONG";

public:
GameWindowManager();

void initialize();
bool isGameRunning();
sf::RenderWindow* getGameWindow();
void clearGameWindow();
void displayGameWindow();
};
}
12 changes: 12 additions & 0 deletions Header/Event/EventManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <SFML/Graphics.hpp>


namespace GameEvent {
class EventManager {
public:
void pollEvents(sf::RenderWindow* game_window);
bool isKeyPressed(sf::Keyboard::Key key);
bool isLeftMouseButtonClicked();
};
}
26 changes: 26 additions & 0 deletions Header/Gameplay/Ball/Ball.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <string>

namespace Gameplay
{
class Paddle;
class Ball
{
private:
sf::CircleShape Ball_Shape;
sf::Texture Pong_Ball_Texture;
const std::string Texture_Path = "Assets/Textures/Ball.png";
float radius = 15.0f;
sf::Vector2f velocity = { 4.0f, 4.0f };
void loadTexture();


public:
Ball();
void update();
void render(sf::RenderWindow* window);
void handlePaddleCollision(Paddle* player1, Paddle* player2);

};
}
54 changes: 54 additions & 0 deletions Header/Gameplay/Boundary/Boundary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once
#include <SFML/Graphics.hpp>
namespace Gameplay

{
class Boundary
{
private:
sf::RectangleShape topBoundary;
sf::RectangleShape bottomBoundary;
sf::RectangleShape leftBoundary;
sf::RectangleShape rightBoundary;
sf::RectangleShape centerLine;

const float horizontal_boundary_width = 1280.0f;
const float horizontal_boundary_height = 20.0f;

const float top_position_x = 0.0f;
const float top_position_y = 0.0f;

const float bottom_position_x = 0.0f;
const float bottom_position_y = 700.0f;

const float vertical_boundary_width = 20.0f;
const float vertical_boundary_height = 720.0f;

const float left_position_x = 0.0f;
const float left_position_y = 0.0f;

const float right_position_x = 1260.0f;
const float right_position_y = 0.0f;

const float center_line_width = 10.0f;
const float center_line_height = 680.0f;

const float center_line_position_x = 640.0f;
const float center_line_position_y = 20.0f;

const sf::Color boundary_color = sf::Color::Blue;
const sf::Color center_line_color = sf::Color::White;

void createTopBoundary();
void createBottomBoundary();
void createLeftBoundary();
void createRightBoundary();

void createCenterLine();

public:
Boundary();
void render(sf::RenderWindow*game_window);

};
}
33 changes: 33 additions & 0 deletions Header/Gameplay/GameplayManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#pragma once
#include "../../Header/Gameplay/Paddle/Paddle.h"
#include "../../Header/Gameplay/Ball/Ball.h"
#include "../../Header/Event/EventManager.h"
#include "../../Header/Gameplay/Boundary/Boundary.h"

namespace Gameplay
{
class GameplayManager {
private:
void initialize();


float player1_position_x = 40.0f;
float player1_position_y = 300.0f;

float player2_position_x = 1210.0f;
float player2_position_y = 300.0f;

GameEvent::EventManager* event_manager;
Boundary* boundary;
public:

void update();
void render(sf::RenderWindow* game_window);
GameplayManager(GameEvent::EventManager* manager);

Ball* ball;
Paddle* player1;
Paddle* player2;
};
}
41 changes: 41 additions & 0 deletions Header/Gameplay/Paddle/Paddle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <string>

using namespace sf;
using namespace std;

namespace Gameplay
{

class Paddle
{
private:
RectangleShape paddle_sprite;

const float paddle_width = 20.f;
const float paddle_height = 100.f;

float paddleSpeed = 0.8f;
float topBoundary = 20.0f;
float bottomBoundary = 700.0f;

Texture Paddle_texture;
string texture_path = "Assets/Textures/Paddle.png";

void createPaddle(float position_x, float position_y);
void movePaddle(bool move_up_key_pressed, bool move_down_key_pressed);

public:
Paddle();
Paddle(float position_x, float position_y);
sf::RectangleShape& getPaddleSprite();
void reset(float position_x, float position_y);

void update(bool move_up, bool move_down);
void render(RenderWindow* game_window);

private:
void loadTexture();
};
}
13 changes: 13 additions & 0 deletions Header/Utility/TimeService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

#pragma once
#include <chrono>

namespace Utility
{
class TimeService
{
private:
std::chrono::steady_clock::time_point previous_time;
float delta_time;
}
}
47 changes: 25 additions & 22 deletions Main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}

window.clear();
window.draw(shape);
window.display();

#include "../../Header/Core/GameWindowManager.h"
#include "../../Header/Event/EventManager.h"
#include "../../Header/Gameplay/GameplayManager.h"

using namespace sf;

int main() {
Core::GameWindowManager gameWindowManager;
gameWindowManager.initialize();

GameEvent::EventManager eventManager;
Gameplay::GameplayManager gameplayManager(&eventManager);

while (gameWindowManager.isGameRunning()) {
eventManager.pollEvents(gameWindowManager.getGameWindow());

gameplayManager.update();

gameWindowManager.clearGameWindow();
gameplayManager.render(gameWindowManager.getGameWindow());
gameWindowManager.displayGameWindow();
}
}

return 0;
}
26 changes: 26 additions & 0 deletions Pong-SFML.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(ProjectDir)SFML\include</IncludePath>
<LibraryPath>$(ProjectDir)SFML\lib</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down Expand Up @@ -134,6 +138,28 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
<ClCompile Include="Source\Core\GameLoop.cpp" />
<ClCompile Include="Source\Core\GameWindowManager.cpp" />
<ClCompile Include="Source\Event\EventManager.cpp" />
<ClCompile Include="Source\Gameplay\Ball\Ball.cpp" />
<ClCompile Include="Source\Gameplay\Boundary\Boundary.cpp" />
<ClCompile Include="Source\Gameplay\GameplayManager.cpp" />
<ClCompile Include="Source\Gameplay\Paddle\Paddle.cpp" />
<ClCompile Include="Source\Utility\TimeService.cpp" />
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Header\Core\GameLoop.h" />
<ClInclude Include="Header\Core\GameWindowManager.h" />
<ClInclude Include="Header\Event\EventManager.h" />
<ClInclude Include="Header\Gameplay\Ball\Ball.h" />
<ClInclude Include="Header\Gameplay\Boundary\Boundary.h" />
<ClInclude Include="Header\Gameplay\GameplayManager.h" />
<ClInclude Include="Header\Gameplay\Paddle\Paddle.h" />
<ClInclude Include="Header\Utility\TimeService.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
Loading