How to do a risk-like map?

Started by
3 comments, last by Zakwayda 18 years, 4 months ago
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
Advertisement
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).
enum Bool { True, False, FileNotFound };
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
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
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[0] >= p[0] || v[j][0] >= p[0]) { // At least one endpoint >= px            if (v[1] < p[1]) { // y1 below ray                if (v[j][1] >= p[1]) { // y2 on or above ray, edge going 'up'                    if ((p[1]-v[1])*(v[j][0]-v[0]) >= (p[0]-v[0])*(v[j][1]-v[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[1])*(v[j][0]-v[0]) <= (p[0]-v[0])*(v[j][1]-v[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.

This topic is closed to new replies.

Advertisement