Hi Folks,
I am trying to do a RISK type game where I have regions and you move armies onto each region etc.
Now I have large images which 5680 X 4178 pixels. However it only contains an outline of the region. I've tried uploading to tinypic but it doesn't display very well.
So I have created another image with the interior of the region as well as just the border
So I then use the 2nd image which the pixels within the region set to white to create a pixel vector. The below code, basically checks each pixel for color. If it is white, then I add a sf::Vector2i entry to a vector for that region.
vector<sf::Vector2i> regionLandPixelList; //stores a list of pixels for this region that denotes a land pixel
void drawEngine::initRegionPixelVector(Region *passed_Region)
{
sf::Image image;
sf::Color color;
image.loadFromFile(passed_Region->getRegionImageFileName());
if (passed_Region->isRegionPlayable())
{
for (int x = 0; x < image.getSize().x; x++)
{
for (int y = 0; y < image.getSize().y; y++)
{
color = image.getPixel(x,y);
if (color == sf::Color::White)
{
passed_Region->addPosToRegionLandPixelList(x,y);
}
}
}
}
}
void Region::addPosToRegionLandPixelList(sf::Vector2i pos)
{
regionLandPixelList.push_back(pos);
}
So then I use the regionLandPixelList vector to determine if the user has moved an army into this region. Now this works well but I've found that the regionLandPixelList grows to very large sizes. For example the region above, the size of regionLandPixelList had over 40K entries. And I eventually plan to have around 60 regions....some of them much larger than the one above.
I am concerned about performance as I have to check the regionlandpixellist of each region, every time the user moves an army piece.
So I was wondering, is there any way/calc that I can use with the region outline to determine if the mouse position is within that region? Obviously each region outline is irregular which makes this very tricky.