Is there any way for someone to, using PyGame or SDL, to do, say:

00000000
01222100
01112110
01112110
01111110
00000000

And have it display the 0's as a water tile (10x10), the 1's as a grass tile (10x10), and the 2's as a rock tile (10x10)? As to make maps easily. I would supply the tiles, obviously, but is this possible?

Hi linux,

Yes, that is definitely possible. I've done something similar from within both pygame and Tkinter (I used Tkinter to design a GUI program for map editing). You would want to begin by creating a pygame Surface for each of the 10x10 image tiles, then stick all your Surfaces in a dictionary for easy access. I guess the simplest thing to do would be to make the dictionary keys the digit codes those surfaces correspond to - so your dictionary would look like { 0:<Surface object for water>; 1:<Surface object for grass>; 2:<Surface object for rock> }.

Then you'd want to loop through the text map and, for each code, find the corresponding Surface using the dictionary and blit it to a larger background Surface in the correct spot (80x60, given your example text map).

One thing to watch out for if you're moving a sprite over top of these tiles is that you don't redraw each tile with every iteration of the game loop. That will create unnecessary slowdown. Instead, only change the tiles that are being traversed and that are animating - it's best to keep these in their own Sprite Group, and have that group update accordingly.

Hope this helps!

commented: Thanks for the PyGame help! +3

Thanks! I'll definitely be using what you told me as a guideline. This will finally be my motivation for picking up PyGame.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.