Help me draw a map
Has anyone ever played Risk? or the full campaign mode from Shogun: Total War?
What I'd really like to be able to do, it to be able to have a map drawn to a window, and for the program to be able to tell what the boundries of each country are, so if I click on England, it will know the difference between that country, the sea surrounding it, and the many other countries around the world.
Now, I have succeeded this in part, by creating countries with straight borders and using the coordinates of all the points of each country could mathmatically work out where the user had clicked, but what if I wanted to use an actual map of the world with squiggly borders?
I'm not really asking for someone to tell me how to do it, just point me in the right direction because I don't have a clue :(
There have been threads on this before, but I can't think of suitable search terms. In the case of both the games you describe, the map is political, so you could just draw each country in a different colour and have a map from the colour value to the country. If you draw it as a BufferedImage, it's easy enough to work out the co-ords of the click and get the colour. (For physical maps, this approach can be adapted to have a second image, off-screen, which you use for the lookup).
Hello Dan-Forever.
If you have every country as a polygone. And you have all the coordinates of every corner in those polygones then you can take the point clicked and draw a line from it and one line through it like a T with the clicked point beeing the point where the two meet. You then check every two coordinates building up a line (polygone by polygone) in your map, and check if your two lines cross it. If the total sum of crossings are odd this means your dot where inside that polygone, if not it means the clicked dot where outside of that polygone. When one polygones been checked you take the next one and so on.
> Hello Dan-Forever.
> If you have every country as a polygone. And you have
> all the coordinates of every corner in those polygones
> then you can take the point clicked and draw a line
> [snip]
Or.... you could just call [url=http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html#contains(int,%20int)]Polygon.contains()[/url] as I said.
Dan, I was looking forward to create a risk java version game, It took me a while to figure it out, since risk in Brazil is called "War". If you'd like to share some info: carvalho.vinicius@superig.com.br