Esempio n. 1
0
SRect Map::GetBoundingBoxFromSegment(SLineSegment line, NPC& npc,
		Character& character) {
	// Get Region
	SRect region;

	//bool npcIntersect = PointInRect(line.to, character.GetBoundingBox()) || PointInRect(line.from, character.GetBoundingBox()) ;
	bool npcIntersect = Intersect(line, character.GetBoundingBox());
	//npc.SetStop(npcIntersect);

	if (npcIntersect) {
		region += character.GetBoundingBox();
	}

	return region;
}
Esempio n. 2
0
SRect Map::GetBoundingBoxFromSegment(SLineSegment line, Character& character) {
	// Validate that the line segment is within the maps range
	if (line.from.x < 0.0f || line.from.x > mMapData.GetWidth()
			|| line.from.y < 0.0f || line.from.y > mMapData.GetHeight()
			|| line.to.x < 0.0f || line.to.x > mMapData.GetWidth()
			|| line.to.y < 0.0f || line.to.y > mMapData.GetHeight()) {
		return SRect();
	}

	// Convert position to indices
	const int fromX = static_cast<int>(line.from.x) / 32;
	const int fromY = static_cast<int>(line.from.y) / 32;
	const int toX = static_cast<int>(line.to.x) / 32;
	const int toY = static_cast<int>(line.to.y) / 32;

	// Calculate Tile Count
	const int countX = toX - fromX + 1;
	const int countY = toY - fromY + 1;

	// Get Region
	SRect region;

#if _DEBUG

	for(int a = 0; a < mNumberOfNPCS; ++a)
	{
		SRect region2 = mNPCS[a]->GetBoundingBox();
		Graphics_DebugRect(region2 + sOffset, 0XFF00FF);

		Graphics_DebugRect(character.GetBoundingBox() + sOffset, 0X00FFFF);
	}

	for(int a = 0; a < mMapData.GetTileAmount(); ++a)
	{
		if(!mMapData.mLayer1[a].IsWalkable())
		{
			SRect region2 = mMapData.mLayer1[a].GetBoundingBox();
			Graphics_DebugRect(region2 + sOffset, 0XFF00FF);
		}
	}

#endif

	int width = GetWidth();
	for (int y = 0; y < countY; ++y) {
		for (int x = 0; x < countX; ++x) {
			const int index = (fromX + x) + ((fromY + y) * (width));

			character.SetTileIndex(index);

			// Block Tile
			if (!mMapData.mLayer1[index].IsWalkable()) {
				region += mMapData.mLayer1[index].GetBoundingBox();
				Graphics_DebugRect(region + sOffset, 0XFF0000);
			}

			for (int a = 0; a < mNumberOfNPCS; ++a) {
				bool npcIntersect = PointInRect(line.to,
						mNPCS[a]->GetBoundingBox());

				if (npcIntersect) {
					return region += mNPCS[a]->GetBoundingBox();
				}
			}

			// Item Tile
			if (mMapData.mLayer1[index].GetItemImageNumber()) {
				SRect debug = region + mMapData.mLayer1[index].GetBoundingBox();
				character.SetOnItem(mMapData.mLayer1[index].GetItemID());
				character.SetOnItemIndex(index);
				Graphics_DebugRect(debug + sOffset, 0XFFFF00);
			} else {
				character.SetOnItem(0);
			}
		}
	}

	return region;
}