diff --git a/Space-Invaders/Header/Event/EventService.h b/Space-Invaders/Header/Event/EventService.h new file mode 100644 index 000000000..ce9882ddc --- /dev/null +++ b/Space-Invaders/Header/Event/EventService.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +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(); // getting inputs for the player + bool pressedRightKey(); + +}; \ No newline at end of file diff --git a/Space-Invaders/Header/Global/ServiceLocator.h b/Space-Invaders/Header/Global/ServiceLocator.h new file mode 100644 index 000000000..332e1549f --- /dev/null +++ b/Space-Invaders/Header/Global/ServiceLocator.h @@ -0,0 +1,41 @@ +#pragma once +#include "../../Header/Graphic/GraphicService.h" +#include "../../Header/Event/EventService.h" +#include "../../Header/Player/PlayerService.h" +#include "../../Header/Time/TimeService.h" + +// ServiceLocator Class Summary: This class manages access to various services in the application. +// include relevant headers files + +class ServiceLocator +{ +private: + + // Private Attributes: + GraphicService* graphic_service; + EventService* event_service; + PlayerService* player_service; + TimeService* time_service; + + // Public Methods + ServiceLocator(); + ~ServiceLocator(); + + // Private Methods: + void createServices(); + void clearAllServices(); + +public: + + // Public Methods: + static ServiceLocator* getInstance(); + void initialize(); // Initializes the ServiceLocator. + void update(); // Updates all services. + void render(); // Renders using the services. + + // Methods to Get Specific Services: + EventService* getEventService(); // Retrieve the EventService instance + GraphicService* getGraphicService(); // Retrieve the GraphicService instance + PlayerService* getPlayerService(); // Retrieve the PlayerService instance + TimeService* getTimeService(); // Retrieve the TimeService instance +}; \ No newline at end of file diff --git a/Space-Invaders/Header/Graphic/GraphicService.h b/Space-Invaders/Header/Graphic/GraphicService.h new file mode 100644 index 000000000..83674fde3 --- /dev/null +++ b/Space-Invaders/Header/Graphic/GraphicService.h @@ -0,0 +1,38 @@ +#pragma once +#include + +class GraphicService +{ +private: + + const std::string game_window_title = "Alien Invader"; + + const int game_window_width = 800; + const int game_window_height = 600; + + const int frame_rate = 60; + + const sf::Color window_color = sf::Color::Black; + + 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/Header/Main/GameService.h b/Space-Invaders/Header/Main/GameService.h new file mode 100644 index 000000000..53f95bee5 --- /dev/null +++ b/Space-Invaders/Header/Main/GameService.h @@ -0,0 +1,25 @@ +#pragma once +#include +#include "../../Header/Global/ServiceLocator.h" + +class GameService +{ +private: + + ServiceLocator* service_locator; + sf::RenderWindow* game_window; + + + void initialize(); // Handles game initialization. + 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/Header/Player/PlayerController.h b/Space-Invaders/Header/Player/PlayerController.h new file mode 100644 index 000000000..36fda230a --- /dev/null +++ b/Space-Invaders/Header/Player/PlayerController.h @@ -0,0 +1,28 @@ +#pragma once +#include + +enum class PlayerState; +class PlayerView; +class PlayerModel; + +class PlayerController +{ +private: + + PlayerView* player_view; + PlayerModel* player_model; + + void processPlayerInput(); + void moveLeft(); + void moveRight(); + +public: + PlayerController(); + ~PlayerController(); + + void initialize(); + void update(); + void render(); + + sf::Vector2f getPlayerPosition(); +}; \ No newline at end of file diff --git a/Space-Invaders/Header/Player/PlayerModel.h b/Space-Invaders/Header/Player/PlayerModel.h new file mode 100644 index 000000000..13d61e0ea --- /dev/null +++ b/Space-Invaders/Header/Player/PlayerModel.h @@ -0,0 +1,43 @@ +#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(400.f, 400.f); + + sf::Vector2f player_position; + PlayerState player_state; //Declaration + int player_score; + +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 = 300.0f; + + PlayerModel(); + ~PlayerModel(); + + void initialize(); + void reset(); + + sf::Vector2f getPlayerPosition(); + void setPlayerPosition(sf::Vector2f position); + + int getPlayerScore(); + void setPlayerScore(int score); + + //new getter and setter + PlayerState getPlayerState(); + void setPlayerState(PlayerState state); + + +}; diff --git a/Space-Invaders/Header/Player/PlayerService.h b/Space-Invaders/Header/Player/PlayerService.h new file mode 100644 index 000000000..2f46d4894 --- /dev/null +++ b/Space-Invaders/Header/Player/PlayerService.h @@ -0,0 +1,16 @@ +#pragma once +#include "../../Header/Player/PlayerController.h" + +class PlayerService +{ +private: + PlayerController* player_controller; + +public: + PlayerService(); + ~PlayerService(); + + void initialize(); + void update(); + void render(); +}; diff --git a/Space-Invaders/Header/Player/PlayerView.h b/Space-Invaders/Header/Player/PlayerView.h new file mode 100644 index 000000000..8a1aa85e9 --- /dev/null +++ b/Space-Invaders/Header/Player/PlayerView.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include "../../Header/Player/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; // ptr to player controller + +public: + PlayerView(); + ~PlayerView(); + + void initialize(); + void update(); + void render(); + void initialize(PlayerController* controller); +}; \ No newline at end of file diff --git a/Space-Invaders/Header/Time/TimeService.h b/Space-Invaders/Header/Time/TimeService.h new file mode 100644 index 000000000..24ddec14a --- /dev/null +++ b/Space-Invaders/Header/Time/TimeService.h @@ -0,0 +1,28 @@ +#pragma once +#include + + // The TimeService class helps keep track of time in game and calculate delta time. + // Utilizes the library to calculate delta time. +class TimeService +{ +private: + + // A point in time which indicates the starting time of previous frame. + std::chrono::time_point previous_time; + + float delta_time; //to store the detla time + + void updateDeltaTime(); // method to update time + float calculateDeltaTime(); //calculate time by subtracting the previous time from the current time + void updatePreviousTime(); // finally update the current time to be previous time + +public: + + //lifecycle methods + void initialize(); + void update(); + + //getter + float getDeltaTime(); +}; + diff --git a/Space-Invaders/Source/Event/EventService.cpp b/Space-Invaders/Source/Event/EventService.cpp new file mode 100644 index 000000000..9be3a667d --- /dev/null +++ b/Space-Invaders/Source/Event/EventService.cpp @@ -0,0 +1,44 @@ +#include "../../Header/Event/EventService.h" +#include "../../Header/Main/GameService.h" +#include "../../Header/Graphic/GraphicService.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; } + +// Player inputs +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/Global/ServiceLocator.cpp b/Space-Invaders/Source/Global/ServiceLocator.cpp new file mode 100644 index 000000000..4c239d74b --- /dev/null +++ b/Space-Invaders/Source/Global/ServiceLocator.cpp @@ -0,0 +1,65 @@ +#include "../../Header/Global/ServiceLocator.h" + +ServiceLocator::ServiceLocator() +{ + graphic_service = nullptr; + event_service = nullptr; + player_service = nullptr; + time_service = nullptr; + createServices(); +} +ServiceLocator::~ServiceLocator() +{ + clearAllServices(); +} + +void ServiceLocator::createServices() +{ + graphic_service = new GraphicService(); + event_service = new EventService(); + player_service = new PlayerService(); + time_service = new TimeService(); +} + +void ServiceLocator::clearAllServices() +{ + delete(graphic_service); + delete(event_service); + delete(player_service); + delete(time_service); +} + +ServiceLocator* ServiceLocator::getInstance() +{ + static ServiceLocator instance; + return &instance; +} + +void ServiceLocator::initialize() +{ + graphic_service->initialize(); + event_service->initialize(); + player_service->initialize(); + time_service->initialize(); +} + +void ServiceLocator::update() +{ + graphic_service->update(); + event_service->update(); + player_service->update(); + time_service->update(); +} + +void ServiceLocator::render() +{ + graphic_service->render(); + player_service->render(); + //no event service because nothing to render + //no time 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/Graphic/GraphicService.cpp b/Space-Invaders/Source/Graphic/GraphicService.cpp new file mode 100644 index 000000000..4c8bb04ab --- /dev/null +++ b/Space-Invaders/Source/Graphic/GraphicService.cpp @@ -0,0 +1,56 @@ +#include "../../Header/Graphic/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 + game_window->setFramerateLimit(frame_rate); // setting a frame rate limit +} + +// 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; +} \ No newline at end of file diff --git a/Space-Invaders/Source/Main/GameService.cpp b/Space-Invaders/Source/Main/GameService.cpp new file mode 100644 index 000000000..12918afe4 --- /dev/null +++ b/Space-Invaders/Source/Main/GameService.cpp @@ -0,0 +1,59 @@ +#include "../../Header/Main/GameService.h" +#include "../../Header/Graphic/GraphicService.h" + +// Constructor: Initializes pointers to null. +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->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/Player/PlayerController.cpp b/Space-Invaders/Source/Player/PlayerController.cpp new file mode 100644 index 000000000..14b9754c9 --- /dev/null +++ b/Space-Invaders/Source/Player/PlayerController.cpp @@ -0,0 +1,74 @@ +#include "../../Header/Player/PlayerController.h" +#include "../../Header/Player/PlayerModel.h" +#include "../../Header/Player/PlayerView.h" +#include "../../Header/Event/EventService.h" +#include "../../Header/Global/ServiceLocator.h" +#include + +PlayerController::PlayerController() +{ + player_view = new PlayerView(); + player_model = new PlayerModel(); +} + +PlayerController::~PlayerController() +{ + delete (player_view); + delete (player_model); +} +//the controller is responsible for calling the lifecycle methods for the other two +void PlayerController::initialize() +{ + player_model->initialize(); + + //This will give an error right now since we haven't included the controller in the view. + player_view->initialize(this); // 'this' refers to the class we are currently inside +} + +void PlayerController::update() +{ + processPlayerInput(); + player_view->update(); // we update() the view +} + +void PlayerController::render() +{ + player_view->render(); // render the view +} + +sf::Vector2f PlayerController::getPlayerPosition() +{ + return player_model->getPlayerPosition(); +} + +void PlayerController::processPlayerInput() +{ + // we will move this to event service at a later time + if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Left))) + { + moveLeft(); + } + // we will move this to event service at a later time + if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Right))) + { + moveRight(); + } +} + +void PlayerController::moveLeft() +{ + sf::Vector2f currentPosition = player_model->getPlayerPosition(); + currentPosition.x -= player_model->player_movement_speed * ServiceLocator::getInstance()->getTimeService()->getDeltaTime(); + + currentPosition.x = std::max(currentPosition.x, player_model->left_most_position.x); + player_model->setPlayerPosition(currentPosition); +} + +void PlayerController::moveRight() +{ + sf::Vector2f currentPosition = player_model->getPlayerPosition(); + currentPosition.x += player_model->player_movement_speed * ServiceLocator::getInstance()->getTimeService()->getDeltaTime(); + + currentPosition.x = std::min(currentPosition.x, player_model->right_most_position.x); + player_model->setPlayerPosition(currentPosition); +} \ No newline at end of file diff --git a/Space-Invaders/Source/Player/PlayerModel.cpp b/Space-Invaders/Source/Player/PlayerModel.cpp new file mode 100644 index 000000000..0d51db820 --- /dev/null +++ b/Space-Invaders/Source/Player/PlayerModel.cpp @@ -0,0 +1,45 @@ +#include "../../Header/Player/PlayerModel.h" + +PlayerModel::PlayerModel() { } + +PlayerModel::~PlayerModel() { } + +void PlayerModel::initialize() { reset(); } // remember to call reset() + +void PlayerModel::reset() +{ + player_state = PlayerState::ALIVE; // set state to alive + player_position = initial_player_position; + player_score = 0; +} + +sf::Vector2f PlayerModel::getPlayerPosition() +{ + return player_position; +} + +void PlayerModel::setPlayerPosition(sf::Vector2f position) +{ + player_position = position; +} + +int PlayerModel::getPlayerScore() +{ + return player_score; +} + +void PlayerModel::setPlayerScore(int score) +{ + player_score = score; +} + +//.. +PlayerState PlayerModel::getPlayerState() +{ + return player_state; +} + +void PlayerModel::setPlayerState(PlayerState state) +{ + player_state = state; +} \ No newline at end of file diff --git a/Space-Invaders/Source/Player/PlayerService.cpp b/Space-Invaders/Source/Player/PlayerService.cpp new file mode 100644 index 000000000..af4e3d1e8 --- /dev/null +++ b/Space-Invaders/Source/Player/PlayerService.cpp @@ -0,0 +1,27 @@ +#include "../../Header/Player/PlayerService.h" +#include "../../Header/Player/PlayerController.h" + +PlayerService::PlayerService() +{ + player_controller = new PlayerController(); +} + +PlayerService::~PlayerService() +{ + delete (player_controller); +} + +void PlayerService::initialize() +{ + player_controller->initialize(); +} + +void PlayerService::update() +{ + player_controller->update(); +} + +void PlayerService::render() +{ + player_controller->render(); +} \ No newline at end of file diff --git a/Space-Invaders/Source/Player/PlayerView.cpp b/Space-Invaders/Source/Player/PlayerView.cpp new file mode 100644 index 000000000..b3abf9070 --- /dev/null +++ b/Space-Invaders/Source/Player/PlayerView.cpp @@ -0,0 +1,50 @@ +#include "../../Header/Player/PlayerView.h" +#include "../../Header/Global/ServiceLocator.h" + +PlayerView::PlayerView() { } + +PlayerView::~PlayerView() { } + +void PlayerView::initialize() +{ + + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + initializePlayerSprite(); +} + +void PlayerView::initialize(PlayerController* controller) +{ + player_controller = controller; //to later use it for setting position + 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() +{ + //set the updated position before we render + player_sprite.setPosition(player_controller->getPlayerPosition()); +} + +void PlayerView::render() +{ + game_window->draw(player_sprite); +} \ No newline at end of file diff --git a/Space-Invaders/Source/Time/TimeService.cpp b/Space-Invaders/Source/Time/TimeService.cpp new file mode 100644 index 000000000..0bfc0d679 --- /dev/null +++ b/Space-Invaders/Source/Time/TimeService.cpp @@ -0,0 +1,39 @@ +#include "../../Header/Time/TimeService.h" + +void TimeService::initialize() +{ + previous_time = std::chrono::steady_clock::now(); + delta_time = 0; +} + +void TimeService::update() +{ + updateDeltaTime(); +} + +float TimeService::getDeltaTime() +{ + return delta_time; +} + +void TimeService::updateDeltaTime() +{ + delta_time = calculateDeltaTime(); + updatePreviousTime(); +} + +float TimeService::calculateDeltaTime() +{ + // 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. + return static_cast(delta) / static_cast(1000000); +} + +// Update previous_time to the current time +void TimeService::updatePreviousTime() +{ + previous_time = std::chrono::steady_clock::now(); +} diff --git a/Space-Invaders/Space-Invaders.vcxproj b/Space-Invaders/Space-Invaders.vcxproj index 6f7fa388d..3dd5235bd 100644 --- a/Space-Invaders/Space-Invaders.vcxproj +++ b/Space-Invaders/Space-Invaders.vcxproj @@ -1,140 +1,160 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {ab3664cd-9870-4359-8811-b481db3b55a0} - SpaceInvaders - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)sfml\include;%(AdditionalIncludeDirectories) - - - Console - true - $(SolutionDir)sfml\lib;%(AdditionalLibraryDirectories) - sfml-graphics-d.lib;sfml-window-d.lib;sfml-network-d.lib;sfml-audio-d.lib;sfml-system-d.lib;%(AdditionalDependencies) - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir)sfml\include;%(AdditionalIncludeDirectories) - - - Console - true - true - true - $(SolutionDir)sfml\lib;%(AdditionalLibraryDirectories) - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ab3664cd-9870-4359-8811-b481db3b55a0} + SpaceInvaders + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)sfml\include;%(AdditionalIncludeDirectories) + + + Console + true + $(SolutionDir)sfml\lib;%(AdditionalLibraryDirectories) + sfml-graphics-d.lib;sfml-window-d.lib;sfml-network-d.lib;sfml-audio-d.lib;sfml-system-d.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)sfml\include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + $(SolutionDir)sfml\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Space-Invaders/Space-Invaders.vcxproj.filters b/Space-Invaders/Space-Invaders.vcxproj.filters index ce0c35ccf..8ae369c39 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.filters +++ b/Space-Invaders/Space-Invaders.vcxproj.filters @@ -1,22 +1,78 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 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 + + \ No newline at end of file diff --git a/Space-Invaders/Space-Invaders.vcxproj.user b/Space-Invaders/Space-Invaders.vcxproj.user index 966b4ffb6..429333de9 100644 --- a/Space-Invaders/Space-Invaders.vcxproj.user +++ b/Space-Invaders/Space-Invaders.vcxproj.user @@ -1,6 +1,6 @@ - - - - true - + + + + true + \ No newline at end of file diff --git a/Space-Invaders/main.cpp b/Space-Invaders/main.cpp index 7d5f90dff..434cdaeb5 100644 --- a/Space-Invaders/main.cpp +++ b/Space-Invaders/main.cpp @@ -1,5 +1,106 @@ - -int main() -{ - return 0; -} \ No newline at end of file +#include +#include +#include "Header/Main/GameService.h" + + +/*class Player +{ +private: + + // Private Properties + int health = 3; + sf::Vector2f position = sf::Vector2f(200.0f, 100.0f); + int movement_speed = 1; + int player_score = 0; + +public: + + // Public Properties + sf::Texture player_texture; + sf::Sprite player_sprite; + + //Public Functions, Getter & Setter methods + void move(float offsetX) { + position.x += offsetX; + } + + int getMoveSpeed() { + return movement_speed; + } + + int getScore() { + return player_score; + }; + + void setScore(int newScore) { + player_score = newScore; + }; + + sf::Vector2f getPosition() { + return position; + } + + void setPosition(sf::Vector2f newPosition) { + position = newPosition; + } + + //New methods to be added + void takeDamage() {}; + void move() {}; + void shootBullets() {}; +};*/ + +int main() +{ + /* + // Define the video mode (dimensions) + sf::VideoMode videoMode = sf::VideoMode(800, 600); + + // Create a window object with specific dimensions and a title + sf::RenderWindow window(videoMode, "My SFML Window"); + + //Player object + Player player; + + //Load Textures and sprite + player.player_texture.loadFromFile("assets/textures/player_ship.png"); + + player.player_sprite.setTexture(player.player_texture); + + while (window.isOpen()) { + sf::Event event; + while (window.pollEvent(event)) { + // Check for window closure + if (event.type == sf::Event::Closed) + window.close(); + } + + // Handle keyboard input + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { + player.move(-1.0f* player.getMoveSpeed()); + } + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { + player.move(1.0f * player.getMoveSpeed()); + } + + // Clear the window--- + window.clear(sf::Color::Black); + + // Set and draw player + player.player_sprite.setPosition(player.getPosition()); + + window.draw(player.player_sprite); + + // Display whatever you draw + window.display(); + }*/ + GameService* game_service = new GameService(); + + game_service->ignite(); + + while (game_service->isRunning()) + { + game_service->update(); + game_service->render(); + } +}