示例#1
0
文件: Walker.cpp 项目: Rasie1/glowy2d
void Walker::update(float dt)
{
    Circle::update(dt);
    if (grounded)
    {
        setVelocity(getVelocity() * 0.999f * dt);
        checkGrounded();
        if (getPosition().y > groundedHeight)
            setPosition(vec2(getPosition().x,
                             getPrevPosition().y));
    }
}
Position PathMemory::moveOnPath(Position current, Position next, Position end)
{
	if (!currentPath)
	{
		if (existsPath(current, end))
		{
			currentPath = getMemory(current, end);
		}
		else
		{
			startPath(current, end);
		}
	}
	else
	{
		if (current == end)
		{
			currentPath->path.push_back(current);
			currentPath->pathComplete = true;
			currentPath = NULL;
			return current;
		}
		if (currentPath->pathComplete)
		{
			return getPrevPosition();
		}
		else if (pathMap[next] == VISITED)
		{
			pathMap[current] = VISITED;
			if (currentPath->path.size() >= 2)
			{
				Position pos = *(currentPath->path.end() - 1);
				currentPath->path.erase(currentPath->path.end() - 1);
				return pos;
			}
			return currentPath->start;
		}
		else
		{
			currentPath->path.push_back(current);
			pathMap[current] = VISITED;
			return next;
		}
	}
	return next;
}