Sign in to follow this  
sarton

How to do a risk-like map?

Recommended Posts

sarton    122
Apologies if this has been covered. I have spent most of a day searching, but can't seem to find what I'm looking for... There are various games which implement Risk or Axis & Alies maps. These maps have territories which a player can select. One implementation I've seen used a greyscale map that defined the various regions with different colors. I'm guessing that the program process the mouse click by finding the color of the region. Once the color is found, it's used to find that polygon, make the selection, etc. Yet I've noticed that games like Gary Grigsby's World at War break the map into tiles. There is no back map with the regions defined by a color image. So, my quesiton is, how is this done? Is there an article (or articles) that cover how these maps are done? What am I missing? TIA

Share this post


Link to post
Share on other sites
hplus0603    11347
Most OS-es implement a drawing primitive call a "region" which can have an arbitrary shape. You could draw any map you wanted, and then test which country you've clicked in by testing PointInRegion() for each of the regions. (You could accelerate it a bit with a quad tree, but that's not really necessary)

To do this, you should probably create a tool that allows you to import a map drawing and extract regions from it (using floor fill or line following or whatever).

Share this post


Link to post
Share on other sites
Make sure that you use an orthogonal projection to show the map.
Also, be sure to search the search the "Isometric Land" forum on this site to find a lot of info regarding rendering the screen.

Sorry I couldn't help more, but I program 3d only.

ProgrammingNerd

Share this post


Link to post
Share on other sites
CJM    454
Hey,

If you're not one for pixelmaps, perhaps turning all regions into polygons is the way to go, then you do a linetest from somewhere you know is in the region [eg the center of the tile] to the point clicked. If the lines you cross is even, you're in the tile, odd, you're outside.

Just my thoughts...

-- CJM

Share this post


Link to post
Share on other sites
jyk    2094
There may be other standard solutions for this sort of game, but if you're interested in pursuing the aforementioned 'point in concave polygon' approach, here's an implementation:


template <class T> bool PointInPoly(
const Vector2<T>& p,
const std::vector<Vector2<T> >& v)
{
bool inside = false;
for (int j = 0, i = v.size()-1; j < v.size(); i = j++) {
if (v[i][0] >= p[0] || v[j][0] >= p[0]) { // At least one endpoint >= px
if (v[i][1] < p[1]) { // y1 below ray
if (v[j][1] >= p[1]) { // y2 on or above ray, edge going 'up'
if ((p[1]-v[i][1])*(v[j][0]-v[i][0]) >= (p[0]-v[i][0])*(v[j][1]-v[i][1])) {
inside = !inside;
}
}
} else if (v[j][1] < p[1]) { // y1 on or above ray, y2 below ray, edge going 'down'
if ((p[1]-v[i][1])*(v[j][0]-v[i][0]) <= (p[0]-v[i][0])*(v[j][1]-v[i][1])) {
inside = !inside;
}
}
}
}
return inside;
}


The std::vector<> argument holds the vertices of the polygon in CCW order. For a large map, this could be optimized by sharing edge calculations, and/or using an underlying grid to quickly narrow down which polygons need to be tested.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this