diff --git a/include/App.hpp b/include/App.hpp index 92d54f63..23a603fd 100644 --- a/include/App.hpp +++ b/include/App.hpp @@ -12,6 +12,10 @@ #include "Game/System.h" #include "Game/Actions.h" + +#include "Util/Keycode.hpp" + + class App { public: enum class State { @@ -38,6 +42,7 @@ class App { std::shared_ptr m_Background; bool m_FirstTime = true; bool m_IsMainMenu = true; + bool m_ThrowMode = false; // music std::shared_ptr m_MusicSystem = @@ -60,6 +65,8 @@ class App { std::shared_ptr m_DungeonMap; std::size_t m_BeforeTempoIndex = 0; std::size_t m_TempoIndex = 0; + + static std::map m_MapTableCodeDire; }; #endif diff --git a/include/Game/Actions.h b/include/Game/Actions.h index c549e1a5..8591b2af 100644 --- a/include/Game/Actions.h +++ b/include/Game/Actions.h @@ -16,14 +16,34 @@ namespace Game { class Actions { public: - static void ThrowOutWeapon() { - auto [playerGP, playerMI] = Settings::Helper::GetPlayerPosDM(); + static void ThrowOutWeapon(Dungeon::Map *dungeonMap, const Player::Direction direction) { + LOG_INFO("Throw out."); + + // get current player pos + const auto [playerGP, playerMI] = Settings::Helper::GetPlayerPosDM(); + + // translate direction + const auto direMI = Settings::Helper::Direct2MI(direction); + + std::size_t weaponEndMI = 0; + auto weaponNextPos = static_cast(playerGP); + + while (true) { + if (dungeonMap->GetMapData()->IsPositionWall(weaponNextPos + direMI)) { + break; + } + + // DOTO: + weaponNextPos += direMI; + } + + weaponEndMI = Settings::Helper::GamePosToMapIdx(weaponNextPos); const auto image = std::make_shared(Config::IMAGE_DAGGER_PATH); const auto object = std::make_shared(); object->SetDrawable(image); - System::AddWeapon(object, playerMI); + System::AddWeapon(object, weaponEndMI); }; }; } diff --git a/include/Game/Graphs/Dagger.h b/include/Game/Graphs/Dagger.h index 54f44b79..a048893f 100644 --- a/include/Game/Graphs/Dagger.h +++ b/include/Game/Graphs/Dagger.h @@ -16,7 +16,7 @@ class DaggerGameObj final : public Game::Graphs::IBase { ~DaggerGameObj() override = default; void Update() override { - LOG_INFO("This is Dagger weapon"); +// LOG_INFO("This is Dagger weapon"); }; }; } // namespace Graphs diff --git a/include/Game/System.h b/include/Game/System.h index 92bba78a..32804140 100644 --- a/include/Game/System.h +++ b/include/Game/System.h @@ -12,7 +12,7 @@ class System final { public: static void Init(Dungeon::Map *dungeonMap); - static void AddWeapon(std::shared_ptr baseType, const std::size_t posposMI); + static void AddWeapon(std::shared_ptr baseType, const std::size_t posMI); static std::shared_ptr GetGameObject(); diff --git a/include/Settings/Helper.hpp b/include/Settings/Helper.hpp index 5d26682e..a671f615 100644 --- a/include/Settings/Helper.hpp +++ b/include/Settings/Helper.hpp @@ -11,6 +11,7 @@ #include #include "Dungeon/Map.h" +#include namespace Settings { class Helper { @@ -37,6 +38,17 @@ class Helper { playerPos, mapIdx }; }; + + inline static glm::ivec2 Direct2MI(Player::Direction direction) { + switch (direction) { + case Player::Direction::UP: return {0, -1}; + case Player::Direction::LEFT: return {-1, 0}; + case Player::Direction::DOWN: return {0, 1}; + case Player::Direction::RIGHT: return {1,0}; + case Player::Direction::NONE: throw std::runtime_error("direction can not be none"); + } + } + private: static Dungeon::Map* m_DungeonMap; }; diff --git a/src/App.cpp b/src/App.cpp index 6f4ca94b..26d8b3eb 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -99,9 +99,12 @@ void App::Update() { m_DungeonMap->TempoTrigger(tempoIndex); } + + + if (Util::Input::IsKeyDown(Util::Keycode::N)) { // Game::Throw::ThrowOut(m_DungeonMap.get()); - Game::Actions::ThrowOutWeapon(); +// Game::Actions::ThrowOutWeapon(); // m_DungeonMap->LoadLevel(m_DungeonMap->GetLevelNum() + 1); // m_AniCameraDestination = {0, 0}; @@ -144,8 +147,29 @@ void App::Update() { // } } + if (Util::Input::IsKeyDown(Util::Keycode::UP) && Util::Input::IsKeyDown(Util::Keycode::DOWN)) { + LOG_INFO("Throw Mode"); + m_ThrowMode = true; + } + + + + // player throw weapon + if (m_ThrowMode && (Util::Input::IsKeyDown(Util::Keycode::W) + || Util::Input::IsKeyDown(Util::Keycode::D) + || Util::Input::IsKeyDown(Util::Keycode::S) + || Util::Input::IsKeyDown(Util::Keycode::A)) + && m_MusicSystem->TempoTrigger()) { + for (const auto& elem: m_MapTableCodeDire) { + if (Util::Input::IsKeyDown(elem.first)) { + Game::Actions::ThrowOutWeapon(m_DungeonMap.get(), elem.second); + } + } + m_ThrowMode = false; + } + // player move - if ((Util::Input::IsKeyDown(Util::Keycode::W) + else if (!m_ThrowMode && (Util::Input::IsKeyDown(Util::Keycode::W) || Util::Input::IsKeyDown(Util::Keycode::D) || Util::Input::IsKeyDown(Util::Keycode::S) || Util::Input::IsKeyDown(Util::Keycode::A)) @@ -187,6 +211,10 @@ void App::Update() { && m_DungeonMap->GetMapData()->IsPositionPlayerAct( m_MainCharacter->GetGamePosition() + direction[i] )) { + + + + // origin mapdata actions playerDestination = m_MainCharacter->GetGamePosition() + direction[i]; m_MainCharacter->SetFaceTo(playerDirection[i]); @@ -265,3 +293,11 @@ void App::Update() { void App::End() { // NOLINT(this method will mutate members in the future) LOG_TRACE("End"); } + + +std::map App::m_MapTableCodeDire = { + {Util::Keycode::W, Player::Direction::UP}, + {Util::Keycode::D, Player::Direction::RIGHT}, + {Util::Keycode::S, Player::Direction::DOWN}, + {Util::Keycode::A, Player::Direction::LEFT}, +}; \ No newline at end of file