Esempio n. 1
0
bool Mob::IntersectsWall(sf::Rect<int> const& position, std::vector<std::vector<gen::Tile>> const& map){
	for (int x = position.left/32 - 1, y = position.top/32 - 1; x < (position.left + position.width)/32 + 2; x++)
	{
		if (x > 0 && x < map.size())
		{
			for (y = position.top/32 - 1; y < (position.top + position.height)/32 + 2; y++)
			{
				if (y > 0 && y < map[x].size())
				{
					if (map[x][y].type == 2)
					{
						if (position.intersects(sf::Rect<int>(x*32, y*32, 32, 32)))
						{
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}
Esempio n. 2
0
bool Building::intersects(sf::Rect<float> const& other) const
{
	return other.intersects(bb);
}
Esempio n. 3
0
int Map::CheckCollision(sf::Rect<int> CheckRect, int X, int Y, int CheckType)
{
	int Xmin = (int)(X / CellSize);
	int Xmax = (int)((X + CheckRect.width) / CellSize);
	int Ymin = (int)(Y / CellSize);
	int Ymax = (int)((Y + CheckRect.height) / CellSize);
	if(CheckType == 0)
		if (X < 0 || Y < 0)
			return 1;//0 returns 1....
	if (CheckType == -1)
		if (X >= (MapWidth - 1) * 32 || Y >= (MapWidth - 1) * 32)//Shitty method of stoping players from leaving the room.
			return -1;//Outside Room
	CheckRect.left = X; CheckRect.top = Y;
	WCR.LimitVariable(0, MapWidth - 1, Xmin);
	WCR.LimitVariable(0, MapWidth - 1, Xmax);
	WCR.LimitVariable(0, MapHeight - 1, Ymin);
	WCR.LimitVariable(0, MapHeight - 1, Ymax);
	for (int i = Xmin; i <= Xmax; i++)
		for (int ii = Ymin; ii <= Ymax; ii++)
		{
			bool IsTrue = false;
			switch (CheckType)//Check for any
			{
			case -2:IsTrue = (MapMatrix[i][ii].objectType != 0); break;
			case 1:IsTrue = (MapMatrix[i][ii].objectType == 1 || MapMatrix[i][ii].objectType == 5); break;//solids
			case 0:break;//Nothing, don't search for empty space. Only search for map edge.
			default:IsTrue = (MapMatrix[i][ii].objectType == CheckType); break;
			}
			if (IsTrue)//Object here
			{
				sf::Rect<int> SolidBoundBox;
				SolidBoundBox.left = i * CellSize;
				SolidBoundBox.top = ii * CellSize;
				SolidBoundBox.width = CellSize; SolidBoundBox.height = CellSize;
				if (CheckRect.intersects(SolidBoundBox))
				{
					if (!MapMatrix[i][ii].pixelPerfect)
						return MapMatrix[i][ii].objectType;
					else
					{
						//get image and player box overlap
						int Left_ = X - i * 32;
						int Top_ = Y - ii * 32;
						int SLeft_ = Left_;
						int STop_ = Top_;
						int Wid_ = CheckRect.width-1;
						int Hei_ = CheckRect.height - 1;

						if (Left_ < 0)
						{
							Wid_ += Left_;
							Left_ = 0;
						}

						if (Top_ < 0)
						{
							Hei_ += Top_;
							Top_ = 0;
						}

						/*if (Top_ > 46)
							Top_ = 46;
						if (Hei_ > 35)
							Hei_ = 35;*/


						if (Wid_ > 31)
							Wid_ = 31;
						if (Hei_ > 31)
							Hei_ = 31;

						for (int f = Wid_; f >= Left_; f--)//<= ??
							for (int ff = Hei_; ff >= Top_; ff--)//<= ??
							{
								if (WCR.MMPtr->TileSets[MapMatrix[i][ii].tileSetID].CollisionMaps[MapMatrix[i][ii].tileID].getPixel(f, ff).a != 0 && WCR.PlrPtr->PlayerMask.getPixel(f - SLeft_, ff - STop_).a != 0)
									return MapMatrix[i][ii].objectType;
							}
					}
					
				}
					
			}
		}
	return false;
}