Skip to content

Commit

Permalink
need to attack
Browse files Browse the repository at this point in the history
  • Loading branch information
onon1101 committed Apr 26, 2024
1 parent fbca6d4 commit 588f258
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 7 deletions.
7 changes: 7 additions & 0 deletions include/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#include "Game/System.h"
#include "Game/Actions.h"

#include "Util/Keycode.hpp"


class App {
public:
enum class State {
Expand All @@ -38,6 +42,7 @@ class App {
std::shared_ptr<Background> m_Background;
bool m_FirstTime = true;
bool m_IsMainMenu = true;
bool m_ThrowMode = false;

// music
std::shared_ptr<Music::Player> m_MusicSystem =
Expand All @@ -60,6 +65,8 @@ class App {
std::shared_ptr<Dungeon::Map> m_DungeonMap;
std::size_t m_BeforeTempoIndex = 0;
std::size_t m_TempoIndex = 0;

static std::map<Util::Keycode, Player::Direction> m_MapTableCodeDire;
};

#endif
26 changes: 23 additions & 3 deletions include/Game/Actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<glm::ivec2>(playerGP);

while (true) {
if (dungeonMap->GetMapData()->IsPositionWall(weaponNextPos + direMI)) {
break;
}

// DOTO:
weaponNextPos += direMI;
}

weaponEndMI = Settings::Helper::GamePosToMapIdx(weaponNextPos);

const auto image = std::make_shared<Util::Image>(Config::IMAGE_DAGGER_PATH);
const auto object = std::make_shared<Graphs::DaggerGameObj>();
object->SetDrawable(image);

System::AddWeapon(object, playerMI);
System::AddWeapon(object, weaponEndMI);
};
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/Game/Graphs/Dagger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/Game/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class System final {
public:
static void Init(Dungeon::Map *dungeonMap);

static void AddWeapon(std::shared_ptr<Game::Graphs::IBase> baseType, const std::size_t posposMI);
static void AddWeapon(std::shared_ptr<Game::Graphs::IBase> baseType, const std::size_t posMI);

static std::shared_ptr<Util::GameObject> GetGameObject();

Expand Down
12 changes: 12 additions & 0 deletions include/Settings/Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <glm/vec2.hpp>

#include "Dungeon/Map.h"
#include <exception>

namespace Settings {
class Helper {
Expand All @@ -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;
};
Expand Down
40 changes: 38 additions & 2 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -265,3 +293,11 @@ void App::Update() {
void App::End() { // NOLINT(this method will mutate members in the future)
LOG_TRACE("End");
}


std::map<Util::Keycode, Player::Direction> 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},
};

0 comments on commit 588f258

Please sign in to comment.