Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to align up images when drawing map of europe  (Read 1696 times)

0 Members and 1 Guest are viewing this topic.

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
How to align up images when drawing map of europe
« 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



Here is South Spain



Here is west Spain/Portugal



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



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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to align up images when drawing map of europe
« Reply #1 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: How to align up images when drawing map of europe
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: How to align up images when drawing map of europe
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/