diff options
-rw-r--r-- | Changelog | 7 | ||||
-rw-r--r-- | brice.dat | 6 | ||||
-rw-r--r-- | include/entities.hpp | 2 | ||||
-rw-r--r-- | include/world.hpp | 2 | ||||
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | src/brice.cpp | 3 | ||||
-rw-r--r-- | src/entities.cpp | 7 | ||||
-rw-r--r-- | src/mob.cpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 27 |
9 files changed, 38 insertions, 21 deletions
@@ -1011,3 +1011,10 @@ - added onHit and onDeath routines to mobs - added mob drops on arena kills - continued work on new renderings + +5/23/2016: +========== + + - fixed grass squishing + - player sits on cat better + - world shading is good-er @@ -1,5 +1,5 @@ 2 -canJump -0 canSprint -0 +1 +canJump +1 diff --git a/include/entities.hpp b/include/entities.hpp index 82f80c7..ca4ef2b 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -284,7 +284,7 @@ public: bool isHit(void) const; // returns true if this entity is near the one provided - bool isNear(Entity e); + bool isNear(const Entity *e); // returns true if the coordinate is within the entity bool isInside(vec2 coord) const; diff --git a/include/world.hpp b/include/world.hpp index 74f9cb7..ce50244 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -264,7 +264,6 @@ protected: * @see addStructure() * @see getStructurePos() */ - std::vector<Structures *> build; /** * A vector of all villages in the world. @@ -291,6 +290,7 @@ protected: public: + std::vector<Structures *> build; /** * A vector of pointers to all entities from the other vectors. * This is used to mass-manage entities, or operate on entities @@ -536,7 +536,7 @@ void logic(){ } } - if(e->isInside(ui::mouse) && player->isNear(*e)) { + if(e->isInside(ui::mouse) && player->isNear(e)) { e->near = true; if (e->type == OBJECTT) ObjectSelected = true; @@ -554,7 +554,7 @@ void logic(){ e->near = false; } } else if (e->type == MOBT) { - e->near = player->isNear(*e); + e->near = player->isNear(e); e->wander(); } } diff --git a/src/brice.cpp b/src/brice.cpp index fb9834d..07cd05d 100644 --- a/src/brice.cpp +++ b/src/brice.cpp @@ -56,8 +56,7 @@ namespace game { if (datas.size() != 0) { const unsigned int count = datas[0][0] - '0'; - for (unsigned int i = 1; i <= count; i += 2) { - std::cout << datas[i] << ' ' << datas[i + 1] << '\n'; + for (unsigned int i = 1; i <= count * 2; i += 2) { brice.emplace(std::make_pair(datas[i], datas[i + 1])); } } diff --git a/src/entities.cpp b/src/entities.cpp index 8299e2c..550748a 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -329,8 +329,8 @@ void Object::reloadTexture(void) height = getItemHeight(iname); } -bool Entity::isNear(Entity e) { - return pow(e.loc.x - loc.x, 2) + pow(e.loc.y - loc.y, 2) <= pow(HLINES(40), 2); +bool Entity::isNear(const Entity *e) { + return (e != nullptr) ? (pow(e->loc.x - loc.x, 2) + pow(e->loc.y - loc.y, 2) <= pow(HLINES(40), 2)) : false; } void NPC::drawThingy(void) const @@ -412,8 +412,9 @@ void Entity::draw(void) } else if (type == MOBT) { if (Mobp(this)->rider != nullptr) { Mobp(this)->rider->loc.x = loc.x + width * 0.25f; - Mobp(this)->rider->loc.y = loc.y + height - game::HLINE; + Mobp(this)->rider->loc.y = loc.y + height - HLINES(5); Mobp(this)->rider->vel.y = .12; + Mobp(this)->rider->z = z + 0.01; } } switch(type) { diff --git a/src/mob.cpp b/src/mob.cpp index 1f998f7..d6df3fd 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -11,6 +11,7 @@ Mob::Mob(void) inv = nullptr; rider = nullptr; canMove = true; + loc = 0; } Page::Page(void) : Mob() diff --git a/src/world.cpp b/src/world.cpp index efafa55..2ecccec 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -689,6 +689,8 @@ void World::draw(Player *p) // flatten grass under the player if the player is on the ground if (p->ground) { + pOffset = (p->loc.x + p->width / 2 - worldStart) / HLINE; + for (unsigned int i = 0; i < worldData.size(); i++) worldData[i].grassUnpressed = !(i < static_cast<unsigned int>(pOffset + 6) && i > static_cast<unsigned int>(pOffset - 6)); } else { @@ -752,6 +754,9 @@ singleDetect(Entity *e) auto deltaTime = game::time::getDeltaTime(); + if (e == nullptr) + return; + // kill dead entities if (!e->isAlive()) { return; @@ -803,7 +808,9 @@ singleDetect(Entity *e) e->handleHits(); // calculate the line that this entity is currently standing on - l = (e->loc.x + e->width / 2 - worldStart) / game::HLINE; + l = std::clamp(static_cast<int>((e->loc.x + e->width / 2 - worldStart) / game::HLINE), + 0, + static_cast<int>(lineCount)); // if the entity is under the world/line, pop it back to the surface if (e->loc.y < worldData[l].groundHeight) { @@ -1030,7 +1037,7 @@ getNearInteractable(Entity &e) { auto n = std::find_if(std::begin(entity), std::end(entity), [&](Entity *&a) { return ((a->type == MOBT) || (a->type == NPCT) || a->type == MERCHT) && - e.isNear(*a) && (e.left ? (a->loc.x < e.loc.x) : (a->loc.x > e.loc.x)); + e.isNear(a) && (e.left ? (a->loc.x < e.loc.x) : (a->loc.x > e.loc.x)); }); return n == std::end(entity) ? nullptr : *n; @@ -1040,7 +1047,7 @@ Mob *World:: getNearMob(Entity &e) { auto n = std::find_if(std::begin(mob), std::end(mob), [&](Mob *&a) { - return e.isNear(*a) && (e.left ? (a->loc.x < e.loc.x + e.width / 2) : (a->loc.x > e.loc.x + e.width / 2)); + return e.isNear(a) && (e.left ? (a->loc.x < e.loc.x + e.width / 2) : (a->loc.x + a->width > e.loc.x + e.width / 2)); }); return n == std::end(mob) ? nullptr : *n; @@ -1892,7 +1899,7 @@ World *loadWorldFromPtr(World *ptr) */ World * loadWorldFromXMLNoSave(std::string path) { - XMLDocument xml; +XMLDocument currentXMLDoc; XMLElement *wxml; XMLElement *vil; @@ -1909,18 +1916,18 @@ loadWorldFromXMLNoSave(std::string path) { return NULL; currentXML = std::string(xmlFolder + path); - xml.LoadFile(currentXML.c_str()); + currentXMLDoc.LoadFile(currentXML.c_str()); // attempt to load a <World> tag - if ((wxml = xml.FirstChildElement("World"))) { + if ((wxml = currentXMLDoc.FirstChildElement("World"))) { wxml = wxml->FirstChildElement(); - vil = xml.FirstChildElement("World")->FirstChildElement("village"); + vil = currentXMLDoc.FirstChildElement("World")->FirstChildElement("village"); tmp = new World(); Indoor = false; } // attempt to load an <IndoorWorld> tag - else if ((wxml = xml.FirstChildElement("IndoorWorld"))) { + else if ((wxml = currentXMLDoc.FirstChildElement("IndoorWorld"))) { wxml = wxml->FirstChildElement(); vil = NULL; tmp = new IndoorWorld(); @@ -2079,10 +2086,12 @@ loadWorldFromXMLNoSave(std::string path) { Village *vptr; if (vil) { - vptr = tmp->addVillage(vil->Attribute("name"), tmp); + vptr = tmp->addVillage(vil->StrAttribute("name"), tmp); vil = vil->FirstChildElement(); } + std::cout << currentXML << ' ' << tmp->build.size() << '\n'; + while(vil) { name = vil->Name(); randx = 0; |