}
bool Entity::isNear(const Entity *e) {
- return pow(e->loc.x - loc.x, 2) + pow(e->loc.y - loc.y, 2) <= pow(HLINES(40), 2);
+ 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
} 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) {
// 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 {
auto deltaTime = game::time::getDeltaTime();
+ if (e == nullptr)
+ return;
+
// kill dead entities
if (!e->isAlive()) {
return;
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) {
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;
*/
World *
loadWorldFromXMLNoSave(std::string path) {
- XMLDocument xml;
+XMLDocument currentXMLDoc;
XMLElement *wxml;
XMLElement *vil;
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();
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;