Pygame - pixel collision map

I am creating a game with pygame, and I need a map where the user can select a country by clicking on it.

Can someone help me?

+4
source share
2 answers

If you don’t find this, I don’t see an easy way to do it - you, of course, start with a world map, - this is a good starting point on Wikipedia: http://upload.wikimedia.org/wikipedia/commons/0/03/ BlankMap-World6.svg

- Ah, according to your comments, you have a map drawn - Yes .. If all you need is to get color per click, it's easier - Choose the coordinates of the mouse click for the mouse click:

e = pygame.event.poll() if e == pygame.MOUSEBUTTONDOWN: pos = e.pos # where "screen" is your variable holding the screen surface color = screen.get_at((pos)) 
+4
source

If each country has a different color, and you know it, you can detect it with:

 import pygame pygame.init() screen = pygame.display.set_mode([100,100]) print(screen.get_at([50,50]))#returns tuple with color values pygame.quit() 

Hope this helps solve your problem.

0
source

Source: https://habr.com/ru/post/1332910/


All Articles