Skip to content

Commit

Permalink
press t can delete weapon
Browse files Browse the repository at this point in the history
  • Loading branch information
onon1101 committed May 2, 2024
1 parent 2ce0d55 commit 954bfe8
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 29 deletions.
Binary file added assets/items/weapon_bow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/items/weapon_spear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion include/Game/Player_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static constexpr std::string_view IMAGE_SLOT_BOMB = ASSETS_DIR
static constexpr std::string_view IMAGE_SLOT_SHOVEL = ASSETS_DIR
"/gui/hud_slot_1.png";

static constexpr std::string_view IMAGE_SLOT_DAGGER = ASSETS_DIR
static constexpr std::string_view IMAGE_SLOT_ATTACK = ASSETS_DIR
"/gui/hud_slot_2.png";

static constexpr std::string_view IMAGE_SLOT_THROW = ASSETS_DIR
Expand All @@ -36,6 +36,12 @@ static constexpr std::string_view IMAGE_BOMB = ASSETS_DIR "/items/bomb.png";
static constexpr std::string_view IMAGE_DAGGER = ASSETS_DIR
"/items/weapon_dagger.png";

static constexpr std::string_view IMAGE_SPEAR = ASSETS_DIR
"/items/weapon_spear.png";

static constexpr std::string_view IMAGE_BOW = ASSETS_DIR
"/items/weapon_bow.png";

static constexpr std::string_view STY_FONT = ASSETS_DIR
"/font/necrosans-6/necrosans-6.otf";

Expand Down
36 changes: 36 additions & 0 deletions include/Game/Warehouse/Spear.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Created by adven on 2024/5/2.
//

#ifndef FUCK_PTSD_SPEAR_H
#define FUCK_PTSD_SPEAR_H
#include "Game/Warehouse/IEquip.h"

class Spear : public IEquip {
public:
explicit Spear();
~Spear() = default;

void SetPosition(const glm::vec2& Position) override;

[[nodiscard]]
Pos GetWinPos() const override {
return Pos::ROW;
}

[[nodiscard]]
std::string GetName() const override {
return "WEAPON";
};

[[nodiscard]]
std::string GetType() const override {
return "Spear";
}

private:
void GenSlot();
void GenItem();
};

#endif // FUCK_PTSD_SPEAR_H
2 changes: 1 addition & 1 deletion include/Game/Warehouse/Throw.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Throw : public IEquip {

[[nodiscard]]
std::string GetType() const override {
return "Throw";
return "Spear";
}

private:
Expand Down
22 changes: 14 additions & 8 deletions include/Game/Warehouse/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ class Tools final {
public:
Tools();

void AddTool(const std::shared_ptr<IEquip>& ge);
void AddTool(
const std::shared_ptr<IEquip>& ge,
const std::string& name,
const std::string& type
);

void RemoveTool(const std::string& name, const std::string& type);

std::string Print() { return "test"; }

Expand All @@ -36,9 +42,11 @@ class Tools final {
private:
void ReArrange();

const std::map<std::string, std::string> m_BaseTool =
{{"BOMB", "1"}, {"SHOVEL", "Shovel"}, {"WEAPON", "Dagger"}};

std::map<std::string, std::string> m_BaseTool = {
{"BOMB", "1"},
{"SHOVEL", "Shovel"},
// {"WEAPON", "Dagger"}};
{"WEAPON", "Spear"}};
std::shared_ptr<Util::GameElement> m_GameElement;

std::vector<std::shared_ptr<IEquip>> m_ToolList;
Expand All @@ -48,13 +56,11 @@ class Tools final {
private:
static constexpr glm::vec2 m_ColInitPos = {
static_cast<int>(-WINDOW_WIDTH) / 2 + 65,
static_cast<int>(WINDOW_HEIGHT) / 2 - 195
};
static_cast<int>(WINDOW_HEIGHT) / 2 - 195};

static constexpr glm::vec2 m_RowInitPos = {
static_cast<int>(-WINDOW_WIDTH) / 2 + 65,
static_cast<int>(WINDOW_HEIGHT) / 2 - 55
};
static_cast<int>(WINDOW_HEIGHT) / 2 - 55};
};

} // namespace Players
Expand Down
12 changes: 2 additions & 10 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,8 @@ void App::Update() {
Display::BeatHeart::SwitchHeart(100);
}


if (Util::Input::IsKeyDown(Util::Keycode::T)) {
Game::Systems::HPIS::ThrowOut(Player::Direction::NONE);
// const auto& m = m_MainCharacter->GetGamePosition();
// const auto&& b = Settings::Helper::GamePosToMapIdx(m + glm::vec2{1, 0});
// if (m_DungeonMap->GetMapData()->IsHasEntity(b)) {
// LOG_INFO(m_DungeonMap->GetMapData()->GetEnemy(b)->GetHealth());
// }
m_MainCharacter->GetToolMod()->RemoveTool("WEAPON", "Spear");
}

if (Util::Input::IsKeyDown(Util::Keycode::N)) {
Expand Down Expand Up @@ -287,6 +281,4 @@ void App::End() { // NOLINT(this method will mutate members in the future)
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},
};
{Util::Keycode::S, Player::Direction::DOWN}};
21 changes: 16 additions & 5 deletions src/Game/Systems/HEIS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Created by adven on 2024/5/1.
//
#include "HEIS.h"
#include "Game_config.h"
#include "Graphs/Dagger.h"
#include "Helper.hpp"

auto Game::Systems::HEIS::Init(Dungeon::Map* dungeon) -> void {
Expand All @@ -24,6 +26,7 @@ auto Game::Systems::HEIS::MakeTile(

auto&& currGP = static_cast<glm::ivec2>(playerGP);

// is wall
while (true) {
mi = Settings::Helper::GamePosToMapIdx(currGP);

Expand All @@ -38,11 +41,19 @@ auto Game::Systems::HEIS::MakeTile(
}
}

const auto dropFloor = []() {

};

dropFloor();
const auto pixelSize =
ToolBoxs::CountImagePixel(Game::Config::IMAGE_DAGGER_PATH, 1, 2);
const auto image = std::make_shared<SpriteSheet>(
Config::IMAGE_DAGGER_PATH,
pixelSize,
std::vector<std::size_t>{0, 1},
false,
100,
false,
100
);
const auto object = std::make_shared<Graphs::DaggerGameObj>();
object->SetDrawable(image);
}

Dungeon::Map* Game::Systems::HEIS::m_Map = nullptr;
7 changes: 5 additions & 2 deletions src/Game/Systems/HPIS.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "HPIS.h"
#include "ISC.h"
#include "Player.h"
#include "Player_config.h"
#include "Settings/Helper.hpp"
#include "Signal.h"

Expand All @@ -24,9 +25,11 @@ void Game::Systems::HPIS::Init(Player* player) {

void Game::Systems::HPIS::IsExistWeaponThrow() {
const auto& _throw = std::make_shared<Game::Warehouse::Throw>(
Config::IMAGE_DAGGER_PATH
// Config::IMAGE_DAGGER_PATH
Players::Config::IMAGE_SPEAR.data()
);
m_Players->GetToolMod()->AddTool(_throw);
// m_Players->GetToolMod()->AddTool(_throw, "Throw", "Dagger");
m_Players->GetToolMod()->AddTool(_throw, "THROW", "Spear");
}

void Game::Systems::HPIS::ThrowOut(const Player::Direction direction) {
Expand Down
2 changes: 1 addition & 1 deletion src/Player/Factory/Dagger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Dagger::GenItem() {
void Dagger::GenSlot() {
const auto& obj = std::make_shared<Util::GameElement>();
const auto& slot = std::make_shared<Util::SpriteSheet>(
Players::Config::IMAGE_SLOT_DAGGER.data()
Players::Config::IMAGE_SLOT_ATTACK.data()
);

slot->SetDrawRect(SDL_Rect{0, 0, 30, 33});
Expand Down
62 changes: 62 additions & 0 deletions src/Player/Factory/Spear.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Created by adven on 2024/5/2.
//

#include "Game/Warehouse/Spear.h"
#include "Player_config.h"
#include "Settings/Helper.hpp"

Spear::Spear() {
GenItem();
GenSlot();

SetVisible(false);
}

void Spear::SetPosition(const glm::vec2& Position) {
m_Transform.translation = Position;

const auto& list = GetChildren();
list[0]->m_Transform.translation = Position + glm::vec2{0, -5};
list[1]->m_Transform.translation = Position + glm::vec2{0, 0.4};
}

void Spear::GenItem() {
const auto& obj = std::make_shared<Util::GameElement>();
const auto& size = Settings::Helper::CountImgPixel(
Players::Config::IMAGE_SPEAR.data(),
1,
2
);
const auto& item = std::make_shared<SpriteSheet>(
Players::Config::IMAGE_SPEAR.data(),
size,
std::vector<std::size_t>{0},
false,
100,
true,
100
);

obj->SetDrawable(item);
obj->SetZIndex(Players::Config::VAL_ZINDEX);
obj->SetScale(Players::Config::VAL_SCALE);
obj->SetPosition(Players::Config::VAL_INITPOS);

AddChild(obj);
}

void Spear::GenSlot() {
const auto& obj = std::make_shared<Util::GameElement>();
const auto& slot = std::make_shared<Util::SpriteSheet>(
Players::Config::IMAGE_SLOT_ATTACK.data()
);

slot->SetDrawRect(SDL_Rect{0, 0, 30, 33});
obj->SetDrawable(slot);
obj->SetZIndex(Players::Config::VAL_ZINDEX);
obj->SetPosition(Players::Config::VAL_INITPOS);
obj->SetScale(Players::Config::VAL_SCALE);

AddChild(obj);
}
52 changes: 51 additions & 1 deletion src/Player/Items/Tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,57 @@ Players::Tools::Tools() {
ReArrange();
};

void Players::Tools::AddTool(const std::shared_ptr<IEquip>& ge) {
void Players::Tools::RemoveTool(
const std::string& name,
const std::string& type
) {
const auto& it = m_BaseTool.find(name);
if (m_BaseTool.end() == it) {
throw std::runtime_error("Remove Tool Error");
}
m_BaseTool.erase(it);

auto removeElem = [&](std::size_t i, std::size_t offset) {
const auto& elem = m_ToolList[i];
m_ToolList.erase(m_ToolList.begin() + i - offset);

m_GameElement->RemoveChild(elem);
};

std::vector<std::size_t> removeList = {};

for (std::size_t i = 0; i < m_ToolList.size(); i++) {
auto test = m_ToolList[i]->GetName();
auto test0 = m_ToolList[i]->GetType();
if (m_ToolList[i]->GetName() == name
&& m_ToolList[i]->GetType() == type) {
removeList.push_back(i);
} else if (m_ToolList[i]->GetName() == "THROW" && m_ToolList[i]->GetType() == type) {
removeList.push_back(i);
}
}

std::size_t count = 0;
std::for_each(
removeList.begin(),
removeList.end(),
[removeElem, &count, this](auto idx) {
const auto& elem = m_ToolList[idx - count];
m_GameElement->RemoveChild(elem);
m_ToolList.erase(m_ToolList.begin() + idx - count);
count++;
}
);

ReArrange();
}

void Players::Tools::AddTool(
const std::shared_ptr<IEquip>& ge,
const std::string& name,
const std::string& type
) {
m_BaseTool.insert({name, type});
m_ToolList.insert(m_ToolList.begin(), ge);
m_GameElement->AddChild(ge);

Expand Down
2 changes: 2 additions & 0 deletions src/Player/Items/ToolFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Game/Warehouse/Bomb.h"
#include "Game/Warehouse/Dagger.h"
#include "Game/Warehouse/Shovel.h"
#include "Game/Warehouse/Spear.h"

std::shared_ptr<IEquip> Players::Items::ToolFactory::MakeTool(
const std::string& name,
Expand Down Expand Up @@ -32,6 +33,7 @@ void Players::Items::ToolFactory::GenShovel(const std::string& type) {
void Players::Items::ToolFactory::GenWeapon(const std::string& type) {
switch (Settings::Hash::HashConvert(type)) {
case "Dagger"_hash: m_Result = std::make_shared<Dagger>(); break;
case "Spear"_hash: m_Result = std::make_shared<Spear>(); break;
default: throw std::runtime_error("Shovel's type is not available");
}
}

0 comments on commit 954bfe8

Please sign in to comment.