Implemented some tools. Also, implemented inventory.
This commit is contained in:
@@ -5,15 +5,23 @@
|
||||
* Author: tibi
|
||||
*/
|
||||
|
||||
#include <GameState.h>
|
||||
#include <assets/Ground.h>
|
||||
#include <components/items/Hoe.h>
|
||||
#include <math/GameMath.h>
|
||||
#include <model/GameObject.h>
|
||||
#include <model/Scene.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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<Background>();
|
||||
Assert(it != root->childrenEnd(), "Can't find background game object.");
|
||||
|
||||
m_back = (*it)->component<Background>();
|
||||
}
|
||||
|
||||
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 */
|
||||
|
Reference in New Issue
Block a user