From 46d3eb914ebec96c25f0997df65c4dece32700c2 Mon Sep 17 00:00:00 2001 From: Tarun Date: Fri, 26 Jul 2024 19:48:55 +0530 Subject: [PATCH 1/8] The whole file gets corrupted thats why i have to write all programs till player ship again --- Space-Invaders/Headers/GameService.cpp | 59 +++++++++++++++++++ Space-Invaders/Headers/GameService.h | 26 ++++++++ Space-Invaders/Headers/GraphicService.cpp | 56 ++++++++++++++++++ Space-Invaders/Headers/GraphicService.h | 38 ++++++++++++ Space-Invaders/Headers/ServiceLocator.cpp | 49 +++++++++++++++ Space-Invaders/Headers/ServiceLocator.h | 29 +++++++++ Space-Invaders/Space-Invaders.vcxproj | 8 +++ Space-Invaders/Space-Invaders.vcxproj.filters | 20 +++++++ Space-Invaders/main.cpp | 19 +++++- 9 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 Space-Invaders/Headers/GameService.cpp create mode 100644 Space-Invaders/Headers/GameService.h create mode 100644 Space-Invaders/Headers/GraphicService.cpp create mode 100644 Space-Invaders/Headers/GraphicService.h create mode 100644 Space-Invaders/Headers/ServiceLocator.cpp create mode 100644 Space-Invaders/Headers/ServiceLocator.h diff --git a/Space-Invaders/Headers/GameService.cpp b/Space-Invaders/Headers/GameService.cpp new file mode 100644 index 000000000..4607039c2 --- /dev/null +++ b/Space-Invaders/Headers/GameService.cpp @@ -0,0 +1,59 @@ +#include "GameService.h" +#include"GraphicService.h" + +GameService::GameService() { + service_locator = nullptr; // Set service locator to null + game_window = nullptr; // Set game window to null +} + +// Destructor: Calls the destroy function to clean up resources. +GameService::~GameService() { + destroy(); // Clean up and release resources +} + +// Prepares the game service for use by obtaining the service locator instance and initializing services. +void GameService::ignite() { + service_locator = ServiceLocator::getInstance(); // Get ServiceLocator + initialize(); // Initialize services. +} + +//initialize service locator and other variables +void GameService::initialize() +{ + service_locator->initialize(); + initializeVariables(); +} + +void GameService::initializeVariables() +{ + game_window = service_locator->getGraphicService()->getGameWindow(); //set game window (it was null before this) +} + +void GameService::destroy() +{ + // don't need to do anything here for now. +} + +// Updates the game logic by delegating to the service locator's update method. +void GameService::update() { + + service_locator->update(); // Call update on the service locator which then updates all its managed services +} + +// Clears the window then display it. +void GameService::render() { + // Clears the game window with the background color provided by the graphic service + game_window->clear(service_locator->getGraphicService()->getWindowColor()); + service_locator->render(); // Render the current frame using the service locator + game_window->display(); // Display the rendered frame on the game window +} + +// Checks if the game is still running by querying the graphic service's window open status. +bool GameService::isRunning() { + // Returns true if the game window is open, indicating the game is still running + return service_locator->getGraphicService()->isGameWindowOpen(); +} + + + + diff --git a/Space-Invaders/Headers/GameService.h b/Space-Invaders/Headers/GameService.h new file mode 100644 index 000000000..c09fa800f --- /dev/null +++ b/Space-Invaders/Headers/GameService.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include "ServiceLocator.h" + +class GameService +{ +private: + + ServiceLocator* service_locator; + sf::RenderWindow* game_window; + + void initialize(); + void initializeVariables();// Handles game initialization. + void destroy(); // Handles cleanup tasks. + +public: + + GameService(); // Constructor for initializing the GameService object. + ~GameService(); // Destructor for cleaning up resources upon object deletion. + + void ignite(); // Initiates the game. + void update(); // Updates the game logic and game state. + void render(); // Renders each frame of the game. + bool isRunning(); // Checks if the game is currently running. +}; \ No newline at end of file diff --git a/Space-Invaders/Headers/GraphicService.cpp b/Space-Invaders/Headers/GraphicService.cpp new file mode 100644 index 000000000..1303689b7 --- /dev/null +++ b/Space-Invaders/Headers/GraphicService.cpp @@ -0,0 +1,56 @@ +#include"ServiceLocator.h" +#include"GraphicService.h" + +// Constructor: Initializes game window and video mode pointers to null. +GraphicService::GraphicService() { + game_window = nullptr; // Initializes game window pointer to null + video_mode = nullptr; // Initializes video mode pointer to null +} + +// Destructor: Cleans up resources by calling onDestroy. +GraphicService::~GraphicService() { + onDestroy(); // Calls onDestroy method to clean up resources +} + +// Initializes the graphic service by creating a new game window. +void GraphicService::initialize() { + game_window = createGameWindow(); // Assigns a new game window to the game_window pointer +} + +// Creates a new SFML RenderWindow object with specified video mode and title. +sf::RenderWindow* GraphicService::createGameWindow() { + setVideoMode(); // Sets up the video mode for the window + return new sf::RenderWindow(*video_mode, game_window_title); // Creates and returns a new RenderWindow object +} + +// Sets up the video mode for the game window using specified dimensions and system's color depth. +void GraphicService::setVideoMode() { + video_mode = new sf::VideoMode(game_window_width, game_window_height, sf::VideoMode::getDesktopMode().bitsPerPixel); // Allocates and sets the video mode +} + +// Cleans up allocated memory for video mode and game window to avoid memory leaks. +void GraphicService::onDestroy() { + delete(video_mode); // Deletes the video mode object + delete(game_window); // Deletes the game window object +} + +// Placeholder function for game update logic. +void GraphicService::update() { } + +// Placeholder function for game rendering logic. +void GraphicService::render() { } + +// Checks if the game window is currently open. +bool GraphicService::isGameWindowOpen() { + return game_window->isOpen(); // Returns the open status of the game window +} + +// Returns a pointer to the game window object. +sf::RenderWindow* GraphicService::getGameWindow() { + return game_window; +} + +// Returns the configured window background color. +sf::Color GraphicService::getWindowColor() { + return window_color; +} diff --git a/Space-Invaders/Headers/GraphicService.h b/Space-Invaders/Headers/GraphicService.h new file mode 100644 index 000000000..3a6cac6df --- /dev/null +++ b/Space-Invaders/Headers/GraphicService.h @@ -0,0 +1,38 @@ + +#pragma once + +#include + +class GraphicService +{ +private: + + const std::string game_window_title = "Outscal Presents - Alien Invader"; + + const int game_window_width = 800; + const int game_window_height = 600; + + const sf::Color window_color = sf::Color::Blue; + + sf::VideoMode* video_mode; // ptr to video mode + sf::RenderWindow* game_window; // ptr to a RenderWindow + + void setVideoMode(); // Method for setting our video mode + void onDestroy(); // method to run when window is deleted + +public: + GraphicService(); + ~GraphicService(); //cleanup + + //method to create the game window. returns a pointer to an instance of the game window + sf::RenderWindow* createGameWindow(); + + + void initialize(); //lifecycle functions + void update(); //.. + void render(); //.. + bool isGameWindowOpen(); //check if the window is open + + sf::RenderWindow* getGameWindow(); //getter for the game window instance + sf::Color getWindowColor();//get the color +}; \ No newline at end of file diff --git a/Space-Invaders/Headers/ServiceLocator.cpp b/Space-Invaders/Headers/ServiceLocator.cpp new file mode 100644 index 000000000..fd1922572 --- /dev/null +++ b/Space-Invaders/Headers/ServiceLocator.cpp @@ -0,0 +1,49 @@ +#include "ServiceLocator.h" + + + +// Constructor: Initializes the graphic_service pointer to null and creates services. +ServiceLocator::ServiceLocator() { + graphic_service = nullptr; // Initialize graphic_service to null + createServices(); // Call createServices to instantiate services +} + +// Destructor: Cleans up resources by clearing all services. +ServiceLocator::~ServiceLocator() { + clearAllServices(); // Call clearAllServices to delete any allocated services +} + +// Creates service instances, specifically the graphic service in this case. +void ServiceLocator::createServices() { + graphic_service = new GraphicService(); // Dynamically create a GraphicService instance +} + +// Deletes allocated services to prevent memory leaks, specifically the graphic service. +void ServiceLocator::clearAllServices() { + delete(graphic_service); // Delete the graphic_service instance + graphic_service = nullptr; // Reset pointer to null to avoid dangling pointer +} + +// Returns a pointer to ServiceLocator. +ServiceLocator* ServiceLocator::getInstance() { + static ServiceLocator instance; // we will discuss what 'static' means at a later time. + return &instance; // Return address of the instance +} + +// Calls initialize on the graphic service, readying it for use. +void ServiceLocator::initialize() { + graphic_service->initialize(); // Initialize graphic service +} + +// Updates the state of the graphic service. +void ServiceLocator::update() { + graphic_service->update(); // Update graphic service +} + +// Renders using the graphic service. +void ServiceLocator::render() { + graphic_service->render(); // Render graphic service +} + +// Returns a pointer to the currently set graphic service. +GraphicService* ServiceLocator::getGraphicService() { return graphic_service; } \ No newline at end of file diff --git a/Space-Invaders/Headers/ServiceLocator.h b/Space-Invaders/Headers/ServiceLocator.h new file mode 100644 index 000000000..84028c811 --- /dev/null +++ b/Space-Invaders/Headers/ServiceLocator.h @@ -0,0 +1,29 @@ +#pragma once +#include "GraphicService.h" + +class ServiceLocator +{ +private: + // Private Attributes: + GraphicService* graphic_service; + + // Private Constructor and Destructor: + ServiceLocator(); + // Constructor for initializing the ServiceLocator. + ~ServiceLocator(); // Destructor for cleaning up resources upon object deletion. + + // Private Methods: + void createServices(); // Creates instances of all services. + void clearAllServices(); // Deletes and deallocates memory for all services. + +public: + // Public Methods: + static ServiceLocator* getInstance(); // Provides a method to access the unique ServiceLocator instance (object). + void initialize(); // Initializes the ServiceLocator. + void update(); // Updates all services. + void render(); // Renders using the services. + + // Methods to Get Specific Services: + GraphicService* getGraphicService(); + +}; diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index 6f7fa388d..fa705159d 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -132,8 +132,16 @@ + + + + + + + + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index ce0c35ccf..c1a3d6972 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -18,5 +18,25 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Space-Invaders/main.cpp b/Space-Invaders/main.cpp index 7d5f90dff..1a2cf9819 100644 --- a/Space-Invaders/main.cpp +++ b/Space-Invaders/main.cpp @@ -1,5 +1,20 @@ - +#include "Headers/GameService.h" int main() { + + GameService* game_service = new GameService(); + + game_service->ignite(); + + while (game_service->isRunning()) + { + game_service->update(); + game_service->render(); + + + + + } return 0; -} \ No newline at end of file +} + From ef66188d0746f79e04d8e20d57328872c815dd6b Mon Sep 17 00:00:00 2001 From: Tarun Date: Sun, 28 Jul 2024 15:12:44 +0530 Subject: [PATCH 2/8] IMPLEMENTED POLLING EVENT --- Space-Invaders/Headers/EventService.cpp | 0 Space-Invaders/Headers/EventService.h | 5 +++++ Space-Invaders/Space-Invaders.vcxproj | 1 + Space-Invaders/Space-Invaders.vcxproj.filters | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 Space-Invaders/Headers/EventService.cpp create mode 100644 Space-Invaders/Headers/EventService.h diff --git a/Space-Invaders/Headers/EventService.cpp b/Space-Invaders/Headers/EventService.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Space-Invaders/Headers/EventService.h b/Space-Invaders/Headers/EventService.h new file mode 100644 index 000000000..09dfcb4c7 --- /dev/null +++ b/Space-Invaders/Headers/EventService.h @@ -0,0 +1,5 @@ +#pragma once +#include +#include + +class E \ No newline at end of file diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index fa705159d..0ee183c2a 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -138,6 +138,7 @@ + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index c1a3d6972..5f6eba855 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -38,5 +38,8 @@ Header Files + + Header Files + \ No newline at end of file From 5673590201775fa44acc60f8fd80cc34cfa611d2 Mon Sep 17 00:00:00 2001 From: Tarun Date: Sun, 28 Jul 2024 16:04:40 +0530 Subject: [PATCH 3/8] added the player spirite and also added the movement --- Space-Invaders/Headers/EventService.cpp | 49 ++++++++++++++ Space-Invaders/Headers/EventService.h | 31 ++++++++- Space-Invaders/Headers/GameService.cpp | 2 + Space-Invaders/Headers/GraphicService.cpp | 12 +++- Space-Invaders/Headers/GraphicService.h | 1 + Space-Invaders/Headers/PlayerService.cpp | 66 +++++++++++++++++++ Space-Invaders/Headers/PlayerService.h | 38 +++++++++++ Space-Invaders/Headers/ServiceLocator.cpp | 31 +++++++-- Space-Invaders/Headers/ServiceLocator.h | 6 ++ Space-Invaders/Space-Invaders.vcxproj | 3 + Space-Invaders/Space-Invaders.vcxproj.filters | 9 +++ 11 files changed, 239 insertions(+), 9 deletions(-) create mode 100644 Space-Invaders/Headers/PlayerService.cpp create mode 100644 Space-Invaders/Headers/PlayerService.h diff --git a/Space-Invaders/Headers/EventService.cpp b/Space-Invaders/Headers/EventService.cpp index e69de29bb..a5c4965e3 100644 --- a/Space-Invaders/Headers/EventService.cpp +++ b/Space-Invaders/Headers/EventService.cpp @@ -0,0 +1,49 @@ +#include"ServiceLocator.h" +#include"GraphicService.h" +#include"EventService.h" + +EventService::EventService() { game_window = nullptr; } + +EventService::~EventService() = default; //calls the default destructor + +void EventService::initialize() +{ + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); +} + +void EventService::update() +{ + //for later +} + +void EventService::processEvents() +{ + if (isGameWindowOpen()) { + while (game_window->pollEvent(game_event)) { + // Check for window closure + if (gameWindowWasClosed() || hasQuitGame()) + { + game_window->close(); + } + } + } +} + +bool EventService::hasQuitGame() { return (isKeyboardEvent() && pressedEscapeKey()); } // only true if the ESC key is pressed and a keyboard event has been registered + + + + +//checks for if a keyboard key has been pressed +bool EventService::isKeyboardEvent() { return game_event.type == sf::Event::KeyPressed; } + +//control click on the SFML functions to see what they do internally +bool EventService::pressedEscapeKey() { return game_event.key.code == sf::Keyboard::Escape; } + +bool EventService::isGameWindowOpen() { return game_window != nullptr; } + +bool EventService::gameWindowWasClosed() { return game_event.type == sf::Event::Closed; } + +bool EventService::pressedLeftKey() { return game_event.key.code == sf::Keyboard::Left; } +bool EventService::pressedRightKey() { return game_event.key.code == sf::Keyboard::Right; } + diff --git a/Space-Invaders/Headers/EventService.h b/Space-Invaders/Headers/EventService.h index 09dfcb4c7..467eff7ca 100644 --- a/Space-Invaders/Headers/EventService.h +++ b/Space-Invaders/Headers/EventService.h @@ -1,5 +1,30 @@ #pragma once -#include -#include +#include +#include -class E \ No newline at end of file +class EventService +{ +private: + sf::Event game_event; //event var + sf::RenderWindow* game_window; //ptr to our game window + + bool isGameWindowOpen(); + bool gameWindowWasClosed(); //for the condition we already had - the title bar cross. + bool hasQuitGame(); //for our new 'ESC' condition + + + + +public: + EventService(); + ~EventService(); + + void initialize(); + void update(); + void processEvents(); // while window is open we will check for events + bool pressedEscapeKey(); + bool isKeyboardEvent(); + bool pressedLeftKey(); + bool pressedRightKey(); + +}; \ No newline at end of file diff --git a/Space-Invaders/Headers/GameService.cpp b/Space-Invaders/Headers/GameService.cpp index 4607039c2..960d7acb4 100644 --- a/Space-Invaders/Headers/GameService.cpp +++ b/Space-Invaders/Headers/GameService.cpp @@ -37,6 +37,8 @@ void GameService::destroy() // Updates the game logic by delegating to the service locator's update method. void GameService::update() { + service_locator->getEventService()->processEvents(); + service_locator->update(); // Call update on the service locator which then updates all its managed services } diff --git a/Space-Invaders/Headers/GraphicService.cpp b/Space-Invaders/Headers/GraphicService.cpp index 1303689b7..f6987679e 100644 --- a/Space-Invaders/Headers/GraphicService.cpp +++ b/Space-Invaders/Headers/GraphicService.cpp @@ -1,10 +1,12 @@ #include"ServiceLocator.h" #include"GraphicService.h" + // Constructor: Initializes game window and video mode pointers to null. GraphicService::GraphicService() { game_window = nullptr; // Initializes game window pointer to null video_mode = nullptr; // Initializes video mode pointer to null + } // Destructor: Cleans up resources by calling onDestroy. @@ -35,10 +37,16 @@ void GraphicService::onDestroy() { } // Placeholder function for game update logic. -void GraphicService::update() { } +void GraphicService::update() { + + +} + // Placeholder function for game rendering logic. -void GraphicService::render() { } +void GraphicService::render() { + + } // Checks if the game window is currently open. bool GraphicService::isGameWindowOpen() { diff --git a/Space-Invaders/Headers/GraphicService.h b/Space-Invaders/Headers/GraphicService.h index 3a6cac6df..68ca09cef 100644 --- a/Space-Invaders/Headers/GraphicService.h +++ b/Space-Invaders/Headers/GraphicService.h @@ -6,6 +6,7 @@ class GraphicService { private: + const std::string game_window_title = "Outscal Presents - Alien Invader"; diff --git a/Space-Invaders/Headers/PlayerService.cpp b/Space-Invaders/Headers/PlayerService.cpp new file mode 100644 index 000000000..49be2d11a --- /dev/null +++ b/Space-Invaders/Headers/PlayerService.cpp @@ -0,0 +1,66 @@ +#include "PlayerService.h" +#include"ServiceLocator.h" + + +void PlayerService::initializePlayerSprite() +{ + if (player_texture.loadFromFile(player_texture_path)) { + player_sprite.setTexture(player_texture); + } +} + +void PlayerService::processPlayerInput() +{ + + EventService* checkkey = ServiceLocator::getInstance()->getEventService(); + if (checkkey->isKeyboardEvent()) { + if (checkkey->pressedLeftKey()) { + move(-1.0 * getMoveSpeed()); + } + + if (checkkey->pressedRightKey()) { + move(1.0 * getMoveSpeed()); + } + } +} + +PlayerService::PlayerService() +{ + game_window = nullptr; +} + +PlayerService::~PlayerService() +{ +} + +void PlayerService::initialize() +{ + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + initializePlayerSprite(); +} + +void PlayerService::update() +{ + processPlayerInput(); + player_sprite.setPosition(getPlayerPosition()); +} + +void PlayerService::render() +{ + game_window->draw(player_sprite); +} + +void PlayerService::move(float offsetX) +{ + position.x += offsetX; +} + +int PlayerService::getMoveSpeed() +{ + return movement_speed; +} + +sf::Vector2f PlayerService::getPlayerPosition() +{ + return position; +} diff --git a/Space-Invaders/Headers/PlayerService.h b/Space-Invaders/Headers/PlayerService.h new file mode 100644 index 000000000..a9440127c --- /dev/null +++ b/Space-Invaders/Headers/PlayerService.h @@ -0,0 +1,38 @@ +#pragma once +#include +class PlayerService +{ + +private: + + + + int health = 3; + sf::Vector2f position = sf::Vector2f(200.0f, 100.0f); + int movement_speed = 5; + int player_score = 0; + + const sf::String player_texture_path = "assets/textures/player_ship.png"; + + sf::Texture player_texture; + sf::Sprite player_sprite; + + sf::RenderWindow* game_window; //as always + + void initializePlayerSprite(); + void processPlayerInput(); + +public: + + PlayerService(); + ~PlayerService(); + + void initialize(); + void update(); + void render(); + + void move(float offsetX); + int getMoveSpeed(); + sf::Vector2f getPlayerPosition(); + +}; diff --git a/Space-Invaders/Headers/ServiceLocator.cpp b/Space-Invaders/Headers/ServiceLocator.cpp index fd1922572..0a81bc1aa 100644 --- a/Space-Invaders/Headers/ServiceLocator.cpp +++ b/Space-Invaders/Headers/ServiceLocator.cpp @@ -1,10 +1,12 @@ #include "ServiceLocator.h" - +#include"EventService.h" // Constructor: Initializes the graphic_service pointer to null and creates services. ServiceLocator::ServiceLocator() { - graphic_service = nullptr; // Initialize graphic_service to null + graphic_service = nullptr;// Initialize graphic_service to null + event_service = nullptr; + player_service = nullptr; createServices(); // Call createServices to instantiate services } @@ -16,12 +18,17 @@ ServiceLocator::~ServiceLocator() { // Creates service instances, specifically the graphic service in this case. void ServiceLocator::createServices() { graphic_service = new GraphicService(); // Dynamically create a GraphicService instance + event_service = new EventService(); + player_service = new PlayerService(); + } // Deletes allocated services to prevent memory leaks, specifically the graphic service. void ServiceLocator::clearAllServices() { delete(graphic_service); // Delete the graphic_service instance - graphic_service = nullptr; // Reset pointer to null to avoid dangling pointer + delete(event_service); + delete(player_service); + } // Returns a pointer to ServiceLocator. @@ -33,17 +40,33 @@ ServiceLocator* ServiceLocator::getInstance() { // Calls initialize on the graphic service, readying it for use. void ServiceLocator::initialize() { graphic_service->initialize(); // Initialize graphic service + event_service->initialize(); + player_service->initialize(); } // Updates the state of the graphic service. void ServiceLocator::update() { graphic_service->update(); // Update graphic service + event_service->update(); + player_service->update(); } // Renders using the graphic service. void ServiceLocator::render() { graphic_service->render(); // Render graphic service + player_service->render(); } // Returns a pointer to the currently set graphic service. -GraphicService* ServiceLocator::getGraphicService() { return graphic_service; } \ No newline at end of file +GraphicService* ServiceLocator::getGraphicService() { return graphic_service; } + +EventService* ServiceLocator::getEventService() { + return event_service; +} + +PlayerService* ServiceLocator::getplayerservice() { + return player_service; +} + + + diff --git a/Space-Invaders/Headers/ServiceLocator.h b/Space-Invaders/Headers/ServiceLocator.h index 84028c811..c8a41b91e 100644 --- a/Space-Invaders/Headers/ServiceLocator.h +++ b/Space-Invaders/Headers/ServiceLocator.h @@ -1,11 +1,15 @@ #pragma once #include "GraphicService.h" +#include"EventService.h" +#include"PlayerService.h" class ServiceLocator { private: // Private Attributes: GraphicService* graphic_service; + EventService* event_service; + PlayerService* player_service; // Private Constructor and Destructor: ServiceLocator(); @@ -25,5 +29,7 @@ class ServiceLocator // Methods to Get Specific Services: GraphicService* getGraphicService(); + EventService* getEventService(); + PlayerService* getplayerservice(); }; diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index 0ee183c2a..efb75e465 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -132,8 +132,10 @@ + + @@ -141,6 +143,7 @@ + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index 5f6eba855..73c3a15d7 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -27,6 +27,12 @@ Source Files + + Source Files + + + Source Files + @@ -41,5 +47,8 @@ Header Files + + Header Files + \ No newline at end of file From cd4e9cd77a6191b9f0e2cd1ee701371a64afac12 Mon Sep 17 00:00:00 2001 From: Tarun Date: Sun, 28 Jul 2024 18:12:06 +0530 Subject: [PATCH 4/8] in this commit we are adding the time dependency in the sip for the better and movement of the ship --- Space-Invaders/Headers/ServiceLocator.cpp | 14 ++++++- Space-Invaders/Headers/ServiceLocator.h | 4 +- Space-Invaders/Headers/TimeService .cpp | 42 +++++++++++++++++++ Space-Invaders/Headers/TimeService .h | 23 ++++++++++ Space-Invaders/Space-Invaders.vcxproj | 2 + Space-Invaders/Space-Invaders.vcxproj.filters | 6 +++ 6 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 Space-Invaders/Headers/TimeService .cpp create mode 100644 Space-Invaders/Headers/TimeService .h diff --git a/Space-Invaders/Headers/ServiceLocator.cpp b/Space-Invaders/Headers/ServiceLocator.cpp index 0a81bc1aa..21ba91f85 100644 --- a/Space-Invaders/Headers/ServiceLocator.cpp +++ b/Space-Invaders/Headers/ServiceLocator.cpp @@ -7,6 +7,7 @@ ServiceLocator::ServiceLocator() { graphic_service = nullptr;// Initialize graphic_service to null event_service = nullptr; player_service = nullptr; + time_Service = nullptr; createServices(); // Call createServices to instantiate services } @@ -20,7 +21,7 @@ void ServiceLocator::createServices() { graphic_service = new GraphicService(); // Dynamically create a GraphicService instance event_service = new EventService(); player_service = new PlayerService(); - + time_Service = new TimeService(); } // Deletes allocated services to prevent memory leaks, specifically the graphic service. @@ -28,6 +29,7 @@ void ServiceLocator::clearAllServices() { delete(graphic_service); // Delete the graphic_service instance delete(event_service); delete(player_service); + delete(time_Service); } @@ -42,6 +44,7 @@ void ServiceLocator::initialize() { graphic_service->initialize(); // Initialize graphic service event_service->initialize(); player_service->initialize(); + time_Service->intialize(); } // Updates the state of the graphic service. @@ -49,8 +52,10 @@ void ServiceLocator::update() { graphic_service->update(); // Update graphic service event_service->update(); player_service->update(); + time_Service->update(); } + // Renders using the graphic service. void ServiceLocator::render() { graphic_service->render(); // Render graphic service @@ -68,5 +73,10 @@ PlayerService* ServiceLocator::getplayerservice() { return player_service; } - +TimeService* ServiceLocator::gettimeservice() +{ + return time_Service; +} + + diff --git a/Space-Invaders/Headers/ServiceLocator.h b/Space-Invaders/Headers/ServiceLocator.h index c8a41b91e..86a93eed9 100644 --- a/Space-Invaders/Headers/ServiceLocator.h +++ b/Space-Invaders/Headers/ServiceLocator.h @@ -2,6 +2,7 @@ #include "GraphicService.h" #include"EventService.h" #include"PlayerService.h" +#include"TimeService .h" class ServiceLocator { @@ -10,6 +11,7 @@ class ServiceLocator GraphicService* graphic_service; EventService* event_service; PlayerService* player_service; + TimeService* time_Service; // Private Constructor and Destructor: ServiceLocator(); @@ -31,5 +33,5 @@ class ServiceLocator GraphicService* getGraphicService(); EventService* getEventService(); PlayerService* getplayerservice(); - + TimeService* gettimeservice(); }; diff --git a/Space-Invaders/Headers/TimeService .cpp b/Space-Invaders/Headers/TimeService .cpp new file mode 100644 index 000000000..0c719b841 --- /dev/null +++ b/Space-Invaders/Headers/TimeService .cpp @@ -0,0 +1,42 @@ +#include "TimeService .h" + +float TimeService::calculate_delta_time() +{ + // Calculate time difference in microseconds between the current and previous frame. + int delta = std::chrono::duration_cast( + std::chrono::steady_clock::now() - previous_time).count(); + + // The cast is used to convert delta time from microseconds into seconds. + // We will learn aboit how this works in detail later. + return static_cast(delta) / static_cast(1000000); +} + +void TimeService::updatePreviousTime() +{ + + previous_time = std::chrono::steady_clock::now(); +} + +void TimeService::updateDeltaTime() +{ + delta_time = calculate_delta_time(); + updatePreviousTime(); + +} + +void TimeService::update() +{ + updateDeltaTime(); +} + +void TimeService::intialize() +{ + previous_time = std::chrono::steady_clock::now(); + delta_time = 0; +} + +float TimeService::getdeltatime() +{ + return delta_time; +} + diff --git a/Space-Invaders/Headers/TimeService .h b/Space-Invaders/Headers/TimeService .h new file mode 100644 index 000000000..2a4183d17 --- /dev/null +++ b/Space-Invaders/Headers/TimeService .h @@ -0,0 +1,23 @@ +#pragma once +//Capture the current time at the beginning of a frame +//Capture the current time again at the beginning of the next frame +//Calculate the delta time by subtracting the previous frame's start time from the current frame's start time. +//Update the current frame's start time to become the previous frame's start time so as to prepare for the next frame. +#include + +class TimeService { +private: + std::chrono::time_point previous_time; + + float delta_time;//to store the value of delta time + float calculate_delta_time();//calculate time by subtracting the previous time from the current time + void updatePreviousTime(); // finally update the current time to be previous time + void updateDeltaTime(); +public: + void update(); + void intialize(); + float getdeltatime(); + + + +}; diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index efb75e465..f85d9a4d0 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -137,6 +137,7 @@ + @@ -145,6 +146,7 @@ + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index 73c3a15d7..219bacc87 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -33,6 +33,9 @@ Source Files + + Source Files + @@ -50,5 +53,8 @@ Header Files + + Header Files + \ No newline at end of file From b02ba2867db71a6320aba115f41d9efc20953ff5 Mon Sep 17 00:00:00 2001 From: Tarun Date: Sun, 28 Jul 2024 19:50:32 +0530 Subject: [PATCH 5/8] in this commit we are implementing the mvc model for the player service --- Space-Invaders/Headers/GraphicService.cpp | 3 ++ Space-Invaders/Headers/GraphicService.h | 2 + Space-Invaders/Headers/PlayerService.cpp | 17 +++++-- Space-Invaders/Headers/PlayerService.h | 6 ++- .../Headers/player/PlayerController.h | 1 + Space-Invaders/Headers/player/PlayerModel.cpp | 50 ++++++++++++++++++ Space-Invaders/Headers/player/PlayerModel.h | 51 +++++++++++++++++++ Space-Invaders/Headers/player/PlayerView.h | 1 + Space-Invaders/Space-Invaders.vcxproj | 4 ++ Space-Invaders/Space-Invaders.vcxproj.filters | 12 +++++ 10 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 Space-Invaders/Headers/player/PlayerController.h create mode 100644 Space-Invaders/Headers/player/PlayerModel.cpp create mode 100644 Space-Invaders/Headers/player/PlayerModel.h create mode 100644 Space-Invaders/Headers/player/PlayerView.h diff --git a/Space-Invaders/Headers/GraphicService.cpp b/Space-Invaders/Headers/GraphicService.cpp index f6987679e..e4a35584d 100644 --- a/Space-Invaders/Headers/GraphicService.cpp +++ b/Space-Invaders/Headers/GraphicService.cpp @@ -17,8 +17,11 @@ GraphicService::~GraphicService() { // Initializes the graphic service by creating a new game window. void GraphicService::initialize() { game_window = createGameWindow(); // Assigns a new game window to the game_window pointer + + game_window->setFramerateLimit(framerate); } + // Creates a new SFML RenderWindow object with specified video mode and title. sf::RenderWindow* GraphicService::createGameWindow() { setVideoMode(); // Sets up the video mode for the window diff --git a/Space-Invaders/Headers/GraphicService.h b/Space-Invaders/Headers/GraphicService.h index 68ca09cef..570c7f584 100644 --- a/Space-Invaders/Headers/GraphicService.h +++ b/Space-Invaders/Headers/GraphicService.h @@ -15,6 +15,8 @@ class GraphicService const sf::Color window_color = sf::Color::Blue; + const int framerate = 60; + sf::VideoMode* video_mode; // ptr to video mode sf::RenderWindow* game_window; // ptr to a RenderWindow diff --git a/Space-Invaders/Headers/PlayerService.cpp b/Space-Invaders/Headers/PlayerService.cpp index 49be2d11a..e8932f90d 100644 --- a/Space-Invaders/Headers/PlayerService.cpp +++ b/Space-Invaders/Headers/PlayerService.cpp @@ -15,11 +15,11 @@ void PlayerService::processPlayerInput() EventService* checkkey = ServiceLocator::getInstance()->getEventService(); if (checkkey->isKeyboardEvent()) { if (checkkey->pressedLeftKey()) { - move(-1.0 * getMoveSpeed()); + moveLef(); } if (checkkey->pressedRightKey()) { - move(1.0 * getMoveSpeed()); + moveRight(); } } } @@ -50,11 +50,20 @@ void PlayerService::render() game_window->draw(player_sprite); } -void PlayerService::move(float offsetX) +void PlayerService::moveLef() { - position.x += offsetX; + + position.x -= ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); } +void PlayerService::moveRight() +{ + + position.x += ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); +} + + + int PlayerService::getMoveSpeed() { return movement_speed; diff --git a/Space-Invaders/Headers/PlayerService.h b/Space-Invaders/Headers/PlayerService.h index a9440127c..997402155 100644 --- a/Space-Invaders/Headers/PlayerService.h +++ b/Space-Invaders/Headers/PlayerService.h @@ -1,5 +1,6 @@ #pragma once #include +#include"TimeService .h" class PlayerService { @@ -9,7 +10,7 @@ class PlayerService int health = 3; sf::Vector2f position = sf::Vector2f(200.0f, 100.0f); - int movement_speed = 5; + float movement_speed = 5.0f; int player_score = 0; const sf::String player_texture_path = "assets/textures/player_ship.png"; @@ -31,7 +32,8 @@ class PlayerService void update(); void render(); - void move(float offsetX); + void moveLef(); + void moveRight(); int getMoveSpeed(); sf::Vector2f getPlayerPosition(); diff --git a/Space-Invaders/Headers/player/PlayerController.h b/Space-Invaders/Headers/player/PlayerController.h new file mode 100644 index 000000000..6f70f09be --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerController.h @@ -0,0 +1 @@ +#pragma once diff --git a/Space-Invaders/Headers/player/PlayerModel.cpp b/Space-Invaders/Headers/player/PlayerModel.cpp new file mode 100644 index 000000000..bc266d1d0 --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerModel.cpp @@ -0,0 +1,50 @@ +#include"PlayerModel.h" + +PlayerModel::PlayerModel() { } + +PlayerModel::~PlayerModel() { } + +void PlayerModel::initialize() { reset(); } + +void PlayerModel::reset() +{ + player_position = initial_player_position; + player_score = 0; +} + +sf::Vector2f PlayerModel::getPlayerPosition() +{ + return player_position; +} + +void PlayerModel::setPlayerPosition(sf::Vector2f position) +{ + player_position = position; +} + +PlayerState PlayerModel::getplayerstate() +{ + return player_state; +} + +void PlayerModel::setplayerstate(PlayerState state) + +{ + player_state = state; + +} + + + + + + + + + + + + + + + diff --git a/Space-Invaders/Headers/player/PlayerModel.h b/Space-Invaders/Headers/player/PlayerModel.h new file mode 100644 index 000000000..5d0ba8e79 --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerModel.h @@ -0,0 +1,51 @@ +#pragma once +#include + + +enum class PlayerState //Our Enum +{ + ALIVE, + DEAD, + // we will add more states later +}; + + +class PlayerModel +{ +private: + + const sf::Vector2f initial_player_position = sf::Vector2f(500.f, 500.f); //new var + sf::Vector2f player_position; //new var + PlayerState player_state; + + int player_score = 0; + + +public: + const sf::Vector2f left_most_position = sf::Vector2f(50.f, 0.f); + const sf::Vector2f right_most_position = sf::Vector2f(700.f, 0.f); + + const float player_movement_speed = 200.0f; + + PlayerModel(); + ~PlayerModel(); + + void initialize(); + + void reset(); //new method + + + + + //getters and setters + sf::Vector2f getPlayerPosition(); + void setPlayerPosition(sf::Vector2f position); + + PlayerState getplayerstate(); + + + void setplayerstate(PlayerState state); + + + +}; \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerView.h b/Space-Invaders/Headers/player/PlayerView.h new file mode 100644 index 000000000..6f70f09be --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerView.h @@ -0,0 +1 @@ +#pragma once diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index f85d9a4d0..87d1530fc 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -136,6 +136,7 @@ + @@ -145,6 +146,9 @@ + + + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index 219bacc87..a5307cb2f 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -36,6 +36,9 @@ Source Files + + Source Files + @@ -56,5 +59,14 @@ Header Files + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file From b1564b096b29492f74d2ddd3e771b29d05589be0 Mon Sep 17 00:00:00 2001 From: Tarun Date: Mon, 29 Jul 2024 18:29:50 +0530 Subject: [PATCH 6/8] IN THSI COMMIT WE HAVE IMPLEMENTED THE MVC MODEL AND WE ENCOUNTER SOME OF THE ERRORS WHICH WE ARE GOING TO FIX IN NEXT MODULE --- Space-Invaders/Headers/PlayerService.cpp | 4 ++ Space-Invaders/Headers/PlayerService.h | 3 + .../Headers/player/PlayerController.cpp | 67 +++++++++++++++++++ .../Headers/player/PlayerController.h | 30 ++++++++- Space-Invaders/Headers/player/PlayerView.cpp | 42 ++++++++++++ Space-Invaders/Headers/player/PlayerView.h | 31 +++++++++ Space-Invaders/Space-Invaders.vcxproj | 2 + Space-Invaders/Space-Invaders.vcxproj.filters | 6 ++ 8 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 Space-Invaders/Headers/player/PlayerController.cpp create mode 100644 Space-Invaders/Headers/player/PlayerView.cpp diff --git a/Space-Invaders/Headers/PlayerService.cpp b/Space-Invaders/Headers/PlayerService.cpp index e8932f90d..d06939a78 100644 --- a/Space-Invaders/Headers/PlayerService.cpp +++ b/Space-Invaders/Headers/PlayerService.cpp @@ -27,6 +27,7 @@ void PlayerService::processPlayerInput() PlayerService::PlayerService() { game_window = nullptr; + pcontroller = nullptr; } PlayerService::~PlayerService() @@ -36,17 +37,20 @@ PlayerService::~PlayerService() void PlayerService::initialize() { game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + pcontroller->intialize(); initializePlayerSprite(); } void PlayerService::update() { processPlayerInput(); + pcontroller->update(); player_sprite.setPosition(getPlayerPosition()); } void PlayerService::render() { + pcontroller->render(); game_window->draw(player_sprite); } diff --git a/Space-Invaders/Headers/PlayerService.h b/Space-Invaders/Headers/PlayerService.h index 997402155..a1cdb65d1 100644 --- a/Space-Invaders/Headers/PlayerService.h +++ b/Space-Invaders/Headers/PlayerService.h @@ -1,6 +1,7 @@ #pragma once #include #include"TimeService .h" +#include"../Headers/player/PlayerController.h" class PlayerService { @@ -23,6 +24,8 @@ class PlayerService void initializePlayerSprite(); void processPlayerInput(); + PlayerController* pcontroller; + public: PlayerService(); diff --git a/Space-Invaders/Headers/player/PlayerController.cpp b/Space-Invaders/Headers/player/PlayerController.cpp new file mode 100644 index 000000000..4be7a2a9c --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerController.cpp @@ -0,0 +1,67 @@ +#include "PlayerController.h" +#include"../EventService.h" +#include"../ServiceLocator.h" +#include +void PlayerController::processinput() +{ + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + processmoveright(); + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + processmoveleft(); + } +} + +void PlayerController::processmoveleft() +{ + + sf::Vector2f current_position = model->getPlayerPosition(); + current_position.x -= model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + current_position.x = std::max(current_position.x, model->left_most_position.x); + model->setPlayerPosition(current_position); +} + + +void PlayerController::processmoveright() +{ + sf::Vector2f current_position = model->getPlayerPosition(); + current_position.x += model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + current_position.x = std::min(current_position.x, model->right_most_position.x); + model->setPlayerPosition(current_position); + +} + +PlayerController::PlayerController() +{ + + model = new PlayerModel(); + view = new PlayerView(); +} + +PlayerController::~PlayerController() +{ + delete (view); + delete (model); +} + +void PlayerController::intialize() +{ + model->initialize(); + view->initialize(); +} + +void PlayerController::update() +{ + view->update(); +} + +void PlayerController::render() +{ + view->render(); +} + +sf::Vector2f PlayerController::getPlayerPosition() +{ + return model->getPlayerPosition(); +} diff --git a/Space-Invaders/Headers/player/PlayerController.h b/Space-Invaders/Headers/player/PlayerController.h index 6f70f09be..924e5b845 100644 --- a/Space-Invaders/Headers/player/PlayerController.h +++ b/Space-Invaders/Headers/player/PlayerController.h @@ -1 +1,29 @@ -#pragma once +#pragma one +#include +#include"PlayerModel.h" +#include"PlayerView.h" + +class PlayerController { + +private: + + PlayerModel* model; + PlayerView* view; + + + void processinput(); + void processmoveleft(); + void processmoveright(); +public: + PlayerController(); + ~PlayerController(); + void intialize(); + void update(); + void render(); + + + + + sf::Vector2f getPlayerPosition(); + +}; diff --git a/Space-Invaders/Headers/player/PlayerView.cpp b/Space-Invaders/Headers/player/PlayerView.cpp new file mode 100644 index 000000000..ceb9af683 --- /dev/null +++ b/Space-Invaders/Headers/player/PlayerView.cpp @@ -0,0 +1,42 @@ +#include"PlayerView.h" +#include"../ServiceLocator.h" +PlayerView::PlayerView() { } + +PlayerView::~PlayerView() { } + +void PlayerView::initialize(PlayerController* controller) +{ + + player_controller = controller; + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + initializePlayerSprite(); +} + +void PlayerView::initializePlayerSprite() +{ + if (player_texture.loadFromFile(player_texture_path)) + { + player_sprite.setTexture(player_texture); + scalePlayerSprite(); + } +} + +void PlayerView::scalePlayerSprite() +{ + // setScale is an inbuilt method of the sprite class that takes two floats to scale the sprite. it scales the sprite to our desired height + player_sprite.setScale( + //Here we find the factor to scale our sprites with. Ignore the static_cast for now, we will discuss it later. + static_cast(player_sprite_width) / player_sprite.getTexture()->getSize().x, + static_cast(player_sprite_height) / player_sprite.getTexture()->getSize().y + ); +} + +void PlayerView::update() +{ + //empty for now +} + +void PlayerView::render() +{ + game_window->draw(player_sprite); +} \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerView.h b/Space-Invaders/Headers/player/PlayerView.h index 6f70f09be..23dd3dad1 100644 --- a/Space-Invaders/Headers/player/PlayerView.h +++ b/Space-Invaders/Headers/player/PlayerView.h @@ -1 +1,32 @@ #pragma once +#include +#include"PlayerController.h" + +class PlayerView +{ +private: + + const sf::String player_texture_path = "assets/textures/player_ship.png"; + const float player_sprite_width = 60.f; + const float player_sprite_height = 60.f; + + sf::RenderWindow* game_window; + + sf::Texture player_texture; + sf::Sprite player_sprite; + + void initializePlayerSprite(); + void scalePlayerSprite(); + + PlayerController* player_controller; + + + +public: + PlayerView(); + ~PlayerView(); + + void initialize(PlayerController* player_controller); + void update(); + void render(); +}; \ No newline at end of file diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index 87d1530fc..9c1f9c7a3 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -136,7 +136,9 @@ + + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index a5307cb2f..e01c392bf 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -39,6 +39,12 @@ Source Files + + Source Files + + + Source Files + From 571656de35b456208007afd36f41fa0f53cbe772 Mon Sep 17 00:00:00 2001 From: Tarun Date: Mon, 29 Jul 2024 19:52:30 +0530 Subject: [PATCH 7/8] did nothing much just add forward declrations --- Space-Invaders/Headers/{ => EVENT}/EventService.h | 0 Space-Invaders/Headers/{ => Global}/ServiceLocator.h | 0 Space-Invaders/Headers/{ => Graphic}/GraphicService.h | 0 Space-Invaders/Headers/{ => TIME}/TimeService .h | 0 Space-Invaders/Headers/{ => main}/GameService.h | 0 Space-Invaders/Headers/{ => player}/PlayerService.h | 0 Space-Invaders/{Headers => source}/EventService.cpp | 0 Space-Invaders/{Headers => source}/GameService.cpp | 0 Space-Invaders/{Headers => source}/GraphicService.cpp | 0 Space-Invaders/{Headers/player => source}/PlayerController.cpp | 0 Space-Invaders/{Headers/player => source}/PlayerModel.cpp | 0 Space-Invaders/{Headers => source}/PlayerService.cpp | 0 Space-Invaders/{Headers/player => source}/PlayerView.cpp | 0 Space-Invaders/{Headers => source}/ServiceLocator.cpp | 0 Space-Invaders/{Headers => source}/TimeService .cpp | 0 15 files changed, 0 insertions(+), 0 deletions(-) rename Space-Invaders/Headers/{ => EVENT}/EventService.h (100%) rename Space-Invaders/Headers/{ => Global}/ServiceLocator.h (100%) rename Space-Invaders/Headers/{ => Graphic}/GraphicService.h (100%) rename Space-Invaders/Headers/{ => TIME}/TimeService .h (100%) rename Space-Invaders/Headers/{ => main}/GameService.h (100%) rename Space-Invaders/Headers/{ => player}/PlayerService.h (100%) rename Space-Invaders/{Headers => source}/EventService.cpp (100%) rename Space-Invaders/{Headers => source}/GameService.cpp (100%) rename Space-Invaders/{Headers => source}/GraphicService.cpp (100%) rename Space-Invaders/{Headers/player => source}/PlayerController.cpp (100%) rename Space-Invaders/{Headers/player => source}/PlayerModel.cpp (100%) rename Space-Invaders/{Headers => source}/PlayerService.cpp (100%) rename Space-Invaders/{Headers/player => source}/PlayerView.cpp (100%) rename Space-Invaders/{Headers => source}/ServiceLocator.cpp (100%) rename Space-Invaders/{Headers => source}/TimeService .cpp (100%) diff --git a/Space-Invaders/Headers/EventService.h b/Space-Invaders/Headers/EVENT/EventService.h similarity index 100% rename from Space-Invaders/Headers/EventService.h rename to Space-Invaders/Headers/EVENT/EventService.h diff --git a/Space-Invaders/Headers/ServiceLocator.h b/Space-Invaders/Headers/Global/ServiceLocator.h similarity index 100% rename from Space-Invaders/Headers/ServiceLocator.h rename to Space-Invaders/Headers/Global/ServiceLocator.h diff --git a/Space-Invaders/Headers/GraphicService.h b/Space-Invaders/Headers/Graphic/GraphicService.h similarity index 100% rename from Space-Invaders/Headers/GraphicService.h rename to Space-Invaders/Headers/Graphic/GraphicService.h diff --git a/Space-Invaders/Headers/TimeService .h b/Space-Invaders/Headers/TIME/TimeService .h similarity index 100% rename from Space-Invaders/Headers/TimeService .h rename to Space-Invaders/Headers/TIME/TimeService .h diff --git a/Space-Invaders/Headers/GameService.h b/Space-Invaders/Headers/main/GameService.h similarity index 100% rename from Space-Invaders/Headers/GameService.h rename to Space-Invaders/Headers/main/GameService.h diff --git a/Space-Invaders/Headers/PlayerService.h b/Space-Invaders/Headers/player/PlayerService.h similarity index 100% rename from Space-Invaders/Headers/PlayerService.h rename to Space-Invaders/Headers/player/PlayerService.h diff --git a/Space-Invaders/Headers/EventService.cpp b/Space-Invaders/source/EventService.cpp similarity index 100% rename from Space-Invaders/Headers/EventService.cpp rename to Space-Invaders/source/EventService.cpp diff --git a/Space-Invaders/Headers/GameService.cpp b/Space-Invaders/source/GameService.cpp similarity index 100% rename from Space-Invaders/Headers/GameService.cpp rename to Space-Invaders/source/GameService.cpp diff --git a/Space-Invaders/Headers/GraphicService.cpp b/Space-Invaders/source/GraphicService.cpp similarity index 100% rename from Space-Invaders/Headers/GraphicService.cpp rename to Space-Invaders/source/GraphicService.cpp diff --git a/Space-Invaders/Headers/player/PlayerController.cpp b/Space-Invaders/source/PlayerController.cpp similarity index 100% rename from Space-Invaders/Headers/player/PlayerController.cpp rename to Space-Invaders/source/PlayerController.cpp diff --git a/Space-Invaders/Headers/player/PlayerModel.cpp b/Space-Invaders/source/PlayerModel.cpp similarity index 100% rename from Space-Invaders/Headers/player/PlayerModel.cpp rename to Space-Invaders/source/PlayerModel.cpp diff --git a/Space-Invaders/Headers/PlayerService.cpp b/Space-Invaders/source/PlayerService.cpp similarity index 100% rename from Space-Invaders/Headers/PlayerService.cpp rename to Space-Invaders/source/PlayerService.cpp diff --git a/Space-Invaders/Headers/player/PlayerView.cpp b/Space-Invaders/source/PlayerView.cpp similarity index 100% rename from Space-Invaders/Headers/player/PlayerView.cpp rename to Space-Invaders/source/PlayerView.cpp diff --git a/Space-Invaders/Headers/ServiceLocator.cpp b/Space-Invaders/source/ServiceLocator.cpp similarity index 100% rename from Space-Invaders/Headers/ServiceLocator.cpp rename to Space-Invaders/source/ServiceLocator.cpp diff --git a/Space-Invaders/Headers/TimeService .cpp b/Space-Invaders/source/TimeService .cpp similarity index 100% rename from Space-Invaders/Headers/TimeService .cpp rename to Space-Invaders/source/TimeService .cpp From c033f7310ced58b1bf2bf1267033ac2ec8385701 Mon Sep 17 00:00:00 2001 From: Tarun Date: Sat, 3 Aug 2024 10:40:56 +0530 Subject: [PATCH 8/8] here i have put the namespace in the code and l also debug the code for the error after the namespace --- Space-Invaders/Headers/EVENT/EventService.h | 41 ++--- .../Headers/Global/ServiceLocator.h | 80 +++++---- .../Headers/Graphic/GraphicService.h | 53 +++--- Space-Invaders/Headers/main/GameService.h | 40 +++-- .../Headers/player/PlayerController.h | 44 +++-- Space-Invaders/Headers/player/PlayerModel.h | 69 ++++---- Space-Invaders/Headers/player/PlayerService.h | 57 +++--- Space-Invaders/Headers/player/PlayerView.h | 45 ++--- Space-Invaders/Space-Invaders.vcxproj | 32 ++-- Space-Invaders/Space-Invaders.vcxproj.filters | 36 ++-- Space-Invaders/main.cpp | 3 +- Space-Invaders/source/EventService.cpp | 84 +++++---- Space-Invaders/source/GameService.cpp | 104 ++++++----- Space-Invaders/source/GraphicService.cpp | 100 +++++------ Space-Invaders/source/PlayerController.cpp | 110 ++++++------ Space-Invaders/source/PlayerModel.cpp | 54 +++--- Space-Invaders/source/PlayerService.cpp | 155 +++++++++-------- Space-Invaders/source/PlayerView.cpp | 77 +++++---- Space-Invaders/source/ServiceLocator.cpp | 162 +++++++++--------- Space-Invaders/source/TimeService .cpp | 2 +- 20 files changed, 723 insertions(+), 625 deletions(-) diff --git a/Space-Invaders/Headers/EVENT/EventService.h b/Space-Invaders/Headers/EVENT/EventService.h index 467eff7ca..93f993fd5 100644 --- a/Space-Invaders/Headers/EVENT/EventService.h +++ b/Space-Invaders/Headers/EVENT/EventService.h @@ -1,30 +1,31 @@ #pragma once #include #include +namespace event { + class EventService + { + private: + sf::Event game_event; //event var + sf::RenderWindow* game_window; //ptr to our game window -class EventService -{ -private: - sf::Event game_event; //event var - sf::RenderWindow* game_window; //ptr to our game window + bool isGameWindowOpen(); + bool gameWindowWasClosed(); //for the condition we already had - the title bar cross. + bool hasQuitGame(); //for our new 'ESC' condition - bool isGameWindowOpen(); - bool gameWindowWasClosed(); //for the condition we already had - the title bar cross. - bool hasQuitGame(); //for our new 'ESC' condition - -public: - EventService(); - ~EventService(); + public: + EventService(); + ~EventService(); - void initialize(); - void update(); - void processEvents(); // while window is open we will check for events - bool pressedEscapeKey(); - bool isKeyboardEvent(); - bool pressedLeftKey(); - bool pressedRightKey(); + void initialize(); + void update(); + void processEvents(); // while window is open we will check for events + bool pressedEscapeKey(); + bool isKeyboardEvent(); + bool pressedLeftKey(); + bool pressedRightKey(); -}; \ No newline at end of file + }; +} \ No newline at end of file diff --git a/Space-Invaders/Headers/Global/ServiceLocator.h b/Space-Invaders/Headers/Global/ServiceLocator.h index 86a93eed9..bf7b53343 100644 --- a/Space-Invaders/Headers/Global/ServiceLocator.h +++ b/Space-Invaders/Headers/Global/ServiceLocator.h @@ -1,37 +1,45 @@ #pragma once -#include "GraphicService.h" -#include"EventService.h" -#include"PlayerService.h" -#include"TimeService .h" - -class ServiceLocator -{ -private: - // Private Attributes: - GraphicService* graphic_service; - EventService* event_service; - PlayerService* player_service; - TimeService* time_Service; - - // Private Constructor and Destructor: - ServiceLocator(); - // Constructor for initializing the ServiceLocator. - ~ServiceLocator(); // Destructor for cleaning up resources upon object deletion. - - // Private Methods: - void createServices(); // Creates instances of all services. - void clearAllServices(); // Deletes and deallocates memory for all services. - -public: - // Public Methods: - static ServiceLocator* getInstance(); // Provides a method to access the unique ServiceLocator instance (object). - void initialize(); // Initializes the ServiceLocator. - void update(); // Updates all services. - void render(); // Renders using the services. - - // Methods to Get Specific Services: - GraphicService* getGraphicService(); - EventService* getEventService(); - PlayerService* getplayerservice(); - TimeService* gettimeservice(); -}; + +#include"../Graphic/GraphicService.h" +#include"../EVENT/EventService.h" +#include"../player/PlayerService.h" +#include"../TIME/TimeService .h" + + +namespace Global { + using namespace player; + using namespace Graphic; + using namespace event; + + class ServiceLocator + { + private: + // Private Attributes: + GraphicService* graphic_service; + EventService* event_service; + PlayerService* player_service; + TimeService* time_Service; + + // Private Constructor and Destructor: + ServiceLocator(); + // Constructor for initializing the ServiceLocator. + ~ServiceLocator(); // Destructor for cleaning up resources upon object deletion. + + // Private Methods: + void createServices(); // Creates instances of all services. + void clearAllServices(); // Deletes and deallocates memory for all services. + + public: + // Public Methods: + static ServiceLocator* getInstance(); // Provides a method to access the unique ServiceLocator instance (object). + void initialize(); // Initializes the ServiceLocator. + void update(); // Updates all services. + void render(); // Renders using the services. + + // Methods to Get Specific Services: + GraphicService* getGraphicService(); + EventService* getEventService(); + PlayerService* getplayerservice(); + TimeService* gettimeservice(); + }; +} \ No newline at end of file diff --git a/Space-Invaders/Headers/Graphic/GraphicService.h b/Space-Invaders/Headers/Graphic/GraphicService.h index 570c7f584..e013140cf 100644 --- a/Space-Invaders/Headers/Graphic/GraphicService.h +++ b/Space-Invaders/Headers/Graphic/GraphicService.h @@ -2,40 +2,43 @@ #pragma once #include +namespace Graphic { -class GraphicService -{ -private: - + class GraphicService + { + private: - const std::string game_window_title = "Outscal Presents - Alien Invader"; - const int game_window_width = 800; - const int game_window_height = 600; + const std::string game_window_title = "Outscal Presents - Alien Invader"; - const sf::Color window_color = sf::Color::Blue; + const int game_window_width = 800; + const int game_window_height = 600; - const int framerate = 60; + const sf::Color window_color = sf::Color::Blue; - sf::VideoMode* video_mode; // ptr to video mode - sf::RenderWindow* game_window; // ptr to a RenderWindow + const int framerate = 60; - void setVideoMode(); // Method for setting our video mode - void onDestroy(); // method to run when window is deleted + sf::VideoMode* video_mode; // ptr to video mode + sf::RenderWindow* game_window; // ptr to a RenderWindow -public: - GraphicService(); - ~GraphicService(); //cleanup + void setVideoMode(); // Method for setting our video mode + void onDestroy(); // method to run when window is deleted - //method to create the game window. returns a pointer to an instance of the game window - sf::RenderWindow* createGameWindow(); + public: + GraphicService(); + ~GraphicService(); //cleanup + //method to create the game window. returns a pointer to an instance of the game window + sf::RenderWindow* createGameWindow(); - void initialize(); //lifecycle functions - void update(); //.. - void render(); //.. - bool isGameWindowOpen(); //check if the window is open - sf::RenderWindow* getGameWindow(); //getter for the game window instance - sf::Color getWindowColor();//get the color -}; \ No newline at end of file + void initialize(); //lifecycle functions + void update(); //.. + void render(); //.. + bool isGameWindowOpen(); //check if the window is open + + sf::RenderWindow* getGameWindow(); //getter for the game window instance + sf::Color getWindowColor();//get the color + }; + +} \ No newline at end of file diff --git a/Space-Invaders/Headers/main/GameService.h b/Space-Invaders/Headers/main/GameService.h index c09fa800f..96ffa1177 100644 --- a/Space-Invaders/Headers/main/GameService.h +++ b/Space-Invaders/Headers/main/GameService.h @@ -1,26 +1,32 @@ #pragma once #include -#include "ServiceLocator.h" +#include"../Global/ServiceLocator.h" -class GameService -{ -private: +namespace Main { - ServiceLocator* service_locator; - sf::RenderWindow* game_window; + using namespace Global; - void initialize(); - void initializeVariables();// Handles game initialization. - void destroy(); // Handles cleanup tasks. + class GameService + { + private: -public: - GameService(); // Constructor for initializing the GameService object. - ~GameService(); // Destructor for cleaning up resources upon object deletion. + ServiceLocator* service_locator; + sf::RenderWindow* game_window; - void ignite(); // Initiates the game. - void update(); // Updates the game logic and game state. - void render(); // Renders each frame of the game. - bool isRunning(); // Checks if the game is currently running. -}; \ No newline at end of file + void initialize(); + void initializeVariables();// Handles game initialization. + void destroy(); // Handles cleanup tasks. + + public: + + GameService(); // Constructor for initializing the GameService object. + ~GameService(); // Destructor for cleaning up resources upon object deletion. + + void ignite(); // Initiates the game. + void update(); // Updates the game logic and game state. + void render(); // Renders each frame of the game. + bool isRunning(); // Checks if the game is currently running. + }; +} \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerController.h b/Space-Invaders/Headers/player/PlayerController.h index 924e5b845..9406c7c23 100644 --- a/Space-Invaders/Headers/player/PlayerController.h +++ b/Space-Invaders/Headers/player/PlayerController.h @@ -1,29 +1,35 @@ -#pragma one +#pragma once #include -#include"PlayerModel.h" -#include"PlayerView.h" +namespace player { -class PlayerController { + enum class PlayerState; + class PlayerView; + class PlayerModel; -private: + class PlayerController { - PlayerModel* model; - PlayerView* view; + private: - void processinput(); - void processmoveleft(); - void processmoveright(); -public: - PlayerController(); - ~PlayerController(); - void intialize(); - void update(); - void render(); - + void processinput(); + void processmoveleft(); + void processmoveright(); + public: + PlayerModel* model; + PlayerView* view; + PlayerController(); + ~PlayerController(); + void intialize(); + void update(); + void render(); - sf::Vector2f getPlayerPosition(); -}; + + + sf::Vector2f getPlayerPosition(); + + }; + +} \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerModel.h b/Space-Invaders/Headers/player/PlayerModel.h index 5d0ba8e79..90d116e84 100644 --- a/Space-Invaders/Headers/player/PlayerModel.h +++ b/Space-Invaders/Headers/player/PlayerModel.h @@ -1,51 +1,58 @@ #pragma once #include +class PlayerView; +class PlayerModel; +namespace player { -enum class PlayerState //Our Enum -{ - ALIVE, - DEAD, - // we will add more states later -}; + enum class PlayerState //Our Enum + { + ALIVE, + DEAD, + // we will add more states later + }; -class PlayerModel -{ -private: - const sf::Vector2f initial_player_position = sf::Vector2f(500.f, 500.f); //new var - sf::Vector2f player_position; //new var - PlayerState player_state; - - int player_score = 0; + class PlayerModel + { + private: -public: - const sf::Vector2f left_most_position = sf::Vector2f(50.f, 0.f); - const sf::Vector2f right_most_position = sf::Vector2f(700.f, 0.f); + const sf::Vector2f initial_player_position = sf::Vector2f(500.f, 500.f); //new var + sf::Vector2f player_position; //new var + PlayerState player_state; + PlayerModel* model; + PlayerView* view; + int player_score = 0; - const float player_movement_speed = 200.0f; - PlayerModel(); - ~PlayerModel(); + public: + const sf::Vector2f left_most_position = sf::Vector2f(50.f, 0.f); + const sf::Vector2f right_most_position = sf::Vector2f(700.f, 0.f); - void initialize(); + const float player_movement_speed = 200.0f; - void reset(); //new method + PlayerModel(); + ~PlayerModel(); + void initialize(); - + void reset(); //new method - //getters and setters - sf::Vector2f getPlayerPosition(); - void setPlayerPosition(sf::Vector2f position); - PlayerState getplayerstate(); - - void setplayerstate(PlayerState state); - + //getters and setters + sf::Vector2f getPlayerPosition(); + void setPlayerPosition(sf::Vector2f position); -}; \ No newline at end of file + PlayerState getplayerstate(); + + + void setplayerstate(PlayerState state); + + + + }; +} \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerService.h b/Space-Invaders/Headers/player/PlayerService.h index a1cdb65d1..25d03fecf 100644 --- a/Space-Invaders/Headers/player/PlayerService.h +++ b/Space-Invaders/Headers/player/PlayerService.h @@ -1,43 +1,48 @@ #pragma once -#include -#include"TimeService .h" -#include"../Headers/player/PlayerController.h" -class PlayerService -{ +#include" +#include"../TIME/TimeService .h" +#include"../player/PlayerController.h" -private: - +namespace player { + class PlayerService + { - int health = 3; - sf::Vector2f position = sf::Vector2f(200.0f, 100.0f); - float movement_speed = 5.0f; - int player_score = 0; + private: - const sf::String player_texture_path = "assets/textures/player_ship.png"; - sf::Texture player_texture; - sf::Sprite player_sprite; - sf::RenderWindow* game_window; //as always + int health = 3; + sf::Vector2f position = sf::Vector2f(200.0f, 100.0f); + float movement_speed = 5.0f; + int player_score = 0; - void initializePlayerSprite(); - void processPlayerInput(); + const sf::String player_texture_path = "assets/textures/player_ship.png"; - PlayerController* pcontroller; + sf::Texture player_texture; + sf::Sprite player_sprite; -public: + sf::RenderWindow* game_window; //as always + + void initializePlayerSprite(); + void processPlayerInput(); + + PlayerController* player_controller; + + + public: PlayerService(); - ~PlayerService(); + ~PlayerService(); - void initialize(); - void update(); - void render(); + void initialize(); + void update(); + void render(); void moveLef(); void moveRight(); - int getMoveSpeed(); - sf::Vector2f getPlayerPosition(); + int getMoveSpeed(); + sf::Vector2f getPlayerPosition(); -}; + }; +} \ No newline at end of file diff --git a/Space-Invaders/Headers/player/PlayerView.h b/Space-Invaders/Headers/player/PlayerView.h index 23dd3dad1..cba5f3eba 100644 --- a/Space-Invaders/Headers/player/PlayerView.h +++ b/Space-Invaders/Headers/player/PlayerView.h @@ -1,32 +1,33 @@ #pragma once #include -#include"PlayerController.h" +#include"../player/PlayerController.h" -class PlayerView -{ -private: + class PlayerController; + namespace player { + class PlayerView + { + private: - const sf::String player_texture_path = "assets/textures/player_ship.png"; - const float player_sprite_width = 60.f; - const float player_sprite_height = 60.f; + const sf::String player_texture_path = "assets/textures/player_ship.png"; + const float player_sprite_width = 60.f; + const float player_sprite_height = 60.f; - sf::RenderWindow* game_window; + sf::RenderWindow* game_window; - sf::Texture player_texture; - sf::Sprite player_sprite; + sf::Texture player_texture; + sf::Sprite player_sprite; - void initializePlayerSprite(); - void scalePlayerSprite(); + void initializePlayerSprite(); + void scalePlayerSprite(); - PlayerController* player_controller; + PlayerController* player_controller; + public: + PlayerView(); + ~PlayerView(); - -public: - PlayerView(); - ~PlayerView(); - - void initialize(PlayerController* player_controller); - void update(); - void render(); -}; \ No newline at end of file + void initialize(PlayerController* player_controller); + void update(); + void render(); + }; + } \ No newline at end of file diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index 9c1f9c7a3..69138384f 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -1,4 +1,4 @@ - + @@ -132,27 +132,27 @@ - - - - - - - - - + + + + + + + + + - - - - + + + + - - + + diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index e01c392bf..31167764f 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -18,60 +18,60 @@ Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files diff --git a/Space-Invaders/main.cpp b/Space-Invaders/main.cpp index 1a2cf9819..a7a0b06f7 100644 --- a/Space-Invaders/main.cpp +++ b/Space-Invaders/main.cpp @@ -1,4 +1,5 @@ -#include "Headers/GameService.h" +#include"../Space-Invaders/Headers/main/GameService.h" +using namespace Main; int main() { diff --git a/Space-Invaders/source/EventService.cpp b/Space-Invaders/source/EventService.cpp index a5c4965e3..729ac8cd0 100644 --- a/Space-Invaders/source/EventService.cpp +++ b/Space-Invaders/source/EventService.cpp @@ -1,49 +1,61 @@ -#include"ServiceLocator.h" -#include"GraphicService.h" -#include"EventService.h" - -EventService::EventService() { game_window = nullptr; } - -EventService::~EventService() = default; //calls the default destructor - -void EventService::initialize() -{ - game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); -} - -void EventService::update() -{ - //for later -} - -void EventService::processEvents() -{ - if (isGameWindowOpen()) { - while (game_window->pollEvent(game_event)) { - // Check for window closure - if (gameWindowWasClosed() || hasQuitGame()) - { - game_window->close(); +//#include"ServiceLocator.h" +//#include"GraphicService.h" +//#include"EventService.h" + +#include"../Headers/main/GameService.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/EVENT/EventService.h" + + +namespace event { + + using namespace Global; + using namespace Graphic; + using namespace event; + + EventService::EventService() { game_window = nullptr; } + + EventService::~EventService() = default; //calls the default destructor + + void EventService::initialize() + { + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + } + + void EventService::update() + { + //for later + } + + void EventService::processEvents() + { + if (isGameWindowOpen()) { + while (game_window->pollEvent(game_event)) { + // Check for window closure + if (gameWindowWasClosed() || hasQuitGame()) + { + game_window->close(); + } } } } -} -bool EventService::hasQuitGame() { return (isKeyboardEvent() && pressedEscapeKey()); } // only true if the ESC key is pressed and a keyboard event has been registered + bool EventService::hasQuitGame() { return (isKeyboardEvent() && pressedEscapeKey()); } // only true if the ESC key is pressed and a keyboard event has been registered -//checks for if a keyboard key has been pressed -bool EventService::isKeyboardEvent() { return game_event.type == sf::Event::KeyPressed; } + //checks for if a keyboard key has been pressed + bool EventService::isKeyboardEvent() { return game_event.type == sf::Event::KeyPressed; } -//control click on the SFML functions to see what they do internally -bool EventService::pressedEscapeKey() { return game_event.key.code == sf::Keyboard::Escape; } + //control click on the SFML functions to see what they do internally + bool EventService::pressedEscapeKey() { return game_event.key.code == sf::Keyboard::Escape; } -bool EventService::isGameWindowOpen() { return game_window != nullptr; } + bool EventService::isGameWindowOpen() { return game_window != nullptr; } -bool EventService::gameWindowWasClosed() { return game_event.type == sf::Event::Closed; } + bool EventService::gameWindowWasClosed() { return game_event.type == sf::Event::Closed; } -bool EventService::pressedLeftKey() { return game_event.key.code == sf::Keyboard::Left; } -bool EventService::pressedRightKey() { return game_event.key.code == sf::Keyboard::Right; } + bool EventService::pressedLeftKey() { return game_event.key.code == sf::Keyboard::Left; } + bool EventService::pressedRightKey() { return game_event.key.code == sf::Keyboard::Right; } +} \ No newline at end of file diff --git a/Space-Invaders/source/GameService.cpp b/Space-Invaders/source/GameService.cpp index 960d7acb4..398a7bb0b 100644 --- a/Space-Invaders/source/GameService.cpp +++ b/Space-Invaders/source/GameService.cpp @@ -1,61 +1,73 @@ -#include "GameService.h" -#include"GraphicService.h" +//#include "GameService.h" +//#include"GraphicService.h" +#include"../Headers/Graphic/GraphicService.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/main/GameService.h" -GameService::GameService() { - service_locator = nullptr; // Set service locator to null - game_window = nullptr; // Set game window to null -} -// Destructor: Calls the destroy function to clean up resources. -GameService::~GameService() { - destroy(); // Clean up and release resources -} -// Prepares the game service for use by obtaining the service locator instance and initializing services. -void GameService::ignite() { - service_locator = ServiceLocator::getInstance(); // Get ServiceLocator - initialize(); // Initialize services. -} +namespace Main { + using namespace Global; + using namespace event; + using namespace Graphic; + GameService::GameService() { -//initialize service locator and other variables -void GameService::initialize() -{ - service_locator->initialize(); - initializeVariables(); -} -void GameService::initializeVariables() -{ - game_window = service_locator->getGraphicService()->getGameWindow(); //set game window (it was null before this) -} -void GameService::destroy() -{ - // don't need to do anything here for now. -} + service_locator = nullptr; // Set service locator to null + game_window = nullptr; // Set game window to null + } -// Updates the game logic by delegating to the service locator's update method. -void GameService::update() { + // Destructor: Calls the destroy function to clean up resources. + GameService::~GameService() { + destroy(); // Clean up and release resources + } - service_locator->getEventService()->processEvents(); + // Prepares the game service for use by obtaining the service locator instance and initializing services. + void GameService::ignite() { + service_locator = ServiceLocator::getInstance(); // Get ServiceLocator + initialize(); // Initialize services. + } - service_locator->update(); // Call update on the service locator which then updates all its managed services -} + //initialize service locator and other variables + void GameService::initialize() + { + service_locator->initialize(); + initializeVariables(); + } -// Clears the window then display it. -void GameService::render() { - // Clears the game window with the background color provided by the graphic service - game_window->clear(service_locator->getGraphicService()->getWindowColor()); - service_locator->render(); // Render the current frame using the service locator - game_window->display(); // Display the rendered frame on the game window -} + void GameService::initializeVariables() + { + game_window = service_locator->getGraphicService()->getGameWindow(); //set game window (it was null before this) + } -// Checks if the game is still running by querying the graphic service's window open status. -bool GameService::isRunning() { - // Returns true if the game window is open, indicating the game is still running - return service_locator->getGraphicService()->isGameWindowOpen(); -} + void GameService::destroy() + { + // don't need to do anything here for now. + } + + // Updates the game logic by delegating to the service locator's update method. + void GameService::update() { + + service_locator->getEventService()->processEvents(); + service_locator->update(); // Call update on the service locator which then updates all its managed services + } + // Clears the window then display it. + void GameService::render() { + // Clears the game window with the background color provided by the graphic service + game_window->clear(service_locator->getGraphicService()->getWindowColor()); + service_locator->render(); // Render the current frame using the service locator + game_window->display(); // Display the rendered frame on the game window + } + + // Checks if the game is still running by querying the graphic service's window open status. + bool GameService::isRunning() { + // Returns true if the game window is open, indicating the game is still running + return service_locator->getGraphicService()->isGameWindowOpen(); + } + +} diff --git a/Space-Invaders/source/GraphicService.cpp b/Space-Invaders/source/GraphicService.cpp index e4a35584d..5b690f231 100644 --- a/Space-Invaders/source/GraphicService.cpp +++ b/Space-Invaders/source/GraphicService.cpp @@ -1,67 +1,71 @@ -#include"ServiceLocator.h" -#include"GraphicService.h" +//#include"ServiceLocator.h" +//#include"GraphicService.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/Graphic/GraphicService.h" +namespace Graphic { -// Constructor: Initializes game window and video mode pointers to null. -GraphicService::GraphicService() { - game_window = nullptr; // Initializes game window pointer to null - video_mode = nullptr; // Initializes video mode pointer to null - -} + // Constructor: Initializes game window and video mode pointers to null. + GraphicService::GraphicService() { + game_window = nullptr; // Initializes game window pointer to null + video_mode = nullptr; // Initializes video mode pointer to null -// Destructor: Cleans up resources by calling onDestroy. -GraphicService::~GraphicService() { - onDestroy(); // Calls onDestroy method to clean up resources -} + } -// Initializes the graphic service by creating a new game window. -void GraphicService::initialize() { - game_window = createGameWindow(); // Assigns a new game window to the game_window pointer + // Destructor: Cleans up resources by calling onDestroy. + GraphicService::~GraphicService() { + onDestroy(); // Calls onDestroy method to clean up resources + } - game_window->setFramerateLimit(framerate); -} + // Initializes the graphic service by creating a new game window. + void GraphicService::initialize() { + game_window = createGameWindow(); // Assigns a new game window to the game_window pointer + game_window->setFramerateLimit(framerate); + } -// Creates a new SFML RenderWindow object with specified video mode and title. -sf::RenderWindow* GraphicService::createGameWindow() { - setVideoMode(); // Sets up the video mode for the window - return new sf::RenderWindow(*video_mode, game_window_title); // Creates and returns a new RenderWindow object -} -// Sets up the video mode for the game window using specified dimensions and system's color depth. -void GraphicService::setVideoMode() { - video_mode = new sf::VideoMode(game_window_width, game_window_height, sf::VideoMode::getDesktopMode().bitsPerPixel); // Allocates and sets the video mode -} + // Creates a new SFML RenderWindow object with specified video mode and title. + sf::RenderWindow* GraphicService::createGameWindow() { + setVideoMode(); // Sets up the video mode for the window + return new sf::RenderWindow(*video_mode, game_window_title); // Creates and returns a new RenderWindow object + } -// Cleans up allocated memory for video mode and game window to avoid memory leaks. -void GraphicService::onDestroy() { - delete(video_mode); // Deletes the video mode object - delete(game_window); // Deletes the game window object -} + // Sets up the video mode for the game window using specified dimensions and system's color depth. + void GraphicService::setVideoMode() { + video_mode = new sf::VideoMode(game_window_width, game_window_height, sf::VideoMode::getDesktopMode().bitsPerPixel); // Allocates and sets the video mode + } -// Placeholder function for game update logic. -void GraphicService::update() { + // Cleans up allocated memory for video mode and game window to avoid memory leaks. + void GraphicService::onDestroy() { + delete(video_mode); // Deletes the video mode object + delete(game_window); // Deletes the game window object + } + // Placeholder function for game update logic. + void GraphicService::update() { -} + + } -// Placeholder function for game rendering logic. -void GraphicService::render() { + // Placeholder function for game rendering logic. + void GraphicService::render() { } -// Checks if the game window is currently open. -bool GraphicService::isGameWindowOpen() { - return game_window->isOpen(); // Returns the open status of the game window -} + // Checks if the game window is currently open. + bool GraphicService::isGameWindowOpen() { + return game_window->isOpen(); // Returns the open status of the game window + } -// Returns a pointer to the game window object. -sf::RenderWindow* GraphicService::getGameWindow() { - return game_window; -} + // Returns a pointer to the game window object. + sf::RenderWindow* GraphicService::getGameWindow() { + return game_window; + } -// Returns the configured window background color. -sf::Color GraphicService::getWindowColor() { - return window_color; -} + // Returns the configured window background color. + sf::Color GraphicService::getWindowColor() { + return window_color; + } +} \ No newline at end of file diff --git a/Space-Invaders/source/PlayerController.cpp b/Space-Invaders/source/PlayerController.cpp index 4be7a2a9c..05d122b62 100644 --- a/Space-Invaders/source/PlayerController.cpp +++ b/Space-Invaders/source/PlayerController.cpp @@ -1,67 +1,73 @@ -#include "PlayerController.h" -#include"../EventService.h" -#include"../ServiceLocator.h" +#include"../Headers/player/PlayerController.h" +#include"../Headers//EVENT/EventService.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/player/PlayerModel.h" +#include"../Headers//player/PlayerView.h" #include -void PlayerController::processinput() -{ +namespace player{ + using namespace Global; + void PlayerController::processinput() + { - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { - processmoveright(); + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + processmoveright(); + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + processmoveleft(); + } } - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { - processmoveleft(); - } -} -void PlayerController::processmoveleft() -{ + void PlayerController::processmoveleft() + { - sf::Vector2f current_position = model->getPlayerPosition(); - current_position.x -= model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); - current_position.x = std::max(current_position.x, model->left_most_position.x); - model->setPlayerPosition(current_position); -} + sf::Vector2f current_position = model->getPlayerPosition(); + current_position.x -= model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + current_position.x = std::max(current_position.x, model->left_most_position.x); + model->setPlayerPosition(current_position); + } -void PlayerController::processmoveright() -{ - sf::Vector2f current_position = model->getPlayerPosition(); - current_position.x += model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); - current_position.x = std::min(current_position.x, model->right_most_position.x); - model->setPlayerPosition(current_position); + void PlayerController::processmoveright() + { + sf::Vector2f current_position = model->getPlayerPosition(); + current_position.x += model->player_movement_speed * ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + current_position.x = std::min(current_position.x, model->right_most_position.x); + model->setPlayerPosition(current_position); -} + } -PlayerController::PlayerController() -{ - - model = new PlayerModel(); - view = new PlayerView(); -} + PlayerController::PlayerController() + { -PlayerController::~PlayerController() -{ - delete (view); - delete (model); -} + model = new PlayerModel(); + view = new PlayerView(); + } -void PlayerController::intialize() -{ - model->initialize(); - view->initialize(); -} + PlayerController::~PlayerController() + { + delete (view); + delete (model); + } -void PlayerController::update() -{ - view->update(); -} + void PlayerController::intialize() + { + model->initialize(); + view->initialize(this); + } -void PlayerController::render() -{ - view->render(); -} + void PlayerController::update() + { + processinput(); + view->update(); + } + + void PlayerController::render() + { + view->render(); + } -sf::Vector2f PlayerController::getPlayerPosition() -{ - return model->getPlayerPosition(); + sf::Vector2f PlayerController::getPlayerPosition() + { + return model->getPlayerPosition(); + } } diff --git a/Space-Invaders/source/PlayerModel.cpp b/Space-Invaders/source/PlayerModel.cpp index bc266d1d0..0218d5e85 100644 --- a/Space-Invaders/source/PlayerModel.cpp +++ b/Space-Invaders/source/PlayerModel.cpp @@ -1,40 +1,44 @@ -#include"PlayerModel.h" +//#include"PlayerModel.h" +#include"../Headers/player/PlayerModel.h" +namespace player { -PlayerModel::PlayerModel() { } + PlayerModel::PlayerModel() { } -PlayerModel::~PlayerModel() { } + PlayerModel::~PlayerModel() { } -void PlayerModel::initialize() { reset(); } + void PlayerModel::initialize() { reset(); } -void PlayerModel::reset() -{ - player_position = initial_player_position; - player_score = 0; -} + void PlayerModel::reset() + { -sf::Vector2f PlayerModel::getPlayerPosition() -{ - return player_position; -} + player_state = PlayerState::ALIVE; + player_position = initial_player_position; + player_score = 0; + } -void PlayerModel::setPlayerPosition(sf::Vector2f position) -{ - player_position = position; -} + sf::Vector2f PlayerModel::getPlayerPosition() + { + return player_position; + } -PlayerState PlayerModel::getplayerstate() -{ - return player_state; -} + void PlayerModel::setPlayerPosition(sf::Vector2f position) + { + player_position = position; + } -void PlayerModel::setplayerstate(PlayerState state) + PlayerState PlayerModel::getplayerstate() + { + return player_state; + } -{ - player_state = state; + void PlayerModel::setplayerstate(PlayerState state) -} + { + player_state = state; + } +} diff --git a/Space-Invaders/source/PlayerService.cpp b/Space-Invaders/source/PlayerService.cpp index d06939a78..8729355e4 100644 --- a/Space-Invaders/source/PlayerService.cpp +++ b/Space-Invaders/source/PlayerService.cpp @@ -1,79 +1,88 @@ -#include "PlayerService.h" -#include"ServiceLocator.h" +//#include "../Headers/PlayerService.h" +//#include"../Headers/ServiceLocator.h" +//#include"../Headers/player/PlayerController.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/player/PlayerService.h" +#include"../Headers/player/PlayerController.h" +#include"../Headers/EVENT/EventService.h" +namespace player { + using namespace event; + using namespace Global; + + void PlayerService::initializePlayerSprite() + { + if (player_texture.loadFromFile(player_texture_path)) { + player_sprite.setTexture(player_texture); + } + } + void PlayerService::processPlayerInput() + { -void PlayerService::initializePlayerSprite() -{ - if (player_texture.loadFromFile(player_texture_path)) { - player_sprite.setTexture(player_texture); + EventService* checkkey = ServiceLocator::getInstance()->getEventService(); + if (checkkey->isKeyboardEvent()) { + if (checkkey->pressedLeftKey()) { + moveLef(); + } + + if (checkkey->pressedRightKey()) { + moveRight(); + } + } } -} -void PlayerService::processPlayerInput() -{ + PlayerService::PlayerService() + { + game_window = nullptr; + player_controller = new PlayerController; + } - EventService* checkkey = ServiceLocator::getInstance()->getEventService(); - if (checkkey->isKeyboardEvent()) { - if (checkkey->pressedLeftKey()) { - moveLef(); - } + PlayerService::~PlayerService() + { + delete player_controller; + } - if (checkkey->pressedRightKey()) { - moveRight(); - } - } -} - -PlayerService::PlayerService() -{ - game_window = nullptr; - pcontroller = nullptr; -} - -PlayerService::~PlayerService() -{ -} - -void PlayerService::initialize() -{ - game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); - pcontroller->intialize(); - initializePlayerSprite(); -} - -void PlayerService::update() -{ - processPlayerInput(); - pcontroller->update(); - player_sprite.setPosition(getPlayerPosition()); -} - -void PlayerService::render() -{ - pcontroller->render(); - game_window->draw(player_sprite); -} - -void PlayerService::moveLef() -{ - - position.x -= ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); -} - -void PlayerService::moveRight() -{ - - position.x += ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); -} - - - -int PlayerService::getMoveSpeed() -{ - return movement_speed; -} - -sf::Vector2f PlayerService::getPlayerPosition() -{ - return position; -} + void PlayerService::initialize() + { + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + player_controller->intialize(); + initializePlayerSprite(); + } + + void PlayerService::update() + { + processPlayerInput(); + player_controller->update(); + player_sprite.setPosition(getPlayerPosition()); + } + + void PlayerService::render() + { + player_controller->render(); + game_window->draw(player_sprite); + } + + void PlayerService::moveLef() + { + + position.x -= ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + } + + void PlayerService::moveRight() + { + + position.x += ServiceLocator::getInstance()->gettimeservice()->getdeltatime(); + } + + + + int PlayerService::getMoveSpeed() + { + return movement_speed; + } + + sf::Vector2f PlayerService::getPlayerPosition() + { + return position; + } +} \ No newline at end of file diff --git a/Space-Invaders/source/PlayerView.cpp b/Space-Invaders/source/PlayerView.cpp index ceb9af683..c4068235f 100644 --- a/Space-Invaders/source/PlayerView.cpp +++ b/Space-Invaders/source/PlayerView.cpp @@ -1,42 +1,49 @@ -#include"PlayerView.h" -#include"../ServiceLocator.h" -PlayerView::PlayerView() { } +//#include"PlayerView.h" +//#include"../ServiceLocator.h" +#include"../Headers/player/PlayerView.h" +#include"../Headers/Global/ServiceLocator.h" -PlayerView::~PlayerView() { } +namespace player { + using namespace Global; -void PlayerView::initialize(PlayerController* controller) -{ + PlayerView::PlayerView() { } - player_controller = controller; - game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); - initializePlayerSprite(); -} + PlayerView::~PlayerView() { } -void PlayerView::initializePlayerSprite() -{ - if (player_texture.loadFromFile(player_texture_path)) + void PlayerView::initialize(PlayerController* controller) { - player_sprite.setTexture(player_texture); - scalePlayerSprite(); + + player_controller = controller; + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + initializePlayerSprite(); + } + + void PlayerView::initializePlayerSprite() + { + if (player_texture.loadFromFile(player_texture_path)) + { + player_sprite.setTexture(player_texture); + scalePlayerSprite(); + } + } + + void PlayerView::scalePlayerSprite() + { + // setScale is an inbuilt method of the sprite class that takes two floats to scale the sprite. it scales the sprite to our desired height + player_sprite.setScale( + //Here we find the factor to scale our sprites with. Ignore the static_cast for now, we will discuss it later. + static_cast(player_sprite_width) / player_sprite.getTexture()->getSize().x, + static_cast(player_sprite_height) / player_sprite.getTexture()->getSize().y + ); + } + + void PlayerView::update() + { + player_sprite.setPosition(player_controller->getPlayerPosition()); + } + + void PlayerView::render() + { + game_window->draw(player_sprite); } -} - -void PlayerView::scalePlayerSprite() -{ - // setScale is an inbuilt method of the sprite class that takes two floats to scale the sprite. it scales the sprite to our desired height - player_sprite.setScale( - //Here we find the factor to scale our sprites with. Ignore the static_cast for now, we will discuss it later. - static_cast(player_sprite_width) / player_sprite.getTexture()->getSize().x, - static_cast(player_sprite_height) / player_sprite.getTexture()->getSize().y - ); -} - -void PlayerView::update() -{ - //empty for now -} - -void PlayerView::render() -{ - game_window->draw(player_sprite); } \ No newline at end of file diff --git a/Space-Invaders/source/ServiceLocator.cpp b/Space-Invaders/source/ServiceLocator.cpp index 21ba91f85..a21653f1d 100644 --- a/Space-Invaders/source/ServiceLocator.cpp +++ b/Space-Invaders/source/ServiceLocator.cpp @@ -1,82 +1,88 @@ -#include "ServiceLocator.h" -#include"EventService.h" +#include"../Headers/Global/ServiceLocator.h" +#include"../Headers/EVENT/EventService.h" +#include"../Headers/player/PlayerService.h" +#include"../Headers/TIME/TimeService .h" +#include"../Headers//Graphic/GraphicService.h" + +namespace Global { + + // Constructor: Initializes the graphic_service pointer to null and creates services. + ServiceLocator::ServiceLocator() { + graphic_service = nullptr;// Initialize graphic_service to null + event_service = nullptr; + player_service = nullptr; + time_Service = nullptr; + createServices(); // Call createServices to instantiate services + } + + // Destructor: Cleans up resources by clearing all services. + ServiceLocator::~ServiceLocator() { + clearAllServices(); // Call clearAllServices to delete any allocated services + } + + // Creates service instances, specifically the graphic service in this case. + void ServiceLocator::createServices() { + graphic_service = new GraphicService(); // Dynamically create a GraphicService instance + event_service = new EventService(); + + player_service = new PlayerService(); + time_Service = new TimeService(); + } + + // Deletes allocated services to prevent memory leaks, specifically the graphic service. + void ServiceLocator::clearAllServices() { + delete(graphic_service); // Delete the graphic_service instance + delete(event_service); + delete(player_service); + delete(time_Service); + + } + + // Returns a pointer to ServiceLocator. + ServiceLocator* ServiceLocator::getInstance() { + static ServiceLocator instance; // we will discuss what 'static' means at a later time. + return &instance; // Return address of the instance + } + + // Calls initialize on the graphic service, readying it for use. + void ServiceLocator::initialize() { + graphic_service->initialize(); // Initialize graphic service + event_service->initialize(); + player_service->initialize(); + time_Service->intialize(); + } + + // Updates the state of the graphic service. + void ServiceLocator::update() { + graphic_service->update(); // Update graphic service + event_service->update(); + player_service->update(); + time_Service->update(); + } + + + // Renders using the graphic service. + void ServiceLocator::render() { + graphic_service->render(); // Render graphic service + player_service->render(); + } + + // Returns a pointer to the currently set graphic service. + GraphicService* ServiceLocator::getGraphicService() { return graphic_service; } + + EventService* ServiceLocator::getEventService() { + return event_service; + } + + PlayerService* ServiceLocator::getplayerservice() { + return player_service; + } + + TimeService* ServiceLocator::gettimeservice() + { + return time_Service; + } -// Constructor: Initializes the graphic_service pointer to null and creates services. -ServiceLocator::ServiceLocator() { - graphic_service = nullptr;// Initialize graphic_service to null - event_service = nullptr; - player_service = nullptr; - time_Service = nullptr; - createServices(); // Call createServices to instantiate services } -// Destructor: Cleans up resources by clearing all services. -ServiceLocator::~ServiceLocator() { - clearAllServices(); // Call clearAllServices to delete any allocated services -} - -// Creates service instances, specifically the graphic service in this case. -void ServiceLocator::createServices() { - graphic_service = new GraphicService(); // Dynamically create a GraphicService instance - event_service = new EventService(); - player_service = new PlayerService(); - time_Service = new TimeService(); -} - -// Deletes allocated services to prevent memory leaks, specifically the graphic service. -void ServiceLocator::clearAllServices() { - delete(graphic_service); // Delete the graphic_service instance - delete(event_service); - delete(player_service); - delete(time_Service); - -} - -// Returns a pointer to ServiceLocator. -ServiceLocator* ServiceLocator::getInstance() { - static ServiceLocator instance; // we will discuss what 'static' means at a later time. - return &instance; // Return address of the instance -} - -// Calls initialize on the graphic service, readying it for use. -void ServiceLocator::initialize() { - graphic_service->initialize(); // Initialize graphic service - event_service->initialize(); - player_service->initialize(); - time_Service->intialize(); -} - -// Updates the state of the graphic service. -void ServiceLocator::update() { - graphic_service->update(); // Update graphic service - event_service->update(); - player_service->update(); - time_Service->update(); -} - - -// Renders using the graphic service. -void ServiceLocator::render() { - graphic_service->render(); // Render graphic service - player_service->render(); -} - -// Returns a pointer to the currently set graphic service. -GraphicService* ServiceLocator::getGraphicService() { return graphic_service; } - -EventService* ServiceLocator::getEventService() { - return event_service; -} - -PlayerService* ServiceLocator::getplayerservice() { - return player_service; -} - -TimeService* ServiceLocator::gettimeservice() -{ - return time_Service; -} - - - diff --git a/Space-Invaders/source/TimeService .cpp b/Space-Invaders/source/TimeService .cpp index 0c719b841..7667ed227 100644 --- a/Space-Invaders/source/TimeService .cpp +++ b/Space-Invaders/source/TimeService .cpp @@ -1,4 +1,4 @@ -#include "TimeService .h" +#include"../Headers/TIME/TimeService .h" float TimeService::calculate_delta_time() {