diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-10 15:33:02 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-10 15:33:02 -0400 |
commit | 076c984c438bea2b34f8dd3a62bb31ebd2eb5282 (patch) | |
tree | b0252c6c054a86eebdf00afccd0afa83e7ff911a /src | |
parent | 1e9f6aaddb2d21045f5e7dc63d6312a4407b3a08 (diff) |
actual game making
Diffstat (limited to 'src')
-rw-r--r-- | src/brice.cpp | 4 | ||||
-rw-r--r-- | src/entities.cpp | 22 | ||||
-rw-r--r-- | src/mob.cpp | 50 | ||||
-rw-r--r-- | src/ui.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 59 |
5 files changed, 90 insertions, 49 deletions
diff --git a/src/brice.cpp b/src/brice.cpp index d5ac46d..de95f51 100644 --- a/src/brice.cpp +++ b/src/brice.cpp @@ -35,8 +35,10 @@ namespace game { void briceClear(void) { std::ofstream out ("brice.dat", std::ios::out); + const std::string defaultt = "1\nSlow\n1\n"; + out.write(defaultt.data(), defaultt.size()); out.close(); - brice.clear(); + briceLoad(); } void briceSave(void) { diff --git a/src/entities.cpp b/src/entities.cpp index 01255d5..9f9a47c 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -257,6 +257,10 @@ void NPC::createFromXML(XMLElement *e, World *w=nullptr) // custom health value E_LOAD_HEALTH; + // movemenet + if (e->QueryBoolAttribute("canMove", &dialog) == XML_NO_ERROR) + canMove = dialog; + // dialog index if (e->QueryUnsignedAttribute("dindex", &flooor) == XML_NO_ERROR) dialogIndex = flooor; @@ -591,8 +595,10 @@ wander(int timeRun) vel.x = HLINES(-0.018); else if (loc.x < targetx - HLINES(5)) vel.x = HLINES(0.018); - else + else { targetx = 0.9112001f; + vel.x = 0; + } } else if (ticksToUse == 0) { ticksToUse = timeRun; @@ -628,6 +634,7 @@ void NPC::interact() { //have the npc's interact back to the player XMLElement *exml,*oxml; static unsigned int oldidx = 9999; + const char *ptr; std::string nname; unsigned int idx; bool stop; @@ -704,8 +711,11 @@ COMMONAIFUNC: moveTo(std::stoi(oxml->GetText())); // asdlfkj - auto ptr = exml->GetText() - 1; - while (isspace(*++ptr)); + if (exml->GetText() == nullptr) + goto OTHERSTUFF; + + ptr = exml->GetText() - 1; + while (*++ptr && isspace(*ptr)); // handle dialog options if ((oxml = exml->FirstChildElement("option"))) { @@ -736,6 +746,8 @@ COMMONAIFUNC: ui::waitForDialog(); } +OTHERSTUFF: + // trigger other npcs if desired if (!(nname = exml->StrAttribute("call")).empty()) { NPC *n = *std::find_if(std::begin(currentWorld->npc), std::end(currentWorld->npc), [nname](NPC *npc) { @@ -1062,7 +1074,7 @@ bool Particles::timeUp(void) void Player::save(void) { std::string data; - std::ofstream out ("xml/main.dat",std::ios::out | std::ios::binary); + std::ofstream out (xmlFolder + ".main.dat", std::ios::out | std::ios::binary); std::cout<<"Saving player data..."<<std::endl; data.append(std::to_string((int)loc.x) + "\n"); data.append(std::to_string((int)loc.y) + "\n"); @@ -1088,7 +1100,7 @@ void Player::save(void) { void Player::sspawn(float x,float y) { unsigned int i; int count; - std::ifstream in (std::string(xmlFolder + "main.dat"),std::ios::in | std::ios::binary); + std::ifstream in (xmlFolder + ".main.dat", std::ios::in | std::ios::binary); spawn(x,y); if (in.good()) { diff --git a/src/mob.cpp b/src/mob.cpp index 7701086..798f09a 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -331,6 +331,7 @@ Trigger::Trigger(void) : Mob() height = 2000; //tex = TextureIterator(); triggered = false; + notext = false; } void Trigger::act(void) @@ -355,28 +356,38 @@ void Trigger::act(void) player->vel.x = 0; - if (exml == nullptr) { + if (notext) { + for (auto &n : currentWorld->npc) { + if (n->name == exml->GetText()) { + n->interact(); + break; + } + } + } else { + + /*if (exml == nullptr) { auto id = xmle->StrAttribute("cid"); if (!id.empty()) { game::setValue(id, xmle->StrAttribute("cvalue")); game::briceUpdate(); } return; - } + }*/ - ui::toggleBlackFast(); - ui::waitForCover(); + ui::toggleBlackFast(); + ui::waitForCover(); - std::string text = exml->GetText(); - char *pch = strtok(&text[0], "\n"); + std::string text = exml->GetText(); + char *pch = strtok(&text[0], "\n"); - while (pch) { - ui::importantText(pch); - ui::waitForDialog(); - pch = strtok(NULL, "\n"); - } + while (pch) { + ui::importantText(pch); + ui::waitForDialog(); + pch = strtok(NULL, "\n"); + } - ui::toggleBlackFast(); + ui::toggleBlackFast(); + } triggered = true; running = false; @@ -397,10 +408,17 @@ bool Trigger::bindTex(void) void Trigger::createFromXML(XMLElement *e, World *w=nullptr) { (void)w; - float Xlocx; - if (e->QueryFloatAttribute("x", &Xlocx) == XML_NO_ERROR) - loc.x = Xlocx; - id = e->StrAttribute("id"); + float Xlocx; + + if (e->QueryFloatAttribute("spawnx", &Xlocx) == XML_NO_ERROR) + loc.x = Xlocx; + + if (e->QueryBoolAttribute("notext", ¬ext) != XML_NO_ERROR) + notext = false; + + id = e->StrAttribute("id"); + + xmle = e; } void Trigger::saveToXML(void) @@ -1256,6 +1256,8 @@ EXIT: if (fadeEnable) break; player->vel.x = -PLAYER_SPEED_CONSTANT; + if (std::stoi(game::getValue("Slow")) == 1) + player->vel.x /= 2.0f; player->left = left = true; player->right = right = false; if (currentWorldToLeft) { @@ -1270,6 +1272,8 @@ EXIT: if (fadeEnable) break; player->vel.x = PLAYER_SPEED_CONSTANT; + if (std::stoi(game::getValue("Slow")) == 1) + player->vel.x /= 2.0f; player->right = right = true; player->left = left = false; if (currentWorldToRight) { diff --git a/src/world.cpp b/src/world.cpp index a36a9b8..2eebc4a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -31,6 +31,12 @@ extern World *currentWorldToRight; // main.cpp extern bool inBattle; // ui.cpp? extern std::string xmlFolder; +static const std::array<std::string, 3> WorldWeatherString { + "None", + "Rainy", + "Snowy" +}; + // particle mutex std::mutex partMutex; @@ -220,7 +226,7 @@ generate(int width) s.y = (randGet() % game::SCREEN_HEIGHT) + 100; } - weather = WorldWeather::Sunny; + weather = WorldWeather::None; } /** @@ -1010,16 +1016,8 @@ detect(Player *p) * Also handles music fading, although that could probably be placed elsewhere. */ void World:: -update(Player *p, unsigned int delta, unsigned int ticks) +update(Player *p, unsigned int delta) { - // 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; @@ -1230,21 +1228,7 @@ void World::setStyle(std::string pre) */ 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 "???"; + return WorldWeatherString[static_cast<int>(weather)]; } const WorldWeather& World::getWeatherId(void) const @@ -1252,6 +1236,17 @@ const WorldWeather& World::getWeatherId(void) const return weather; } +void World::setWeather(const std::string &s) +{ + for (unsigned int i = WorldWeatherString.size(); i--;) { + if (WorldWeatherString[i] == s) { + weather = static_cast<WorldWeather>(i); + return; + } + } + weather = WorldWeather::None; +} + /** * Pretty self-explanatory. */ @@ -2008,6 +2003,16 @@ loadWorldFromXMLNoSave(std::string path) { } } + // weather tags + else if (name == "weather") { + tmp->setWeather(wxml->GetText()); + } + + // set spawn x for player + else if (name == "spawnx") { + player->loc.x = std::stoi(wxml->GetText()); + } + // mob creation else if (name == "rabbit") { newEntity = new Rabbit(); @@ -2054,8 +2059,6 @@ loadWorldFromXMLNoSave(std::string path) { if (newEntity != nullptr) { bool alive = true; if (wxml->QueryBoolAttribute("alive", &alive) != XML_NO_ERROR || alive) { - newEntity->createFromXML(wxml, tmp); - switch (newEntity->type) { case NPCT: tmp->addNPC(dynamic_cast<NPC *>(newEntity)); @@ -2069,6 +2072,8 @@ loadWorldFromXMLNoSave(std::string path) { default: break; } + + newEntity->createFromXML(wxml, tmp); } } |