/* * Hoe.cpp * * Created on: Dec 2, 2016 * Author: tibi */ #include #include #include #include #include #include #include using namespace farmlands::assets; namespace farmlands { namespace components { namespace items { Hoe::Hoe() : m_back(nullptr) { } Hoe::~Hoe() { } model::Component* Hoe::clone() { return new Hoe(); } void Hoe::dump(unsigned level) { for (unsigned i = 0; i < level; i++) std::cout<<" "; std::cout << " .Component: Hoe\n"; } 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 */ } /* namespace components */ } /* namespace farmlands */