diff --git a/assets/items/Tools.items b/assets/items/Tools.items index bed8e7a..3e6a0f3 100644 --- a/assets/items/Tools.items +++ b/assets/items/Tools.items @@ -15,6 +15,20 @@ + + + + + + + + + diff --git a/assets/sprites/Player.sprite b/assets/sprites/Player.sprite index 6b17c8a..0d0ee29 100644 --- a/assets/sprites/Player.sprite +++ b/assets/sprites/Player.sprite @@ -1,6 +1,6 @@ + anchorX="0.5" anchorY="0.95"> diff --git a/assets/sprites/items/RustyWateringCan.sprite b/assets/sprites/items/RustyWateringCan.sprite new file mode 100644 index 0000000..4a576cd --- /dev/null +++ b/assets/sprites/items/RustyWateringCan.sprite @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/assets/sprites/items/wateringCan.png b/assets/sprites/items/wateringCan.png new file mode 100644 index 0000000..e9ab965 Binary files /dev/null and b/assets/sprites/items/wateringCan.png differ diff --git a/assets/tilesets/Ground.png b/assets/tilesets/Ground.png index 0dac8fd..8d0b7b1 100644 Binary files a/assets/tilesets/Ground.png and b/assets/tilesets/Ground.png differ diff --git a/src/assets/Ground.h b/src/assets/Ground.h index a8c925e..2efb831 100644 --- a/src/assets/Ground.h +++ b/src/assets/Ground.h @@ -14,26 +14,29 @@ namespace assets { /** * Maps tiles to ground name */ - enum class Ground + enum Ground { - Dirt = 0, - DirtVariation0 = 1, - DirtVariation1 = 2, - DirtVariation2 = 3, - DirtVariation3 = 4, - DirtVariation4 = 5, - DirtVariation5 = 6, - DirtVariation6 = 7, - DirtVariation7 = 8, - DirtVariation8 = 9, + None = 0, + Dirt = 1, + DirtVariation0 = 2, + DirtVariation1 = 3, + DirtVariation2 = 4, + DirtVariation3 = 5, + DirtVariation4 = 6, + DirtVariation5 = 7, + DirtVariation6 = 8, + DirtVariation7 = 9, + DirtVariation8 = 10, - SoilCenter = 30, + SoilDry = 92, - SoilWet = 36 + SoilWet = 98, + + Water = 180, }; inline bool groundIsDirt(int cell) { return cell >= Ground::Dirt && cell <= Ground::DirtVariation8; } - inline bool groundIsDrySoil(int cell) { return cell == Ground::SoilCenter; } + inline bool groundIsDrySoil(int cell) { return cell == Ground::SoilDry; } inline bool groundIsWetSoil(int cell) { return cell == Ground::SoilWet; } } diff --git a/src/components/items/Axe.cpp b/src/components/items/Axe.cpp new file mode 100644 index 0000000..c333375 --- /dev/null +++ b/src/components/items/Axe.cpp @@ -0,0 +1,43 @@ +/* + * Axe.cpp + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#include +#include +#include + +namespace farmlands { +namespace components { +namespace items { + +Axe::Axe() +{ +} + +Axe::~Axe() +{ +} + +model::Component* Axe::clone() +{ + return new Axe(); +} + +void Axe::dump(unsigned level) +{ + for (unsigned i = 0; i < level; i++) + std::cout<<" "; + + std::cout << " .Component: Axe\n"; +} + +void Axe::performAction(float x, float y, model::Direction d) +{ +} + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ diff --git a/src/components/items/Axe.h b/src/components/items/Axe.h new file mode 100644 index 0000000..a8c0f9b --- /dev/null +++ b/src/components/items/Axe.h @@ -0,0 +1,34 @@ +/* + * Axe.h + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#ifndef COMPONENTS_ITEMS_AXE_H_ +#define COMPONENTS_ITEMS_AXE_H_ + +#include +#include + +namespace farmlands { +namespace components { +namespace items { + + class Axe: public model::Component, public ITool + { + public: + Axe(); + virtual ~Axe(); + + virtual model::Component* clone() override; + virtual void dump(unsigned level) override; + + virtual void performAction(float x, float y, model::Direction d) override; + }; + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ + +#endif /* COMPONENTS_ITEMS_AXE_H_ */ diff --git a/src/components/items/Giftable.cpp b/src/components/items/Giftable.cpp index 4fdefaf..e876356 100644 --- a/src/components/items/Giftable.cpp +++ b/src/components/items/Giftable.cpp @@ -26,15 +26,8 @@ model::Component* Giftable::clone() return new Giftable(); } -bool Giftable::canGift(float x, float y, model::Direction d) +void Giftable::performAction(float x, float y, model::Direction d) { - // TODO: implement Giftable::canGift - return false; -} - -void Giftable::offerGift(float x, float y, model::Direction d) -{ - // TODO: implement Giftable::offerGift } void Giftable::dump(unsigned level) diff --git a/src/components/items/Giftable.h b/src/components/items/Giftable.h index 7da2f90..ae101b7 100644 --- a/src/components/items/Giftable.h +++ b/src/components/items/Giftable.h @@ -8,14 +8,14 @@ #ifndef CONTROLLER_ITEMS_GIFTABLE_H_ #define CONTROLLER_ITEMS_GIFTABLE_H_ +#include #include -#include namespace farmlands { namespace components { namespace items { - class Giftable: public model::Component + class Giftable: public model::Component, public ITool { public: Giftable(); @@ -24,8 +24,7 @@ namespace items { virtual model::Component* clone() override; virtual void dump(unsigned level) override; - bool canGift(float x, float y, model::Direction d); - void offerGift(float x, float y, model::Direction d); + virtual void performAction(float x, float y, model::Direction d) override; }; } /* namespace items */ diff --git a/src/components/items/Hoe.cpp b/src/components/items/Hoe.cpp index d524fe3..e76b699 100644 --- a/src/components/items/Hoe.cpp +++ b/src/components/items/Hoe.cpp @@ -5,15 +5,23 @@ * Author: tibi */ +#include +#include #include +#include +#include +#include #include +using namespace farmlands::assets; + namespace farmlands { namespace components { namespace items { Hoe::Hoe() + : m_back(nullptr) { } @@ -34,8 +42,34 @@ void Hoe::dump(unsigned level) std::cout << " .Component: Hoe\n"; } -void Hoe::performAttack(float x, float y, model::Direction d) +void Hoe::onInitialize() { + model::GameObject* root = &GameState::current().scene->root; + + // Find background object + auto it = root->findByComponent(); + Assert(it != root->childrenEnd(), "Can't find background game object."); + + m_back = (*it)->component(); +} + +void Hoe::performAction(float x, float y, model::Direction d) +{ + Assert(m_back, "No background object!!!"); + + // Compute watering position + float digX, digY; + translate(x, y, d, 0.5f, &digX, &digY); + + size_t col = floorf(digX); + size_t row = floorf(digY); + + // See what the cell contains + Cell backCell = m_back->cell(0, row, col); + Cell soilCell = m_back->cell(1, row, col); + + if (groundIsDirt(backCell) && soilCell == Ground::None) + m_back->setCell(1, row, col, Ground::SoilDry); } } /* namespace items */ diff --git a/src/components/items/Hoe.h b/src/components/items/Hoe.h index fc4e3e7..0054766 100644 --- a/src/components/items/Hoe.h +++ b/src/components/items/Hoe.h @@ -8,6 +8,8 @@ #ifndef COMPONENTS_ITEMS_HOE_H_ #define COMPONENTS_ITEMS_HOE_H_ +#include +#include #include #include @@ -15,7 +17,7 @@ namespace farmlands { namespace components { namespace items { - class Hoe: public model::Component + class Hoe: public model::Component, public ITool { public: Hoe(); @@ -24,7 +26,12 @@ namespace items { virtual model::Component* clone() override; virtual void dump(unsigned level) override; - void performAttack(float x, float y, model::Direction d); + virtual void onInitialize() override; + + virtual void performAction(float x, float y, model::Direction d) override; + + private: + Background* m_back; }; } /* namespace items */ diff --git a/src/components/items/ITool.h b/src/components/items/ITool.h new file mode 100644 index 0000000..1510963 --- /dev/null +++ b/src/components/items/ITool.h @@ -0,0 +1,28 @@ +/* + * ITool.h + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#ifndef COMPONENTS_ITEMS_ITOOL_H_ +#define COMPONENTS_ITEMS_ITOOL_H_ + +#include + +namespace farmlands { +namespace components { +namespace items { + + class ITool + { + public: + virtual ~ITool() { } + virtual void performAction(float playerX, float playerY, model::Direction) = 0; + }; + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ + +#endif /* COMPONENTS_ITEMS_ITOOL_H_ */ diff --git a/src/components/items/Pickaxe.cpp b/src/components/items/Pickaxe.cpp new file mode 100644 index 0000000..fec5e25 --- /dev/null +++ b/src/components/items/Pickaxe.cpp @@ -0,0 +1,43 @@ +/* + * Pickaxe.cpp + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#include + +#include + +namespace farmlands { +namespace components { +namespace items { + +Pickaxe::Pickaxe() +{ +} + +Pickaxe::~Pickaxe() +{ +} + +model::Component* Pickaxe::clone() +{ + return new Pickaxe(); +} + +void Pickaxe::dump(unsigned level) +{ + for (unsigned i = 0; i < level; i++) + std::cout<<" "; + + std::cout << " .Component: Pickaxe\n"; +} + +void Pickaxe::performAction(float x, float y, model::Direction d) +{ +} + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ diff --git a/src/components/items/Pickaxe.h b/src/components/items/Pickaxe.h new file mode 100644 index 0000000..aead1fa --- /dev/null +++ b/src/components/items/Pickaxe.h @@ -0,0 +1,34 @@ +/* + * Pickaxe.h + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#ifndef COMPONENTS_ITEMS_PICKAXE_H_ +#define COMPONENTS_ITEMS_PICKAXE_H_ + +#include +#include + +namespace farmlands { +namespace components { +namespace items { + + class Pickaxe: public model::Component, public ITool + { + public: + Pickaxe(); + virtual ~Pickaxe(); + + virtual model::Component* clone() override; + virtual void dump(unsigned level) override; + + virtual void performAction(float x, float y, model::Direction d) override; + }; + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ + +#endif /* COMPONENTS_ITEMS_PICKAXE_H_ */ diff --git a/src/components/items/Scythe.cpp b/src/components/items/Scythe.cpp new file mode 100644 index 0000000..1255591 --- /dev/null +++ b/src/components/items/Scythe.cpp @@ -0,0 +1,43 @@ +/* + * Scythe.cpp + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#include +#include +#include + +namespace farmlands { +namespace components { +namespace items { + +Scythe::Scythe() +{ +} + +Scythe::~Scythe() +{ +} + +model::Component* Scythe::clone() +{ + return new Scythe(); +} + +void Scythe::dump(unsigned level) +{ + for (unsigned i = 0; i < level; i++) + std::cout<<" "; + + std::cout << " .Component: Scythe\n"; +} + +void Scythe::performAction(float x, float y, model::Direction d) +{ +} + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ diff --git a/src/components/items/Scythe.h b/src/components/items/Scythe.h new file mode 100644 index 0000000..c2b1a55 --- /dev/null +++ b/src/components/items/Scythe.h @@ -0,0 +1,34 @@ +/* + * Scythe.h + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#ifndef COMPONENTS_ITEMS_SCYTHE_H_ +#define COMPONENTS_ITEMS_SCYTHE_H_ + +#include +#include + +namespace farmlands { +namespace components { +namespace items { + + class Scythe: public model::Component, public ITool + { + public: + Scythe(); + virtual ~Scythe(); + + virtual model::Component* clone() override; + virtual void dump(unsigned level) override; + + virtual void performAction(float x, float y, model::Direction d) override; + }; + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ + +#endif /* COMPONENTS_ITEMS_SCYTHE_H_ */ diff --git a/src/components/items/WateringCan.cpp b/src/components/items/WateringCan.cpp new file mode 100644 index 0000000..8067974 --- /dev/null +++ b/src/components/items/WateringCan.cpp @@ -0,0 +1,95 @@ +/* + * WateringCan.cpp + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#include +#include +#include +#include +#include + +#include + +using namespace farmlands::assets; + +namespace farmlands { +namespace components { +namespace items { + +WateringCan::WateringCan() + : capacity(10), + amountLeft(10), + m_back(nullptr) +{ +} + +WateringCan::~WateringCan() +{ +} + +model::Component* WateringCan::clone() +{ + WateringCan* clone = new WateringCan(); + clone->capacity = capacity; + clone->amountLeft = amountLeft; + + return clone; +} + +void WateringCan::dump(unsigned level) +{ + for (unsigned i = 0; i < level; i++) + std::cout<<" "; + + std::cout << " .Component: Hoe\n"; +} + +void WateringCan::onInitialize() +{ + model::GameObject* root = &GameState::current().scene->root; + + // Find background object + auto it = root->findByComponent(); + Assert(it != root->childrenEnd(), "Can't find background game object."); + + m_back = (*it)->component(); +} + +void WateringCan::performAction(float x, float y, model::Direction d) +{ + Assert(m_back, "No background object!!!"); + + // Compute watering position + float digX, digY; + translate(x, y, d, 0.5f, &digX, &digY); + + size_t col = floorf(digX); + size_t row = floorf(digY); + + // See what the cell contains + Cell backCell = m_back->cell(0, row, col); + Cell soilCell = m_back->cell(1, row, col); + + // If there is water, fill can + if (backCell == Ground::Water) + { + amountLeft = capacity; + std::cout << "Filled can: " << amountLeft << "\n"; + } + + // If there is dry soil, wet it + if (groundIsDrySoil(soilCell) && amountLeft > 0) + { + m_back->setCell(1, row, col, Ground::SoilWet); + --amountLeft; + + std::cout << "Watering can: " << amountLeft << "\n"; + } +} + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ diff --git a/src/components/items/WateringCan.h b/src/components/items/WateringCan.h new file mode 100644 index 0000000..5c920da --- /dev/null +++ b/src/components/items/WateringCan.h @@ -0,0 +1,45 @@ +/* + * WateringCan.h + * + * Created on: Dec 3, 2016 + * Author: tibi + */ + +#ifndef COMPONENTS_ITEMS_WATERINGCAN_H_ +#define COMPONENTS_ITEMS_WATERINGCAN_H_ + +#include +#include +#include +#include + +namespace farmlands { +namespace components { +namespace items { + + class WateringCan: public model::Component, public ITool + { + public: + WateringCan(); + virtual ~WateringCan(); + + virtual model::Component* clone() override; + virtual void dump(unsigned level) override; + + virtual void onInitialize() override; + + virtual void performAction(float x, float y, model::Direction d) override; + + public: + uint32_t capacity; + uint32_t amountLeft; + + private: + Background* m_back; + }; + +} /* namespace items */ +} /* namespace components */ +} /* namespace farmlands */ + +#endif /* COMPONENTS_ITEMS_WATERINGCAN_H_ */ diff --git a/src/components/items/Weapon.cpp b/src/components/items/Weapon.cpp index 8170d78..de4f76a 100644 --- a/src/components/items/Weapon.cpp +++ b/src/components/items/Weapon.cpp @@ -57,7 +57,7 @@ void Weapon::onUpdateLogic() } } -void Weapon::performAttack(float x, float y, model::Direction d) +void Weapon::performAction(float x, float y, model::Direction d) { if (attackTimeLeft <= 0) { @@ -70,7 +70,7 @@ void Weapon::dump(unsigned level) for (unsigned i = 0; i < level; i++) std::cout<<" "; - std::cout << " .Component: Transform "; + std::cout << " .Component: Weapon "; std::cout << "damage="< +#include #include #include -#include namespace farmlands { namespace components { namespace items { - class Weapon: public model::Component + class Weapon: public model::Component, public ITool { public: Weapon(); @@ -33,7 +33,7 @@ namespace items { /** * Performs everything required to attacking an enemy with a weapon. To be called from player controller. */ - void performAttack(float x, float y, model::Direction d); + virtual void performAction(float x, float y, model::Direction d); // Properties float damage; diff --git a/src/components/player/PlayerController.cpp b/src/components/player/PlayerController.cpp deleted file mode 100644 index 6fac3f0..0000000 --- a/src/components/player/PlayerController.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/* - * PlayerController.cpp - * - * Created on: Nov 27, 2016 - * Author: tibi - */ - -#include -#include -#include -#include -#include -#include -#include -#include