Skip to content

Feature 4 game loop #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions Header/Core/GameLoop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "SFML/Graphics.hpp"
#include "GameWindowManager.h"
#include "../Event/EventManager.h"

using namespace sf;
using namespace Core;
using namespace Eventmanager;


namespace Core
{
class GameLoop
{
private:
GameWindowManager* game_window_manager;
EventManager* event_manager;

public:
void initialize();

bool isGameRunning();
void pollEvent();
void update();
void render();
};
}

29 changes: 29 additions & 0 deletions Header/Core/GameWindowManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <SFML/Graphics.hpp>

using namespace sf;

namespace Core
{
class GameWindowManager
{
private:
int game_window_width = 1280;
int game_window_height = 720;
std::string game_title = "SFML-Pong!";

RenderWindow* game_window;

void createGameWindow();

public:
void initialize();
RenderWindow* getGameWindow();
bool isGameRunning();
void clearWindow();
void displayWindow();
//void render();
};
}

16 changes: 16 additions & 0 deletions Header/Event/EventManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "SFML/Graphics.hpp"

using namespace sf;

namespace Eventmanager
{
class EventManager
{
public:
void pollEvents(RenderWindow* game_window); // Process all events
//bool isKeyPressed(sf::Keyboard::Key key); // Check specific key
};
}

30 changes: 14 additions & 16 deletions Main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Header/Core/GameWindowManager.h"
#include "Header/Event/EventManager.h"
#include "Header/Core/GameLoop.h"

using namespace Core;
using namespace Eventmanager;

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();
}
GameLoop* game_loop = new GameLoop();

window.clear();
window.draw(shape);
window.display();
}
game_loop->initialize();
while (game_loop->isGameRunning())
{
game_loop->pollEvent();
game_loop->update();
game_loop->render();
}
}
8 changes: 8 additions & 0 deletions Pong-SFML.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,16 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Source\Core\GameLoop.cpp" />
<ClCompile Include="Source\Event\EventManager.cpp" />
<ClCompile Include="Source\Core\GameWindowManager.cpp" />
<ClCompile Include="Main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Header\Core\GameLoop.h" />
<ClInclude Include="Header\Event\EventManager.h" />
<ClInclude Include="Header\Core\GameWindowManager.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
44 changes: 7 additions & 37 deletions Pong-SFML.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,55 +45,25 @@
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Gameplay\Boundary\Boundary.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Gameplay\Ball\Ball.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Gameplay\Paddle\Paddle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Gameplay\GameplayManager.cpp">
<ClCompile Include="Source\Core\GameWindowManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Event\EventManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Utility\TimeService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\UI\UIService.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Source\Core\GameWindowManager.cpp">
<ClCompile Include="Source\Core\GameLoop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Header\Gameplay\Ball\Ball.h">
<Filter>Header Files\Header\GamePlay\Ball</Filter>
</ClInclude>
<ClInclude Include="Header\Gameplay\Boundary\Boundary.h">
<Filter>Header Files\Header\GamePlay\Boundary</Filter>
</ClInclude>
<ClInclude Include="Header\Event\EventManager.h">
<Filter>Header Files\Header\Events</Filter>
</ClInclude>
<ClInclude Include="Header\Gameplay\GameplayManager.h">
<Filter>Header Files\Header\GamePlay</Filter>
</ClInclude>
<ClInclude Include="Header\Core\GameWindowManager.h">
<Filter>Header Files\Header\Core</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header\Gameplay\Paddle\Paddle.h">
<Filter>Header Files\Header\GamePlay\Paddle</Filter>
</ClInclude>
<ClInclude Include="Header\Utility\TimeService.h">
<Filter>Header Files\Header\Utility</Filter>
<ClInclude Include="Header\Event\EventManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Header\UI\UIService.h">
<Filter>Header Files\Header\UI</Filter>
<ClInclude Include="Header\Core\GameLoop.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
56 changes: 56 additions & 0 deletions SFML/include/SFML/Audio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila ([email protected])
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#ifndef SFML_AUDIO_HPP
#define SFML_AUDIO_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

#include <SFML/System.hpp>
#include <SFML/Audio/InputSoundFile.hpp>
#include <SFML/Audio/Listener.hpp>
#include <SFML/Audio/Music.hpp>
#include <SFML/Audio/OutputSoundFile.hpp>
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundFileFactory.hpp>
#include <SFML/Audio/SoundFileReader.hpp>
#include <SFML/Audio/SoundFileWriter.hpp>
#include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/SoundSource.hpp>
#include <SFML/Audio/SoundStream.hpp>


#endif // SFML_AUDIO_HPP

////////////////////////////////////////////////////////////
/// \defgroup audio Audio module
///
/// Sounds, streaming (musics or custom sources), recording,
/// spatialization.
///
////////////////////////////////////////////////////////////
70 changes: 70 additions & 0 deletions SFML/include/SFML/Audio/AlResource.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila ([email protected])
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#ifndef SFML_ALRESOURCE_HPP
#define SFML_ALRESOURCE_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.hpp>


namespace sf
{
////////////////////////////////////////////////////////////
/// \brief Base class for classes that require an OpenAL context
///
////////////////////////////////////////////////////////////
class SFML_AUDIO_API AlResource
{
protected:

////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
AlResource();

////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~AlResource();
};

} // namespace sf


#endif // SFML_ALRESOURCE_HPP

////////////////////////////////////////////////////////////
/// \class sf::AlResource
/// \ingroup audio
///
/// This class is for internal use only, it must be the base
/// of every class that requires a valid OpenAL context in
/// order to work.
///
////////////////////////////////////////////////////////////
48 changes: 48 additions & 0 deletions SFML/include/SFML/Audio/Export.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila ([email protected])
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#ifndef SFML_AUDIO_EXPORT_HPP
#define SFML_AUDIO_EXPORT_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>


////////////////////////////////////////////////////////////
// Define portable import / export macros
////////////////////////////////////////////////////////////
#if defined(SFML_AUDIO_EXPORTS)

#define SFML_AUDIO_API SFML_API_EXPORT

#else

#define SFML_AUDIO_API SFML_API_IMPORT

#endif


#endif // SFML_AUDIO_EXPORT_HPP
Loading