From 69157ba38a5fee849d2069d78052a6fcd948f82a Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:31:15 -0400 Subject: [PATCH 1/8] Create code to render Player --- Array-Jumper/header/Player/PlayerModel.h | 26 ++++++++++ Array-Jumper/header/Player/PlayerView.h | 35 ++++++++++++++ Array-Jumper/source/Player/PlayerModel.cpp | 22 +++++++++ Array-Jumper/source/Player/PlayerView.cpp | 55 ++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 Array-Jumper/header/Player/PlayerModel.h create mode 100644 Array-Jumper/header/Player/PlayerView.h create mode 100644 Array-Jumper/source/Player/PlayerModel.cpp create mode 100644 Array-Jumper/source/Player/PlayerView.cpp diff --git a/Array-Jumper/header/Player/PlayerModel.h b/Array-Jumper/header/Player/PlayerModel.h new file mode 100644 index 00000000..43014b1b --- /dev/null +++ b/Array-Jumper/header/Player/PlayerModel.h @@ -0,0 +1,26 @@ +#pragma once +namespace Player +{ + enum class PlayerState + { + ALIVE, + DEAD + }; + + class PlayerModel + { + public: + + int getPosition(); + void setPosition(int player_position); + + PlayerState getPlayerState(); + void setPlayerState(PlayerState state); + private: + int current_position; + PlayerState player_state; + + }; + + +} \ No newline at end of file diff --git a/Array-Jumper/header/Player/PlayerView.h b/Array-Jumper/header/Player/PlayerView.h new file mode 100644 index 00000000..83a2539c --- /dev/null +++ b/Array-Jumper/header/Player/PlayerView.h @@ -0,0 +1,35 @@ +#pragma once +#include "../../header/UI/UIElement/ImageView.h" + +namespace Player +{ + class PlayerView + { + public: + PlayerView(); + ~PlayerView(); + + void initialize(); + void update(); + void render(); + + + private: + UI::UIElement::ImageView* player_image; + sf::RenderWindow* game_window; + + float player_height; + float player_width; + + void initializePlayerImage(); + void drawPlayer(); + void loadImage(); + void calculatePlayerDimension(); + void updatePlayerPosition(); + + sf::Vector2f calculatePlayerPosition(); + + }; + + +} \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerModel.cpp b/Array-Jumper/source/Player/PlayerModel.cpp new file mode 100644 index 00000000..2e346512 --- /dev/null +++ b/Array-Jumper/source/Player/PlayerModel.cpp @@ -0,0 +1,22 @@ +#include "../../header/Player/PlayerModel.h" + + +namespace Player { + + int PlayerModel::getPosition() + { + return current_position; + } + void PlayerModel::setPosition(int player_position) + { + current_position = player_position; + } + PlayerState PlayerModel::getPlayerState() + { + return player_state; + } + void PlayerModel::setPlayerState(PlayerState state) + { + player_state = state; + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerView.cpp b/Array-Jumper/source/Player/PlayerView.cpp new file mode 100644 index 00000000..a3b8435a --- /dev/null +++ b/Array-Jumper/source/Player/PlayerView.cpp @@ -0,0 +1,55 @@ +#include "../../header/Player/PlayerView.h" +#include "../../header/Global/Config.h" +#include "../../header/Global/ServiceLocator.h" +namespace Player +{ + using namespace Global; + + Player::PlayerView::PlayerView() + { + game_window = nullptr; + player_image = new UI::UIElement::ImageView(); + } + PlayerView::~PlayerView() + { + } + void PlayerView::initialize() + { + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + loadImage(); + } + void PlayerView::update() + { + updatePlayerPosition(); + } + void PlayerView::render() + { + drawPlayer(); + } + void PlayerView::initializePlayerImage() + { + player_image->initialize(Config::character_texture_path, player_width, player_height, sf::Vector2f(0, 0)); + } + void PlayerView::drawPlayer() + { + player_image->render(); + } + void PlayerView::loadImage() + { + calculatePlayerDimension(); + initializePlayerImage(); + } + void PlayerView::calculatePlayerDimension() + { + player_width = 1000.f; + player_height = 1000.f; + } + void PlayerView::updatePlayerPosition() + { + player_image->setPosition(calculatePlayerPosition()); + } + sf::Vector2f PlayerView::calculatePlayerPosition() + { + return sf::Vector2f(0,0); + } +} \ No newline at end of file From e14f0c446da3edd0768ff6d1e006814b217545bb Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:06:21 -0400 Subject: [PATCH 2/8] Draw the Player on Screen --- Array-Jumper/Array-Jumper.vcxproj | 8 ++++ Array-Jumper/Array-Jumper.vcxproj.filters | 8 ++++ Array-Jumper/header/Global/ServiceLocator.h | 3 ++ Array-Jumper/header/Player/PlayerController.h | 27 +++++++++++++ Array-Jumper/header/Player/PlayerService.h | 20 ++++++++++ Array-Jumper/header/Player/PlayerView.h | 5 ++- Array-Jumper/source/Global/ServiceLocator.cpp | 19 +++++++++ .../source/Player/PlayerController.cpp | 39 +++++++++++++++++++ Array-Jumper/source/Player/PlayerService.cpp | 25 ++++++++++++ Array-Jumper/source/Player/PlayerView.cpp | 13 ++++++- .../UI/MainMenu/MainMenuUIController.cpp | 1 + 11 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 Array-Jumper/header/Player/PlayerController.h create mode 100644 Array-Jumper/header/Player/PlayerService.h create mode 100644 Array-Jumper/source/Player/PlayerController.cpp create mode 100644 Array-Jumper/source/Player/PlayerService.cpp diff --git a/Array-Jumper/Array-Jumper.vcxproj b/Array-Jumper/Array-Jumper.vcxproj index 658ea835..58d93879 100644 --- a/Array-Jumper/Array-Jumper.vcxproj +++ b/Array-Jumper/Array-Jumper.vcxproj @@ -137,6 +137,10 @@ + + + + @@ -154,6 +158,10 @@ + + + + diff --git a/Array-Jumper/Array-Jumper.vcxproj.filters b/Array-Jumper/Array-Jumper.vcxproj.filters index dff4a580..2db32309 100644 --- a/Array-Jumper/Array-Jumper.vcxproj.filters +++ b/Array-Jumper/Array-Jumper.vcxproj.filters @@ -44,6 +44,10 @@ + + + + @@ -74,6 +78,10 @@ + + + + diff --git a/Array-Jumper/header/Global/ServiceLocator.h b/Array-Jumper/header/Global/ServiceLocator.h index 7e9ef35a..f3e053a6 100644 --- a/Array-Jumper/header/Global/ServiceLocator.h +++ b/Array-Jumper/header/Global/ServiceLocator.h @@ -3,6 +3,7 @@ #include "../../header/Event/EventService.h" #include "../../header/UI/UIService.h" #include "../../header/Sound/SoundService.h" +#include "../../header/Player/PlayerService.h" namespace Global { @@ -13,6 +14,7 @@ namespace Global Event::EventService* event_service; Sound::SoundService* sound_service; UI::UIService* ui_service; + Player::PlayerService* player_service; ~ServiceLocator(); @@ -31,5 +33,6 @@ namespace Global Event::EventService* getEventService(); Sound::SoundService* getSoundService(); UI::UIService* getUIService(); + Player::PlayerService* getPlayerService(); }; } \ No newline at end of file diff --git a/Array-Jumper/header/Player/PlayerController.h b/Array-Jumper/header/Player/PlayerController.h new file mode 100644 index 00000000..ad0e03bc --- /dev/null +++ b/Array-Jumper/header/Player/PlayerController.h @@ -0,0 +1,27 @@ +#pragma once +namespace Player +{ + class PlayerModel; + class PlayerView; + enum class PlayerState; + + class PlayerController + { + public: + PlayerController(); + ~ PlayerController(); + + void initialize(); + void update(); + void render(); + + PlayerState getPlayerState(); + void setPlayerState(PlayerState state); + + private: + PlayerModel* player_model; + PlayerView* player_view; + + + }; +} \ No newline at end of file diff --git a/Array-Jumper/header/Player/PlayerService.h b/Array-Jumper/header/Player/PlayerService.h new file mode 100644 index 00000000..acaaecde --- /dev/null +++ b/Array-Jumper/header/Player/PlayerService.h @@ -0,0 +1,20 @@ +#pragma once +namespace Player +{ + class PlayerController; + class PlayerService + { + public: + PlayerService(); + ~PlayerService(); + + void initialize(); + void update(); + void render(); + + private: + PlayerController* player_conroller; + }; + + +} \ No newline at end of file diff --git a/Array-Jumper/header/Player/PlayerView.h b/Array-Jumper/header/Player/PlayerView.h index 83a2539c..5b55b3ef 100644 --- a/Array-Jumper/header/Player/PlayerView.h +++ b/Array-Jumper/header/Player/PlayerView.h @@ -3,10 +3,11 @@ namespace Player { + class PlayerController; class PlayerView { public: - PlayerView(); + PlayerView(PlayerController* controller); ~PlayerView(); void initialize(); @@ -18,6 +19,8 @@ namespace Player UI::UIElement::ImageView* player_image; sf::RenderWindow* game_window; + PlayerController* player_controller; + float player_height; float player_width; diff --git a/Array-Jumper/source/Global/ServiceLocator.cpp b/Array-Jumper/source/Global/ServiceLocator.cpp index 5aa28494..42acd7ba 100644 --- a/Array-Jumper/source/Global/ServiceLocator.cpp +++ b/Array-Jumper/source/Global/ServiceLocator.cpp @@ -9,6 +9,7 @@ namespace Global using namespace Sound; using namespace UI; using namespace Main; + using namespace Player; ServiceLocator::ServiceLocator() { @@ -16,6 +17,7 @@ namespace Global event_service = nullptr; sound_service = nullptr; ui_service = nullptr; + player_service = nullptr; createServices(); } @@ -28,6 +30,7 @@ namespace Global event_service = new EventService(); sound_service = new SoundService(); ui_service = new UIService(); + player_service = new PlayerService(); } void ServiceLocator::initialize() @@ -36,6 +39,7 @@ namespace Global event_service->initialize(); sound_service->initialize(); ui_service->initialize(); + player_service->initialize(); } void ServiceLocator::update() @@ -43,12 +47,22 @@ namespace Global graphic_service->update(); event_service->update(); ui_service->update(); + if (GameService::getGameState() == GameState::GAMEPLAY) + { + player_service->render(); + + } } void ServiceLocator::render() { graphic_service->render(); ui_service->render(); + if (GameService::getGameState() == GameState::GAMEPLAY) + { + player_service->render(); + + } } void ServiceLocator::clearAllServices() @@ -57,6 +71,7 @@ namespace Global delete(event_service); delete(sound_service); delete(ui_service); + delete(player_service); } ServiceLocator* ServiceLocator::getInstance() @@ -72,4 +87,8 @@ namespace Global SoundService* ServiceLocator::getSoundService() { return sound_service; } UIService* ServiceLocator::getUIService() { return ui_service; } + Player::PlayerService* ServiceLocator::getPlayerService() + { + return player_service; + } } \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerController.cpp b/Array-Jumper/source/Player/PlayerController.cpp new file mode 100644 index 00000000..7681c4d8 --- /dev/null +++ b/Array-Jumper/source/Player/PlayerController.cpp @@ -0,0 +1,39 @@ +#include "../../header/Player/PlayerController.h" +#include "../../header/Player/PlayerModel.h" +#include "../../header/Player/PlayerView.h" + +namespace Player +{ + Player::PlayerController::PlayerController() + { + player_model = new PlayerModel(); + player_view = new PlayerView(this); + } + Player::PlayerController::~PlayerController() + { + delete(player_model); + delete(player_view); + } + void PlayerController::initialize() + { + player_view->initialize(); + + } + void PlayerController::update() + { + player_view->update(); + + } + void PlayerController::render() + { + player_view->render(); + } + PlayerState PlayerController::getPlayerState() + { + return player_model->getPlayerState(); + } + void PlayerController::setPlayerState(PlayerState state) + { + player_model->setPlayerState(state); + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerService.cpp b/Array-Jumper/source/Player/PlayerService.cpp new file mode 100644 index 00000000..aee3bc68 --- /dev/null +++ b/Array-Jumper/source/Player/PlayerService.cpp @@ -0,0 +1,25 @@ +#include "../../header/Player/PlayerService.h" +#include "../../header/Player/PlayerController.h" +namespace Player +{ + Player::PlayerService::PlayerService() + { + player_conroller = new PlayerController(); + } + PlayerService::~PlayerService() + { + delete(player_conroller); + } + void PlayerService::initialize() + { + player_conroller->initialize(); + } + void PlayerService::update() + { + player_conroller->update(); + } + void PlayerService::render() + { + player_conroller->render(); + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerView.cpp b/Array-Jumper/source/Player/PlayerView.cpp index a3b8435a..70e6acea 100644 --- a/Array-Jumper/source/Player/PlayerView.cpp +++ b/Array-Jumper/source/Player/PlayerView.cpp @@ -1,12 +1,15 @@ #include "../../header/Player/PlayerView.h" #include "../../header/Global/Config.h" #include "../../header/Global/ServiceLocator.h" +#include "../../header/Player/PlayerController.h" +#include "../../header/Player/PlayerModel.h" namespace Player { using namespace Global; - Player::PlayerView::PlayerView() + Player::PlayerView::PlayerView(PlayerController* controller) { + player_controller = controller; game_window = nullptr; player_image = new UI::UIElement::ImageView(); } @@ -24,7 +27,13 @@ namespace Player } void PlayerView::render() { - drawPlayer(); + switch (player_controller->getPlayerState()) + { + case PlayerState::ALIVE: + drawPlayer(); + default: + break; + } } void PlayerView::initializePlayerImage() { diff --git a/Array-Jumper/source/UI/MainMenu/MainMenuUIController.cpp b/Array-Jumper/source/UI/MainMenu/MainMenuUIController.cpp index b3c74893..7a572427 100644 --- a/Array-Jumper/source/UI/MainMenu/MainMenuUIController.cpp +++ b/Array-Jumper/source/UI/MainMenu/MainMenuUIController.cpp @@ -75,6 +75,7 @@ namespace UI void MainMenuUIController::playButtonCallback() { ServiceLocator::getInstance()->getSoundService()->playSound(SoundType::BUTTON_CLICK); + GameService::setGameState(GameState::GAMEPLAY); } void MainMenuUIController::instructionsButtonCallback() From f1d48e6462e9b1b3d7cf003a4991969096c93ce2 Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:43:00 -0400 Subject: [PATCH 3/8] Draw Background Image --- Array-Jumper/Array-Jumper.vcxproj | 8 +++ Array-Jumper/Array-Jumper.vcxproj.filters | 8 +++ Array-Jumper/header/Global/ServiceLocator.h | 3 ++ Array-Jumper/header/Level/LevelController.h | 20 +++++++ Array-Jumper/header/Level/LevelModel.h | 15 ++++++ Array-Jumper/header/Level/LevelService.h | 19 +++++++ Array-Jumper/header/Level/LevelView.h | 35 ++++++++++++ Array-Jumper/source/Global/ServiceLocator.cpp | 14 ++++- Array-Jumper/source/Level/LevelController.cpp | 29 ++++++++++ Array-Jumper/source/Level/LevelModel.cpp | 10 ++++ Array-Jumper/source/Level/LevelService.cpp | 25 +++++++++ Array-Jumper/source/Level/LevelView.cpp | 53 +++++++++++++++++++ 12 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 Array-Jumper/header/Level/LevelController.h create mode 100644 Array-Jumper/header/Level/LevelModel.h create mode 100644 Array-Jumper/header/Level/LevelService.h create mode 100644 Array-Jumper/header/Level/LevelView.h create mode 100644 Array-Jumper/source/Level/LevelController.cpp create mode 100644 Array-Jumper/source/Level/LevelModel.cpp create mode 100644 Array-Jumper/source/Level/LevelService.cpp create mode 100644 Array-Jumper/source/Level/LevelView.cpp diff --git a/Array-Jumper/Array-Jumper.vcxproj b/Array-Jumper/Array-Jumper.vcxproj index 58d93879..652afe6b 100644 --- a/Array-Jumper/Array-Jumper.vcxproj +++ b/Array-Jumper/Array-Jumper.vcxproj @@ -137,6 +137,10 @@ + + + + @@ -158,6 +162,10 @@ + + + + diff --git a/Array-Jumper/Array-Jumper.vcxproj.filters b/Array-Jumper/Array-Jumper.vcxproj.filters index 2db32309..7c648ee9 100644 --- a/Array-Jumper/Array-Jumper.vcxproj.filters +++ b/Array-Jumper/Array-Jumper.vcxproj.filters @@ -48,6 +48,10 @@ + + + + @@ -82,6 +86,10 @@ + + + + diff --git a/Array-Jumper/header/Global/ServiceLocator.h b/Array-Jumper/header/Global/ServiceLocator.h index f3e053a6..118cb896 100644 --- a/Array-Jumper/header/Global/ServiceLocator.h +++ b/Array-Jumper/header/Global/ServiceLocator.h @@ -4,6 +4,7 @@ #include "../../header/UI/UIService.h" #include "../../header/Sound/SoundService.h" #include "../../header/Player/PlayerService.h" +#include "../../header/Level/LevelService.h" namespace Global { @@ -15,6 +16,7 @@ namespace Global Sound::SoundService* sound_service; UI::UIService* ui_service; Player::PlayerService* player_service; + Level::LevelService* level_service; ~ServiceLocator(); @@ -34,5 +36,6 @@ namespace Global Sound::SoundService* getSoundService(); UI::UIService* getUIService(); Player::PlayerService* getPlayerService(); + Level::LevelService* getLevelService(); }; } \ No newline at end of file diff --git a/Array-Jumper/header/Level/LevelController.h b/Array-Jumper/header/Level/LevelController.h new file mode 100644 index 00000000..698c391f --- /dev/null +++ b/Array-Jumper/header/Level/LevelController.h @@ -0,0 +1,20 @@ +#pragma once +namespace Level +{ + class LevelModel; + class LevelView; + class LevelController + { + public: + LevelController(); + ~LevelController(); + + void initialize(); + void update(); + void render(); + + private: + LevelModel* level_model; + LevelView* level_view; + }; +} \ No newline at end of file diff --git a/Array-Jumper/header/Level/LevelModel.h b/Array-Jumper/header/Level/LevelModel.h new file mode 100644 index 00000000..6f914585 --- /dev/null +++ b/Array-Jumper/header/Level/LevelModel.h @@ -0,0 +1,15 @@ +#pragma once +namespace Level +{ + class LevelModel + { + public: + LevelModel(); + ~LevelModel(); + + private: + + }; + + +} \ No newline at end of file diff --git a/Array-Jumper/header/Level/LevelService.h b/Array-Jumper/header/Level/LevelService.h new file mode 100644 index 00000000..319b8fbe --- /dev/null +++ b/Array-Jumper/header/Level/LevelService.h @@ -0,0 +1,19 @@ +#pragma once +namespace Level +{ + class LevelController; + class LevelService + { + public: + LevelService(); + ~LevelService(); + + void initialize(); + void update(); + void render(); + + private: + LevelController* level_controller; + }; + +} \ No newline at end of file diff --git a/Array-Jumper/header/Level/LevelView.h b/Array-Jumper/header/Level/LevelView.h new file mode 100644 index 00000000..7562cba1 --- /dev/null +++ b/Array-Jumper/header/Level/LevelView.h @@ -0,0 +1,35 @@ +#pragma once +#include "../../header/UI/UIElement/ImageView.h" +namespace Level +{ + class LevelController; + class LevelView + { + public: + LevelView(LevelController* controller); + ~LevelView(); + + void initilaize(); + void update(); + void render(); + + + + + + + private: + LevelController* level_controller; + UI::UIElement::ImageView* background_image; + sf::RenderWindow* game_window; + + const float background_alpha = 110.f; + + void createImage(); + void initilizeImage(); + void updateImage(); + void drawImage(); + void deleteImage(); + }; + +} \ No newline at end of file diff --git a/Array-Jumper/source/Global/ServiceLocator.cpp b/Array-Jumper/source/Global/ServiceLocator.cpp index 42acd7ba..0ff20b89 100644 --- a/Array-Jumper/source/Global/ServiceLocator.cpp +++ b/Array-Jumper/source/Global/ServiceLocator.cpp @@ -10,6 +10,7 @@ namespace Global using namespace UI; using namespace Main; using namespace Player; + using namespace Level; ServiceLocator::ServiceLocator() { @@ -17,6 +18,7 @@ namespace Global event_service = nullptr; sound_service = nullptr; ui_service = nullptr; + level_service = nullptr; player_service = nullptr; createServices(); @@ -30,6 +32,7 @@ namespace Global event_service = new EventService(); sound_service = new SoundService(); ui_service = new UIService(); + level_service = new LevelService(); player_service = new PlayerService(); } @@ -39,6 +42,7 @@ namespace Global event_service->initialize(); sound_service->initialize(); ui_service->initialize(); + level_service->initialize(); player_service->initialize(); } @@ -49,7 +53,8 @@ namespace Global ui_service->update(); if (GameService::getGameState() == GameState::GAMEPLAY) { - player_service->render(); + level_service->update(); + player_service->update(); } } @@ -60,6 +65,7 @@ namespace Global ui_service->render(); if (GameService::getGameState() == GameState::GAMEPLAY) { + level_service->render(); player_service->render(); } @@ -71,6 +77,7 @@ namespace Global delete(event_service); delete(sound_service); delete(ui_service); + delete(level_service); delete(player_service); } @@ -87,8 +94,13 @@ namespace Global SoundService* ServiceLocator::getSoundService() { return sound_service; } UIService* ServiceLocator::getUIService() { return ui_service; } + Level::LevelService* ServiceLocator::getLevelService() + { + return level_service; + } Player::PlayerService* ServiceLocator::getPlayerService() { return player_service; } + } \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelController.cpp b/Array-Jumper/source/Level/LevelController.cpp new file mode 100644 index 00000000..9f019c47 --- /dev/null +++ b/Array-Jumper/source/Level/LevelController.cpp @@ -0,0 +1,29 @@ +#include "../../header/Level/LevelController.h" +#include "../../header/Level/LevelModel.h" +#include "../../header/Level/LevelView.h" +namespace Level +{ + Level::LevelController::LevelController() + { + level_model = new LevelModel(); + level_view = new LevelView(this); + } + LevelController::~LevelController() + { + delete(level_model); + delete(level_view); + + } + void LevelController::initialize() + { + level_view->initilaize(); + } + void LevelController::update() + { + level_view->update(); + } + void LevelController::render() + { + level_view->render(); + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelModel.cpp b/Array-Jumper/source/Level/LevelModel.cpp new file mode 100644 index 00000000..ac85569b --- /dev/null +++ b/Array-Jumper/source/Level/LevelModel.cpp @@ -0,0 +1,10 @@ +#include "../../header/Level/LevelModel.h" +namespace Level +{ + Level::LevelModel::LevelModel() + { + } + LevelModel::~LevelModel() + { + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelService.cpp b/Array-Jumper/source/Level/LevelService.cpp new file mode 100644 index 00000000..9dfada3c --- /dev/null +++ b/Array-Jumper/source/Level/LevelService.cpp @@ -0,0 +1,25 @@ +#include "../../header/Level/LevelService.h" +#include "../../header/Level/LevelController.h" +namespace Level +{ + Level::LevelService::LevelService() + { + level_controller = new LevelController(); + } + LevelService::~LevelService() + { + delete(level_controller); + } + void LevelService::initialize() + { + level_controller->initialize(); + } + void LevelService::update() + { + level_controller->update(); + } + void LevelService::render() + { + level_controller->render(); + } +} \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelView.cpp b/Array-Jumper/source/Level/LevelView.cpp new file mode 100644 index 00000000..4530819a --- /dev/null +++ b/Array-Jumper/source/Level/LevelView.cpp @@ -0,0 +1,53 @@ +#include "../../header/Level/LevelView.h" +#include "../../header/Level/LevelController.h" +#include "../../header/Global/Config.h" +#include "../../header/Global/ServiceLocator.h" +namespace Level +{ + using namespace Global; + + Level::LevelView::LevelView(LevelController* controller) + { + level_controller = controller; + game_window = nullptr; + createImage(); + } + LevelView::~LevelView() + { + deleteImage(); + } + void LevelView::initilaize() + { + game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + initilizeImage(); + } + void LevelView::update() + { + updateImage(); + } + void LevelView::render() + { + drawImage(); + } + void LevelView::createImage() + { + background_image = new UI::UIElement::ImageView(); + } + void LevelView::initilizeImage() + { + background_image->initialize(Config::array_jumper_bg_texture_path, game_window->getSize().x, game_window->getSize().y, sf::Vector2f(0, 0)); + background_image->setImageAlpha(background_alpha); + } + void LevelView::updateImage() + { + background_image->update(); + } + void LevelView::drawImage() + { + background_image->render(); + } + void LevelView::deleteImage() + { + delete(background_image); + } +} \ No newline at end of file From 2479dbe28c24df82d9406bcabb0322e1e671afa0 Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:00:37 -0400 Subject: [PATCH 4/8] Create Data for Level --- Array-Jumper/Array-Jumper.vcxproj | 4 ++- Array-Jumper/Array-Jumper.vcxproj.filters | 1 + Array-Jumper/header/Level/BlockType.h | 11 ++++++++ Array-Jumper/header/Level/LevelController.h | 3 +++ Array-Jumper/header/Level/LevelData.h | 26 +++++++++++++++++++ Array-Jumper/header/Level/LevelModel.h | 16 +++++++++++- Array-Jumper/source/Level/LevelController.cpp | 4 +++ Array-Jumper/source/Level/LevelModel.cpp | 5 ++++ 8 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 Array-Jumper/header/Level/BlockType.h create mode 100644 Array-Jumper/header/Level/LevelData.h diff --git a/Array-Jumper/Array-Jumper.vcxproj b/Array-Jumper/Array-Jumper.vcxproj index 652afe6b..ada9f8bf 100644 --- a/Array-Jumper/Array-Jumper.vcxproj +++ b/Array-Jumper/Array-Jumper.vcxproj @@ -1,4 +1,4 @@ - + @@ -162,7 +162,9 @@ + + diff --git a/Array-Jumper/Array-Jumper.vcxproj.filters b/Array-Jumper/Array-Jumper.vcxproj.filters index 7c648ee9..3d6e2cc0 100644 --- a/Array-Jumper/Array-Jumper.vcxproj.filters +++ b/Array-Jumper/Array-Jumper.vcxproj.filters @@ -90,6 +90,7 @@ + diff --git a/Array-Jumper/header/Level/BlockType.h b/Array-Jumper/header/Level/BlockType.h new file mode 100644 index 00000000..8f7e9db6 --- /dev/null +++ b/Array-Jumper/header/Level/BlockType.h @@ -0,0 +1,11 @@ +#pragma once + +enum class BlockType +{ + OBSTACLE_ONE = -1, + OBSTACLE_TWO = -2, + TARGET = 0, + ONE = 1, + TWO = 2, + THREE = 3, +}; \ No newline at end of file diff --git a/Array-Jumper/header/Level/LevelController.h b/Array-Jumper/header/Level/LevelController.h index 698c391f..54ce9d23 100644 --- a/Array-Jumper/header/Level/LevelController.h +++ b/Array-Jumper/header/Level/LevelController.h @@ -1,4 +1,5 @@ #pragma once +#include "BlockType.h" namespace Level { class LevelModel; @@ -13,6 +14,8 @@ namespace Level void update(); void render(); + BlockType getCurrentBoxValue(int currentPosion); + private: LevelModel* level_model; LevelView* level_view; diff --git a/Array-Jumper/header/Level/LevelData.h b/Array-Jumper/header/Level/LevelData.h new file mode 100644 index 00000000..1f33d8a7 --- /dev/null +++ b/Array-Jumper/header/Level/LevelData.h @@ -0,0 +1,26 @@ +#pragma once +#include "../../header/Level/BlockType.h" + +namespace Level +{ + struct LevelData + { + static const int number_of_box = 10; + BlockType level_boxes[number_of_box] = { + BlockType::ONE, + BlockType::TWO, + BlockType::OBSTACLE_ONE, + BlockType::TWO, + BlockType::THREE, + BlockType::ONE, + BlockType::OBSTACLE_TWO, + BlockType::TWO, + BlockType::ONE, + BlockType::TARGET + }; + + + + }; +} + diff --git a/Array-Jumper/header/Level/LevelModel.h b/Array-Jumper/header/Level/LevelModel.h index 6f914585..512e8aaf 100644 --- a/Array-Jumper/header/Level/LevelModel.h +++ b/Array-Jumper/header/Level/LevelModel.h @@ -1,14 +1,28 @@ #pragma once +#include "../../header/Level/LevelData.h" namespace Level { + struct BoxDimension + { + float box_width; + float box_height; + + float box_spacing; + + float box_spacing_percentage = 0.3f; + float bottom_offset = 200.f; + + }; class LevelModel { public: LevelModel(); ~LevelModel(); - private: + BlockType getCurrentBoxValue(int currentPosion); + private: + LevelData current_level_data; }; diff --git a/Array-Jumper/source/Level/LevelController.cpp b/Array-Jumper/source/Level/LevelController.cpp index 9f019c47..effd5ed7 100644 --- a/Array-Jumper/source/Level/LevelController.cpp +++ b/Array-Jumper/source/Level/LevelController.cpp @@ -26,4 +26,8 @@ namespace Level { level_view->render(); } + BlockType LevelController::getCurrentBoxValue(int currentPosion) + { + return level_model->getCurrentBoxValue(currentPosion); + } } \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelModel.cpp b/Array-Jumper/source/Level/LevelModel.cpp index ac85569b..9f317616 100644 --- a/Array-Jumper/source/Level/LevelModel.cpp +++ b/Array-Jumper/source/Level/LevelModel.cpp @@ -1,4 +1,5 @@ #include "../../header/Level/LevelModel.h" + namespace Level { Level::LevelModel::LevelModel() @@ -7,4 +8,8 @@ namespace Level LevelModel::~LevelModel() { } + BlockType LevelModel::getCurrentBoxValue(int currentPosion) + { + return current_level_data.level_boxes[currentPosion]; + } } \ No newline at end of file From 85d1b9358733bdbbc7365cb9f5a2f465c333515f Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:30:22 -0400 Subject: [PATCH 5/8] Draw a Box with Overlay --- Array-Jumper/header/Level/LevelModel.h | 4 +- Array-Jumper/header/Level/LevelView.h | 18 ++++- Array-Jumper/source/Global/ServiceLocator.cpp | 6 +- Array-Jumper/source/Level/LevelView.cpp | 80 ++++++++++++++++++- 4 files changed, 100 insertions(+), 8 deletions(-) diff --git a/Array-Jumper/header/Level/LevelModel.h b/Array-Jumper/header/Level/LevelModel.h index 512e8aaf..393a3b97 100644 --- a/Array-Jumper/header/Level/LevelModel.h +++ b/Array-Jumper/header/Level/LevelModel.h @@ -4,8 +4,8 @@ namespace Level { struct BoxDimension { - float box_width; - float box_height; + float box_width = 300.f; + float box_height = 300.f; float box_spacing; diff --git a/Array-Jumper/header/Level/LevelView.h b/Array-Jumper/header/Level/LevelView.h index 7562cba1..3a9f3532 100644 --- a/Array-Jumper/header/Level/LevelView.h +++ b/Array-Jumper/header/Level/LevelView.h @@ -1,5 +1,6 @@ #pragma once #include "../../header/UI/UIElement/ImageView.h" +#include "LevelModel.h" namespace Level { class LevelController; @@ -13,18 +14,31 @@ namespace Level void update(); void render(); - - + void calcuateBoxDimension(); + UI::UIElement::ImageView* getBoxImage(BlockType type); + + void drawBox(sf::Vector2f position); + void drawBoxValue(sf::Vector2f position, BlockType type); private: LevelController* level_controller; UI::UIElement::ImageView* background_image; + UI::UIElement::ImageView* box_image; sf::RenderWindow* game_window; const float background_alpha = 110.f; + BoxDimension box_dimension; + + UI::UIElement::ImageView* target_overlay_image; + UI::UIElement::ImageView* letter_one_overlay_image; + UI::UIElement::ImageView* letter_two_overlay_image; + UI::UIElement::ImageView* letter_three_overlay_image; + UI::UIElement::ImageView* obstacle_one_overlay_image; + UI::UIElement::ImageView* obstacle_two_overlay_image; + void createImage(); void initilizeImage(); void updateImage(); diff --git a/Array-Jumper/source/Global/ServiceLocator.cpp b/Array-Jumper/source/Global/ServiceLocator.cpp index 0ff20b89..9f1e2f57 100644 --- a/Array-Jumper/source/Global/ServiceLocator.cpp +++ b/Array-Jumper/source/Global/ServiceLocator.cpp @@ -43,7 +43,7 @@ namespace Global sound_service->initialize(); ui_service->initialize(); level_service->initialize(); - player_service->initialize(); + //player_service->initialize(); } void ServiceLocator::update() @@ -54,7 +54,7 @@ namespace Global if (GameService::getGameState() == GameState::GAMEPLAY) { level_service->update(); - player_service->update(); + //player_service->update(); } } @@ -66,7 +66,7 @@ namespace Global if (GameService::getGameState() == GameState::GAMEPLAY) { level_service->render(); - player_service->render(); + //player_service->render(); } } diff --git a/Array-Jumper/source/Level/LevelView.cpp b/Array-Jumper/source/Level/LevelView.cpp index 4530819a..5ac6c5aa 100644 --- a/Array-Jumper/source/Level/LevelView.cpp +++ b/Array-Jumper/source/Level/LevelView.cpp @@ -5,6 +5,7 @@ namespace Level { using namespace Global; + using namespace UI::UIElement; Level::LevelView::LevelView(LevelController* controller) { @@ -29,25 +30,102 @@ namespace Level { drawImage(); } + void LevelView::calcuateBoxDimension() + { + if (!game_window) return; + + box_dimension.box_width = 300.f; + box_dimension.box_height = 300.f; + } + ImageView* LevelView::getBoxImage(BlockType type) + { + switch (type) + { + case BlockType::OBSTACLE_ONE: + return obstacle_one_overlay_image; + break; + case BlockType::OBSTACLE_TWO: + return obstacle_two_overlay_image; + break; + case BlockType::TARGET: + return target_overlay_image; + break; + case BlockType::ONE: + return letter_one_overlay_image; + break; + case BlockType::TWO: + return letter_two_overlay_image; + break; + case BlockType::THREE: + return letter_three_overlay_image; + break; + } + } + void LevelView::drawBox(sf::Vector2f position) + { + box_image->setPosition(position); + box_image->render(); + } + void LevelView::drawBoxValue(sf::Vector2f position, BlockType type) + { + ImageView* image = getBoxImage(type); + image->setPosition(position); + image->render(); + } void LevelView::createImage() { - background_image = new UI::UIElement::ImageView(); + background_image = new ImageView(); + box_image = new ImageView(); + target_overlay_image = new ImageView(); + letter_one_overlay_image = new ImageView(); + letter_two_overlay_image = new ImageView(); + letter_three_overlay_image = new ImageView(); + obstacle_one_overlay_image = new ImageView(); + obstacle_two_overlay_image = new ImageView(); + + } void LevelView::initilizeImage() { background_image->initialize(Config::array_jumper_bg_texture_path, game_window->getSize().x, game_window->getSize().y, sf::Vector2f(0, 0)); background_image->setImageAlpha(background_alpha); + + box_image->initialize(Config::box_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + //target_overlay_image->initialize(Config::target_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + letter_one_overlay_image->initialize(Config::letter_one_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + letter_two_overlay_image->initialize(Config::letter_two_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + letter_three_overlay_image->initialize(Config::letter_three_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + obstacle_one_overlay_image->initialize(Config::obstacle_01_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); + obstacle_two_overlay_image->initialize(Config::obstacle_02_texture_path, box_dimension.box_width, box_dimension.box_height, sf::Vector2f(0, 0)); } void LevelView::updateImage() { background_image->update(); + box_image->update(); + target_overlay_image->update(); + letter_one_overlay_image->update(); + letter_two_overlay_image->update(); + letter_three_overlay_image->update(); + obstacle_one_overlay_image->update(); + obstacle_two_overlay_image->update(); } void LevelView::drawImage() { background_image->render(); + drawBox(sf::Vector2f(0, 0)); + BlockType blockTypeToDraw = level_controller->getCurrentBoxValue(0); + drawBoxValue(sf::Vector2f(0, 0), blockTypeToDraw); + } void LevelView::deleteImage() { delete(background_image); + delete(box_image); + delete(target_overlay_image); + delete(letter_one_overlay_image); + delete(letter_two_overlay_image); + delete(letter_three_overlay_image); + delete(obstacle_one_overlay_image); + delete(obstacle_two_overlay_image); } } \ No newline at end of file From 81801486b8cc79fd6a5dc05bdd495c6c3f74af74 Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:10:26 -0400 Subject: [PATCH 6/8] Draw all boxes using Arrays --- Array-Jumper/header/Level/LevelModel.h | 4 +-- Array-Jumper/header/Level/LevelView.h | 3 ++ Array-Jumper/source/Level/LevelView.cpp | 45 +++++++++++++++++++++---- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Array-Jumper/header/Level/LevelModel.h b/Array-Jumper/header/Level/LevelModel.h index 393a3b97..512e8aaf 100644 --- a/Array-Jumper/header/Level/LevelModel.h +++ b/Array-Jumper/header/Level/LevelModel.h @@ -4,8 +4,8 @@ namespace Level { struct BoxDimension { - float box_width = 300.f; - float box_height = 300.f; + float box_width; + float box_height; float box_spacing; diff --git a/Array-Jumper/header/Level/LevelView.h b/Array-Jumper/header/Level/LevelView.h index 3a9f3532..03aa3fb6 100644 --- a/Array-Jumper/header/Level/LevelView.h +++ b/Array-Jumper/header/Level/LevelView.h @@ -14,7 +14,10 @@ namespace Level void update(); void render(); + void calculateBoxWidthHeightDimension(); + void calculateBoxSpacing(); void calcuateBoxDimension(); + sf::Vector2f calculateBoxPosition(int index); UI::UIElement::ImageView* getBoxImage(BlockType type); void drawBox(sf::Vector2f position); diff --git a/Array-Jumper/source/Level/LevelView.cpp b/Array-Jumper/source/Level/LevelView.cpp index 5ac6c5aa..393a6a96 100644 --- a/Array-Jumper/source/Level/LevelView.cpp +++ b/Array-Jumper/source/Level/LevelView.cpp @@ -2,6 +2,7 @@ #include "../../header/Level/LevelController.h" #include "../../header/Global/Config.h" #include "../../header/Global/ServiceLocator.h" +#include namespace Level { using namespace Global; @@ -20,6 +21,7 @@ namespace Level void LevelView::initilaize() { game_window = ServiceLocator::getInstance()->getGraphicService()->getGameWindow(); + calcuateBoxDimension(); initilizeImage(); } void LevelView::update() @@ -30,12 +32,38 @@ namespace Level { drawImage(); } + void LevelView::calculateBoxWidthHeightDimension() + { + float screenWidth = static_cast(game_window->getSize().x); + int numBoxes = LevelData::number_of_box; + + //Each Box has a Gap on it's left, 1 extra gap for last block's right side + int numGaps = numBoxes + 1; + + //Total space consumed by all gaps + float totalSpaceByGaps = box_dimension.box_spacing_percentage * static_cast(numGaps); + + //Total space consumed by boxes and gaps + float totalSpace = numBoxes + totalSpaceByGaps; + + box_dimension.box_width = screenWidth / (totalSpace); + box_dimension.box_height = box_dimension.box_width; + } + void LevelView::calculateBoxSpacing() + { + box_dimension.box_spacing = box_dimension.box_spacing_percentage * box_dimension.box_width; + } void LevelView::calcuateBoxDimension() { if (!game_window) return; - - box_dimension.box_width = 300.f; - box_dimension.box_height = 300.f; + calculateBoxWidthHeightDimension(); + calculateBoxSpacing(); + } + sf::Vector2f LevelView::calculateBoxPosition(int index) + { + float xPosition = box_dimension.box_spacing + static_cast(index) * (box_dimension.box_width + box_dimension.box_spacing); + float yPosition = static_cast(game_window->getSize().y) - box_dimension.box_height - box_dimension.bottom_offset; + return sf::Vector2f(xPosition, yPosition); } ImageView* LevelView::getBoxImage(BlockType type) { @@ -112,9 +140,14 @@ namespace Level void LevelView::drawImage() { background_image->render(); - drawBox(sf::Vector2f(0, 0)); - BlockType blockTypeToDraw = level_controller->getCurrentBoxValue(0); - drawBoxValue(sf::Vector2f(0, 0), blockTypeToDraw); + + for (int i = 0; i < LevelData::number_of_box; i++) + { + sf::Vector2f positon = calculateBoxPosition(i); + BlockType blockTypeToDraw = level_controller->getCurrentBoxValue(i); + drawBox(positon); + drawBoxValue(positon, blockTypeToDraw); + } } void LevelView::deleteImage() From 779165f75c7bd945acc27c85db436c12734a1ab1 Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Mon, 4 Nov 2024 22:04:55 -0500 Subject: [PATCH 7/8] Draw player on box --- Array-Jumper/header/Level/LevelController.h | 2 ++ Array-Jumper/header/Level/LevelService.h | 3 +++ Array-Jumper/header/Level/LevelView.h | 2 ++ Array-Jumper/header/Player/PlayerView.h | 5 +++-- Array-Jumper/source/Global/ServiceLocator.cpp | 6 +++--- Array-Jumper/source/Level/LevelController.cpp | 5 ++++- Array-Jumper/source/Level/LevelService.cpp | 5 +++++ Array-Jumper/source/Level/LevelView.cpp | 4 ++++ Array-Jumper/source/Player/PlayerView.cpp | 12 +++++++++--- 9 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Array-Jumper/header/Level/LevelController.h b/Array-Jumper/header/Level/LevelController.h index 54ce9d23..c6b953a3 100644 --- a/Array-Jumper/header/Level/LevelController.h +++ b/Array-Jumper/header/Level/LevelController.h @@ -1,5 +1,6 @@ #pragma once #include "BlockType.h" +#include "../../header/Level/LevelModel.h" namespace Level { class LevelModel; @@ -15,6 +16,7 @@ namespace Level void render(); BlockType getCurrentBoxValue(int currentPosion); + BoxDimension getBoxDimension(); private: LevelModel* level_model; diff --git a/Array-Jumper/header/Level/LevelService.h b/Array-Jumper/header/Level/LevelService.h index 319b8fbe..c3607a90 100644 --- a/Array-Jumper/header/Level/LevelService.h +++ b/Array-Jumper/header/Level/LevelService.h @@ -1,6 +1,7 @@ #pragma once namespace Level { + struct BoxDimension; class LevelController; class LevelService { @@ -12,6 +13,8 @@ namespace Level void update(); void render(); + BoxDimension getBoxDimension(); + private: LevelController* level_controller; }; diff --git a/Array-Jumper/header/Level/LevelView.h b/Array-Jumper/header/Level/LevelView.h index 03aa3fb6..d2149b2f 100644 --- a/Array-Jumper/header/Level/LevelView.h +++ b/Array-Jumper/header/Level/LevelView.h @@ -23,6 +23,8 @@ namespace Level void drawBox(sf::Vector2f position); void drawBoxValue(sf::Vector2f position, BlockType type); + BoxDimension getBoxDimension(); + private: diff --git a/Array-Jumper/header/Player/PlayerView.h b/Array-Jumper/header/Player/PlayerView.h index 5b55b3ef..ba9077a3 100644 --- a/Array-Jumper/header/Player/PlayerView.h +++ b/Array-Jumper/header/Player/PlayerView.h @@ -1,8 +1,10 @@ #pragma once #include "../../header/UI/UIElement/ImageView.h" +#include "../../header/Level/LevelModel.h" namespace Player { + using namespace Level; class PlayerController; class PlayerView { @@ -14,6 +16,7 @@ namespace Player void update(); void render(); + BoxDimension current_box_dimensions; private: UI::UIElement::ImageView* player_image; @@ -33,6 +36,4 @@ namespace Player sf::Vector2f calculatePlayerPosition(); }; - - } \ No newline at end of file diff --git a/Array-Jumper/source/Global/ServiceLocator.cpp b/Array-Jumper/source/Global/ServiceLocator.cpp index 9f1e2f57..0ff20b89 100644 --- a/Array-Jumper/source/Global/ServiceLocator.cpp +++ b/Array-Jumper/source/Global/ServiceLocator.cpp @@ -43,7 +43,7 @@ namespace Global sound_service->initialize(); ui_service->initialize(); level_service->initialize(); - //player_service->initialize(); + player_service->initialize(); } void ServiceLocator::update() @@ -54,7 +54,7 @@ namespace Global if (GameService::getGameState() == GameState::GAMEPLAY) { level_service->update(); - //player_service->update(); + player_service->update(); } } @@ -66,7 +66,7 @@ namespace Global if (GameService::getGameState() == GameState::GAMEPLAY) { level_service->render(); - //player_service->render(); + player_service->render(); } } diff --git a/Array-Jumper/source/Level/LevelController.cpp b/Array-Jumper/source/Level/LevelController.cpp index effd5ed7..0d8a54e5 100644 --- a/Array-Jumper/source/Level/LevelController.cpp +++ b/Array-Jumper/source/Level/LevelController.cpp @@ -1,5 +1,4 @@ #include "../../header/Level/LevelController.h" -#include "../../header/Level/LevelModel.h" #include "../../header/Level/LevelView.h" namespace Level { @@ -30,4 +29,8 @@ namespace Level { return level_model->getCurrentBoxValue(currentPosion); } + BoxDimension LevelController::getBoxDimension() + { + return level_view->getBoxDimension(); + } } \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelService.cpp b/Array-Jumper/source/Level/LevelService.cpp index 9dfada3c..b40208e7 100644 --- a/Array-Jumper/source/Level/LevelService.cpp +++ b/Array-Jumper/source/Level/LevelService.cpp @@ -1,5 +1,6 @@ #include "../../header/Level/LevelService.h" #include "../../header/Level/LevelController.h" +#include "../../header/Level/LevelModel.h" namespace Level { Level::LevelService::LevelService() @@ -22,4 +23,8 @@ namespace Level { level_controller->render(); } + BoxDimension LevelService::getBoxDimension() + { + return level_controller->getBoxDimension(); + } } \ No newline at end of file diff --git a/Array-Jumper/source/Level/LevelView.cpp b/Array-Jumper/source/Level/LevelView.cpp index 393a6a96..19f116a0 100644 --- a/Array-Jumper/source/Level/LevelView.cpp +++ b/Array-Jumper/source/Level/LevelView.cpp @@ -100,6 +100,10 @@ namespace Level image->setPosition(position); image->render(); } + BoxDimension LevelView::getBoxDimension() + { + return box_dimension; + } void LevelView::createImage() { background_image = new ImageView(); diff --git a/Array-Jumper/source/Player/PlayerView.cpp b/Array-Jumper/source/Player/PlayerView.cpp index 70e6acea..7d863e5a 100644 --- a/Array-Jumper/source/Player/PlayerView.cpp +++ b/Array-Jumper/source/Player/PlayerView.cpp @@ -3,6 +3,8 @@ #include "../../header/Global/ServiceLocator.h" #include "../../header/Player/PlayerController.h" #include "../../header/Player/PlayerModel.h" +#include "../../header/Level/LevelModel.h" + namespace Player { using namespace Global; @@ -35,6 +37,7 @@ namespace Player break; } } + void PlayerView::initializePlayerImage() { player_image->initialize(Config::character_texture_path, player_width, player_height, sf::Vector2f(0, 0)); @@ -50,8 +53,9 @@ namespace Player } void PlayerView::calculatePlayerDimension() { - player_width = 1000.f; - player_height = 1000.f; + current_box_dimensions = ServiceLocator::getInstance()->getLevelService()->getBoxDimension(); + player_width = current_box_dimensions.box_width; + player_height = current_box_dimensions.box_height; } void PlayerView::updatePlayerPosition() { @@ -59,6 +63,8 @@ namespace Player } sf::Vector2f PlayerView::calculatePlayerPosition() { - return sf::Vector2f(0,0); + float xPosition = (current_box_dimensions.box_width + current_box_dimensions.box_spacing); + float yPosition = static_cast(game_window->getSize().y) - current_box_dimensions.box_height - current_box_dimensions.bottom_offset - player_height; + return sf::Vector2f(xPosition, yPosition); } } \ No newline at end of file From c0a4e5b41da58b31656563e6acbbcc76b59a78aa Mon Sep 17 00:00:00 2001 From: Akashkapoor <150754201+akashkapoordev@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:57:51 -0500 Subject: [PATCH 8/8] Fixed some bugs --- Array-Jumper/header/Player/PlayerController.h | 1 + Array-Jumper/header/Player/PlayerView.h | 1 + Array-Jumper/source/Player/PlayerController.cpp | 6 ++++++ Array-Jumper/source/Player/PlayerView.cpp | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Array-Jumper/header/Player/PlayerController.h b/Array-Jumper/header/Player/PlayerController.h index ad0e03bc..6fd5c87f 100644 --- a/Array-Jumper/header/Player/PlayerController.h +++ b/Array-Jumper/header/Player/PlayerController.h @@ -17,6 +17,7 @@ namespace Player PlayerState getPlayerState(); void setPlayerState(PlayerState state); + int getCurrentPosition(); private: PlayerModel* player_model; diff --git a/Array-Jumper/header/Player/PlayerView.h b/Array-Jumper/header/Player/PlayerView.h index ba9077a3..5017f487 100644 --- a/Array-Jumper/header/Player/PlayerView.h +++ b/Array-Jumper/header/Player/PlayerView.h @@ -17,6 +17,7 @@ namespace Player void render(); BoxDimension current_box_dimensions; + private: UI::UIElement::ImageView* player_image; diff --git a/Array-Jumper/source/Player/PlayerController.cpp b/Array-Jumper/source/Player/PlayerController.cpp index 7681c4d8..5482ede3 100644 --- a/Array-Jumper/source/Player/PlayerController.cpp +++ b/Array-Jumper/source/Player/PlayerController.cpp @@ -36,4 +36,10 @@ namespace Player { player_model->setPlayerState(state); } + int PlayerController::getCurrentPosition() + { + return player_model->getPosition(); + } + + } \ No newline at end of file diff --git a/Array-Jumper/source/Player/PlayerView.cpp b/Array-Jumper/source/Player/PlayerView.cpp index 7d863e5a..b1e4dec0 100644 --- a/Array-Jumper/source/Player/PlayerView.cpp +++ b/Array-Jumper/source/Player/PlayerView.cpp @@ -63,7 +63,7 @@ namespace Player } sf::Vector2f PlayerView::calculatePlayerPosition() { - float xPosition = (current_box_dimensions.box_width + current_box_dimensions.box_spacing); + float xPosition = current_box_dimensions.box_spacing + static_cast(player_controller->getCurrentPosition ()) * (current_box_dimensions.box_width + current_box_dimensions.box_spacing); float yPosition = static_cast(game_window->getSize().y) - current_box_dimensions.box_height - current_box_dimensions.bottom_offset - player_height; return sf::Vector2f(xPosition, yPosition); }