diff --git a/assets/levels/Farm.back b/assets/levels/Farm.back
deleted file mode 100644
index 0afbdf5..0000000
--- a/assets/levels/Farm.back
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/assets/levels/.directory b/assets/maps/.directory
similarity index 100%
rename from assets/levels/.directory
rename to assets/maps/.directory
diff --git a/assets/maps/Farm.map b/assets/maps/Farm.map
new file mode 100644
index 0000000..5e7d694
--- /dev/null
+++ b/assets/maps/Farm.map
@@ -0,0 +1,15 @@
+
+
\ No newline at end of file
diff --git a/assets/levels/Farm_Background.csv b/assets/maps/Farm_Background.csv
similarity index 100%
rename from assets/levels/Farm_Background.csv
rename to assets/maps/Farm_Background.csv
diff --git a/assets/levels/Farm_Soil.csv b/assets/maps/Farm_Soil.csv
similarity index 100%
rename from assets/levels/Farm_Soil.csv
rename to assets/maps/Farm_Soil.csv
diff --git a/assets/plants/Plantable.xml b/assets/plants/Plantable.xml
new file mode 100644
index 0000000..ff4db76
--- /dev/null
+++ b/assets/plants/Plantable.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/assets/plants/Seeds.xml b/assets/plants/Seeds.xml
new file mode 100644
index 0000000..23effae
--- /dev/null
+++ b/assets/plants/Seeds.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/assets/plants/graphics/Ugliceea.png b/assets/plants/graphics/Ugliceea.png
new file mode 100644
index 0000000..10107c0
Binary files /dev/null and b/assets/plants/graphics/Ugliceea.png differ
diff --git a/assets/scenes/Game.scene b/assets/scenes/Game.scene
index 6aa92f4..908e1c2 100644
--- a/assets/scenes/Game.scene
+++ b/assets/scenes/Game.scene
@@ -6,15 +6,17 @@
+
-
-
-
+
+
+
+
diff --git a/assets_original/plant_uglyceea.xcf b/assets_original/plant_uglyceea.xcf
new file mode 100644
index 0000000..2f2241d
Binary files /dev/null and b/assets_original/plant_uglyceea.xcf differ
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 02112b2..3971375 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -11,12 +11,17 @@ namespace farmlands {
GameState GameState::s_current;
GameState::GameState()
- : config(nullptr),
+ : gameInitialized(false),
+ config(nullptr),
renderContext(),
scene(nullptr),
itemPrefabs(),
- elapsedTime(0),
- gameInitialized(false)
+ seedsPrefabs(),
+ plantsPrefabs(),
+ time(0),
+ date(0),
+ isMidnight(false),
+ deltaTime(0)
{
}
@@ -24,6 +29,15 @@ GameState::~GameState()
{
if (scene) delete scene;
if (config) delete config;
+
+ for (auto obj : itemPrefabs)
+ delete obj;
+
+ for (auto obj : seedsPrefabs)
+ delete obj;
+
+ for (auto obj : plantsPrefabs)
+ delete obj;
}
GameState& farmlands::GameState::current()
@@ -31,9 +45,4 @@ GameState& farmlands::GameState::current()
return s_current;
}
-void farmlands::GameState::setCurrent(GameState& state)
-{
- s_current = state;
-}
-
}
diff --git a/src/GameState.h b/src/GameState.h
index d689fba..82d8e29 100644
--- a/src/GameState.h
+++ b/src/GameState.h
@@ -24,7 +24,9 @@ namespace farmlands {
GameState();
~GameState();
static GameState& current();
- static void setCurrent(GameState& state);
+
+ // Initialized?
+ bool gameInitialized;
// Game settings
model::Configuration* config;
@@ -35,10 +37,15 @@ namespace farmlands {
// Scene
model::Scene* scene;
std::vector itemPrefabs;
+ std::vector seedsPrefabs;
+ std::vector plantsPrefabs;
- // Misc
- float elapsedTime;
- bool gameInitialized;
+ // Timing
+ float time;
+ uint32_t date;
+ bool isMidnight;
+
+ float deltaTime;
private:
static GameState s_current;
diff --git a/src/assets/Ground.h b/src/assets/Ground.h
index 2efb831..da74084 100644
--- a/src/assets/Ground.h
+++ b/src/assets/Ground.h
@@ -38,7 +38,7 @@ namespace assets {
inline bool groundIsDirt(int cell) { return cell >= Ground::Dirt && cell <= Ground::DirtVariation8; }
inline bool groundIsDrySoil(int cell) { return cell == Ground::SoilDry; }
inline bool groundIsWetSoil(int cell) { return cell == Ground::SoilWet; }
-
+ inline bool groundIsSoil(int cell) { return cell == Ground::SoilDry || cell == Ground::SoilWet; }
}
}
diff --git a/src/components/DebugController.cpp b/src/components/DebugController.cpp
index 9c30cd1..5313459 100644
--- a/src/components/DebugController.cpp
+++ b/src/components/DebugController.cpp
@@ -48,7 +48,7 @@ void DebugController::onUpdateLogic()
vel = ScaleShiftVelocity;
// Time independent
- vel *= GameState::current().elapsedTime;
+ vel *= GameState::current().deltaTime;
if (Input::instance().pressed(GameKey::Debug_ZoomIn))
m_camera->scale *= 1 + vel;
diff --git a/src/components/GameTime.cpp b/src/components/GameTime.cpp
new file mode 100644
index 0000000..9076071
--- /dev/null
+++ b/src/components/GameTime.cpp
@@ -0,0 +1,55 @@
+/*
+ * GameTime.cpp
+ *
+ * Created on: Dec 9, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+
+#include
+
+// Day length (in seconds)
+//#define DAYLENGTH 24 * 60
+#define DAYLENGTH 10
+
+namespace farmlands {
+namespace components {
+
+GameTime::~GameTime()
+{
+}
+
+model::Component* GameTime::clone()
+{
+ return new GameTime();
+}
+
+void GameTime::dump(unsigned level)
+{
+ for (unsigned i = 0; i < level; i++)
+ std::cout<<" ";
+
+ std::cout << " .Component: GameTime \n";
+}
+
+void GameTime::onUpdateLogic()
+{
+ float delta = GameState::current().deltaTime;
+ GameState::current().time += delta;
+ GameState::current().isMidnight = false;
+
+ if (GameState::current().time > DAYLENGTH)
+ {
+ GameState::current().time -= DAYLENGTH;
+ GameState::current().date++;
+ GameState::current().isMidnight = true;
+
+ std::cout << "It's midnight! Date: " << GameState::current().date << "\n";
+ }
+
+}
+
+} /* namespace components */
+} /* namespace farmlands */
diff --git a/src/components/GameTime.h b/src/components/GameTime.h
new file mode 100644
index 0000000..25bd4f8
--- /dev/null
+++ b/src/components/GameTime.h
@@ -0,0 +1,33 @@
+/*
+ * GameTime.h
+ *
+ * Created on: Dec 9, 2016
+ * Author: tibi
+ */
+
+#ifndef COMPONENTS_GAMETIME_H_
+#define COMPONENTS_GAMETIME_H_
+
+#include
+
+namespace farmlands {
+namespace components {
+
+ /**
+ * Maintains game time.
+ */
+ class GameTime: public model::Component
+ {
+ public:
+ virtual ~GameTime();
+
+ virtual model::Component* clone() override;
+ virtual void dump(unsigned level) override;
+
+ virtual void onUpdateLogic() override;
+ };
+
+} /* namespace components */
+} /* namespace farmlands */
+
+#endif /* COMPONENTS_GAMETIME_H_ */
diff --git a/src/components/basic/Grid.cpp b/src/components/basic/Grid.cpp
index 157403c..78292b4 100644
--- a/src/components/basic/Grid.cpp
+++ b/src/components/basic/Grid.cpp
@@ -139,6 +139,11 @@ void Grid::set(model::GameObject* obj, int x, int y, bool throwOnOverwrite)
}
m_grid[index] = obj;
+
+ // Set transform as well
+ Transform* transf = obj->component();
+ transf->x = x;
+ transf->y = y;
}
} /* namespace basic */
diff --git a/src/components/basic/Grid.h b/src/components/basic/Grid.h
index 6e97965..2f59f81 100644
--- a/src/components/basic/Grid.h
+++ b/src/components/basic/Grid.h
@@ -67,9 +67,9 @@ namespace basic {
// Operations
model::GameObject* get(int x, int y);
+ void set(model::GameObject* obj, int x, int y, bool throwOnOverwrite = true);
private:
- void set(model::GameObject* obj, int x, int y, bool throwOnOverwrite);
utils::Rect m_bounds;
model::GameObject** m_grid;
diff --git a/src/components/basic/Sprite.cpp b/src/components/basic/Sprite.cpp
index a79029f..5f5588a 100644
--- a/src/components/basic/Sprite.cpp
+++ b/src/components/basic/Sprite.cpp
@@ -64,7 +64,7 @@ void Sprite::dump(unsigned level)
void Sprite::onPreRender()
{
- advanceTime(GameState::current().elapsedTime);
+ advanceTime(GameState::current().deltaTime);
}
void Sprite::addState(const SpriteState& state)
diff --git a/src/components/items/Weapon.cpp b/src/components/items/Weapon.cpp
index de4f76a..680b1d2 100644
--- a/src/components/items/Weapon.cpp
+++ b/src/components/items/Weapon.cpp
@@ -53,7 +53,7 @@ void Weapon::onUpdateLogic()
{
if (attackTimeLeft > 0)
{
- attackTimeLeft -= GameState::current().elapsedTime;
+ attackTimeLeft -= GameState::current().deltaTime;
}
}
diff --git a/src/components/plants/Plant.cpp b/src/components/plants/Plant.cpp
new file mode 100644
index 0000000..119a300
--- /dev/null
+++ b/src/components/plants/Plant.cpp
@@ -0,0 +1,101 @@
+/*
+ * Plant.cpp
+ *
+ * Created on: Dec 9, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+
+#include
+
+namespace farmlands {
+namespace components {
+namespace plants {
+
+Plant::Plant()
+ : needsWater(false),
+ daysWithoutWater(0),
+ maxDaysWithoutWater(2),
+ state(0),
+ stateDays(0),
+ stateLengths(),
+ m_sprite(nullptr)
+{
+ // The age is set to 0xffffffff so that it is updated at the next 'update logic' call
+}
+
+Plant::~Plant()
+{
+}
+
+model::Component* Plant::clone()
+{
+ Plant* clone = new Plant();
+ clone->needsWater = needsWater;
+ clone->daysWithoutWater = daysWithoutWater;
+ clone->maxDaysWithoutWater = maxDaysWithoutWater;
+ clone->state = state;
+ clone->stateDays = stateDays;
+ clone->state = state;
+ std::copy(stateLengths.begin(), stateLengths.end(), std::back_inserter(clone->stateLengths));
+
+ return clone;
+}
+
+void Plant::dump(unsigned level)
+{
+ for (unsigned i = 0; i < level; i++)
+ std::cout<<" ";
+
+ std::cout << " .Component: Plant\n";
+}
+
+void Plant::onInitialize()
+{
+ m_sprite = gameObject->component();
+
+ if (stateLengths.empty())
+ stateLengths.push_back(-1);
+}
+
+void Plant::onUpdateLogic()
+{
+ // At midnight, the plant grows
+ if (GameState::current().isMidnight)
+ {
+ stateDays++;
+ daysWithoutWater++;
+
+ // Exceeded plant's survival time without water
+ if (needsWater && daysWithoutWater > maxDaysWithoutWater)
+ die();
+
+ // Increment state
+ bool haveState = state < stateLengths.size();
+ bool isFinite = (stateLengths[state] != -1);
+ bool finishedState = stateDays >= (size_t)stateLengths[state];
+
+ if (haveState && isFinite && finishedState)
+ {
+ ++state;
+ stateDays = 0;
+ m_sprite->setState(state);
+ }
+ }
+}
+
+void Plant::onWatered()
+{
+ daysWithoutWater = 0;
+}
+
+void Plant::die()
+{
+ // TODO: implement plant death
+}
+
+} /* namespace plants */
+} /* namespace components */
+} /* namespace farmlands */
diff --git a/src/components/plants/Plant.h b/src/components/plants/Plant.h
new file mode 100644
index 0000000..81a2c73
--- /dev/null
+++ b/src/components/plants/Plant.h
@@ -0,0 +1,55 @@
+/*
+ * Plant.h
+ *
+ * Created on: Dec 9, 2016
+ * Author: tibi
+ */
+
+#ifndef COMPONENTS_PLANTS_PLANT_H_
+#define COMPONENTS_PLANTS_PLANT_H_
+
+#include
+#include
+
+#include
+#include
+
+namespace farmlands {
+namespace components {
+namespace plants {
+
+ class Plant: public model::Component
+ {
+ public:
+ Plant();
+ virtual ~Plant();
+
+ virtual model::Component* clone() override;
+ virtual void dump(unsigned level) override;
+
+ virtual void onInitialize() override;
+ virtual void onUpdateLogic() override;
+
+ void onWatered();
+ void die();
+
+ bool needsWater; // Watering - if the plant needs water (trees don't need water).
+ uint32_t daysWithoutWater; // How many days passed since last watered
+ uint32_t maxDaysWithoutWater; // How many days the plant can survive without water
+
+ size_t state; // Current state
+ uint32_t stateDays; // How many days have elapsed since the last state change
+
+ // The length of each state, measured in days.
+ // After all the states are passed through, the plant dies; -1 means infinity
+ std::vector stateLengths;
+
+ private:
+ basic::Sprite* m_sprite;
+ };
+
+} /* namespace plants */
+} /* namespace components */
+} /* namespace farmlands */
+
+#endif /* COMPONENTS_PLANTS_PLANT_H_ */
diff --git a/src/components/plants/Seed.cpp b/src/components/plants/Seed.cpp
new file mode 100644
index 0000000..7fbe00f
--- /dev/null
+++ b/src/components/plants/Seed.cpp
@@ -0,0 +1,101 @@
+/*
+ * Seed.cpp
+ *
+ * Created on: Dec 6, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+#include
+#include
+#include