SFML community forums

Help => Graphics => Topic started by: starkhorn on August 22, 2013, 10:53:15 pm

Title: How to align up images when drawing map of europe
Post by: starkhorn on August 22, 2013, 10:53:15 pm
I'm trying to do my first c++/sfml game. :)

I love RISK/Total War type games so I thought to do a simple war game based in Europe. So I want a map of europe made up of individual images of each region...so when one side captured a region, I can easily change the colour of that region etc.

So I've got a png for each region.

For example

here is North Spain

(http://i39.tinypic.com/ogwexi.png)

Here is South Spain

(http://i44.tinypic.com/32zuvt1.png)

Here is west Spain/Portugal

(http://i42.tinypic.com/2w4h0r7.png)

Here is what I want displayed on the screen, i.e. all 3 regions aligned up correctly.

(http://i42.tinypic.com/iqwies.png)

So now I'm trying to figure out how to display them all in the correct places, so they look like a real map of europe.

My thinking here was to use a tile map system which would be configured via a text file., i.e. each image = a rectangle with no background colour outside of the borders of each region. Tile-map and image file dimensions are equal in width/length.

My concern is how to align up each image so that they fit nicely, i.e. say for the spain/portugal region, my txt file would be as below. The number would be the region id (each region has the image file as a field). Then I would draw the image file at the location of the tilemap.

1 = North Spain, 2 = portugal, 3 - south Spain.

x,1
2,3

The N Spain (region 1) image file contains the part of the region that should cover the top of Portugal. But if I program something like above then how can I avoid portugal "sticking out" by 100 pixels to the left of N Spain?
Title: Re: How to align up images when drawing map of europe
Post by: Nexus on August 22, 2013, 10:59:05 pm
I don't think a tilemap is a good idea, because the countries are not aligned in a grid. Given a rectangle for every country, you should hardcode the position of the left-upper rectangle corner in the world.

Thus, in a text file, you would have something like:
North Spain: 259 390
South Spain: 281 518
Portugal: 248 432
Title: Re: How to align up images when drawing map of europe
Post by: Ixrec on August 22, 2013, 11:01:06 pm
Why not simply hardcode the map position data into your program?  Do you want to allow players to be able to reposition the regions for some reason?
Title: Re: How to align up images when drawing map of europe
Post by: eXpl0it3r on August 23, 2013, 01:05:32 am
Why not simply hardcode the map position data into your program?  Do you want to allow players to be able to reposition the regions for some reason?
Because external files are easier and cleaner to work with. If you're testing positions, you'll have to recompile the whole application whenever you change something, while with an external file, you simple change it and refresh the data.
And from a code design point of view, you should try to reduce the "magic values" as much as possible.