aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2016-05-05 09:27:39 -0400
committerClyne Sullivan <tullivan99@gmail.com>2016-05-05 09:27:39 -0400
commit1a1640760502081c2dcded90cff351163fabce76 (patch)
tree5f6b4f493fe57916261b22950a55482fbee6b7fe /src/world.cpp
parent095293277dbca80e91c4f25b05923b7cb3a79396 (diff)
bricing, controls jumps and sprints
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp66
1 files changed, 43 insertions, 23 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 80fc322..c085620 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -44,9 +44,6 @@ constexpr const unsigned int GRASS_HEIGHT = 4;
// the path of the currently loaded XML file, externally referenced in places
std::string currentXML;
-// contains the current world's weather, extern'd in ui.cpp, main.cpp, ..?
-WorldWeather weather = WorldWeather::Sunny;
-
// keeps track of pathnames of XML file'd worlds the player has left to enter structures
static std::vector<std::string> inside;
@@ -212,6 +209,8 @@ generate(int width)
s.x = (randGet() % (-worldStart * 2)) + worldStart;
s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
}
+
+ weather = WorldWeather::Sunny;
}
/**
@@ -707,8 +706,16 @@ detect(Player *p)
* Also handles music fading, although that could probably be placed elsewhere.
*/
void World::
-update(Player *p, unsigned int delta)
+update(Player *p, unsigned int delta, unsigned int ticks)
{
+ // update day/night time
+ if (!(ticks % DAY_CYCLE) || ticks == 0) {
+ if (weather == WorldWeather::Sunny)
+ weather = WorldWeather::Dark;
+ else if (weather == WorldWeather::Dark)
+ weather = WorldWeather::Sunny;
+ }
+
// update player coords
p->loc.y += p->vel.y * delta;
p->loc.x +=(p->vel.x * p->speed) * delta;
@@ -1027,6 +1034,35 @@ setStyle(std::string pre)
* Pretty self-explanatory.
*/
std::string World::
+getWeatherStr(void) const
+{
+ switch (weather) {
+ case WorldWeather::Sunny:
+ return "Sunny";
+ break;
+ case WorldWeather::Dark:
+ return "Dark";
+ break;
+ case WorldWeather::Rain:
+ return "Rainy";
+ break;
+ case WorldWeather::Snowy:
+ return "Snowy";
+ break;
+ }
+ return "???";
+}
+
+const WorldWeather& World::
+getWeatherId(void) const
+{
+ return weather;
+}
+
+/**
+ * Pretty self-explanatory.
+ */
+std::string World::
setToLeft(std::string file)
{
return (toLeft = file);
@@ -1492,11 +1528,13 @@ Arena::Arena(void)
{
generate(800);
addMob(new Door(), vec2 {100, 100});
+ mmob = nullptr;
}
Arena::~Arena(void)
{
- mmob->die();
+ if (mmob != nullptr)
+ mmob->die();
deleteEntities();
}
@@ -1526,24 +1564,6 @@ WorldSwitchInfo Arena::exitArena(Player *p)
return std::make_pair(this, vec2 {0, 0});
}
-std::string getWorldWeatherStr(WorldWeather ww)
-{
- switch (ww) {
- case WorldWeather::Sunny:
- return "Sunny";
- break;
- case WorldWeather::Dark:
- return "Darky";
- break;
- case WorldWeather::Rain:
- return "Rainy";
- break;
- default:
- return "Snowy";
- break;
- }
-}
-
static bool loadedLeft = false;
static bool loadedRight = false;