示例#1
0
	uint16_t Footholdtree::getnext(uint16_t curid, bool left, float fx, float fy) const
	{
		if (footholds.count(curid))
		{
			uint16_t nextid = left ? footholds.at(curid).getprev() : footholds.at(curid).getnext();
			if (footholds.count(nextid))
			{
				return nextid;
			}
		}
		return getbelow(fx, fy);
	}
示例#2
0
	int16_t Footholdtree::getgroundbelow(Point<int16_t> position) const
	{
		uint16_t fhid = getbelow(position.x(), position.y());
		if (fhid > 0)
		{
			const Foothold& fh = getfh(fhid);
			return static_cast<int16_t>(fh.resolvex(position.x()));
		}
		else
		{
			return borders.second();
		}
	}
示例#3
0
	void Footholdtree::updatefh(PhysicsObject& phobj) const
	{
		if (phobj.fhid == 0)
		{
			phobj.fhid = getbelow(phobj.fx, phobj.fy);
		}
		else if (phobj.onground)
		{
			const Foothold& curfh = getfh(phobj.fhid);
			if (phobj.fx > curfh.getr())
			{
				phobj.fhid = getnext(phobj.fhid, false, phobj.fx, phobj.fy);
			}
			else if (phobj.fx < curfh.getl())
			{
				phobj.fhid = getnext(phobj.fhid, true, phobj.fx, phobj.fy);
			}
		}
		else
		{
			phobj.fhid = getbelow(phobj.fx, phobj.fy);
		}

		const Foothold& nextfh = getfh(phobj.fhid);
		phobj.fhlayer = nextfh.getlayer();
		phobj.fhslope = nextfh.getslope();

		float ground = nextfh.resolvex(phobj.fx);
		if (phobj.vspeed == 0.0f)
		{
			if (abs(ground - phobj.fy) <= abs(phobj.hspeed))
			{
				phobj.fy = ground;
			}
		}
		phobj.onground = phobj.fy == ground;
	}
	foothold footholdtree::getnext(bool left, foothold cur)
	{
		short nextid = left ? cur.prev : cur.next;

		if (nextid > 0)
		{
			cur = footholds[nextid];
		}
		else
		{
			vector2d pos = left ? cur.getledge() : cur.getredge();
			cur = getbelow(pos);
		}

		return cur;
	}
示例#5
0
	void Footholdtree::updatefh(PhysicsObject& phobj) const
	{
		const Foothold& curfh = getfh(phobj.fhid);
		bool checkslope = false;

		double x = phobj.crntx();
		double y = phobj.crnty();
		if (phobj.onground)
		{
			if (std::floor(x) > curfh.getr())
			{
				phobj.fhid = curfh.getnext();
			}
			else if (std::ceil(x) < curfh.getl())
			{
				phobj.fhid = curfh.getprev();
			}

			if (phobj.fhid == 0)
			{
				phobj.fhid = getbelow(x, y);
			}
			else
			{
				checkslope = true;
			}
		}
		else
		{
			phobj.fhid = getbelow(x, y);
		}

		const Foothold& nextfh = getfh(phobj.fhid);
		phobj.fhslope = nextfh.getslope();

		double ground = nextfh.resolvex(x);
		if (phobj.vspeed == 0.0 && checkslope)
		{
			double vdelta = abs(phobj.fhslope);
			if (phobj.fhslope < 0.0)
			{
				vdelta *= (ground - y);
			}
			else if (phobj.fhslope > 0.0)
			{
				vdelta *= (y - ground);
			}

			if (curfh.getslope() != 0.0 || nextfh.getslope() != 0.0)
			{
				if (phobj.hspeed > 0.0 && vdelta <= phobj.hspeed)
				{
					phobj.y = ground;
				}
				else if (phobj.hspeed < 0.0 && vdelta >= phobj.hspeed)
				{
					phobj.y = ground;
				}
			}
		}

		phobj.onground = phobj.y == ground;

		uint16_t belowid = getbelow(x, nextfh.resolvex(x) + 1.0);
		if (belowid > 0)
		{
			double nextground = getfh(belowid).resolvex(x);
			phobj.enablejd = (nextground - ground) < 600.0;
			phobj.groundbelow = ground + 1.0;
		}
		else
		{
			phobj.enablejd = false;
		}

		if (phobj.fhlayer == 0 || phobj.onground)
		{
			phobj.fhlayer = nextfh.getlayer();
		}
	}