< Prev  |  Home  |  Next >

Images

We now have a game map that we can display, but the graphics aren’t very good. Rather than have coloured squares for the different resources, it would be nicer to have images.

Open a program to create images (paint, photoshop, etc.) and create a new 40 pixel by 40 pixel blank image. You can then draw how you’d like the dirt to look in your game. Here’s my dirt image, which I have drawn using Adobe Fireworks:

Making dirt

Once you have a suitable image for each of your resources, you can then just change your ‘colours’ dictionary, associating resources with these new images, instead of just the colours:

I’ve changed the name of this dictionary to ‘textures’, as now we’re not linking resources to colours. The other thing we need to change is that we are now going to have to draw images for each of the tiles, and not rectangles. You can replace the line drawing the rectangles with the following:

‘Blit’ just means copy the image to the display surface. Notice that we only need to pass 2 parameters to draw an image, and not 3. We only need to pass the image to display and the x and y-coordinates to display it at. You don’t need the width and height, as the entire image will be displayed. If you run the same program from the last section, but with the above changes, you should see the following:

Pygame images

Hopefully your images look a little better than mine! If you can’t see your new images on the map, then make sure that you have the images saved in the same place as your program. Here’s the complete code for this section:

Challenge

Make sure that you have a range of different resources, each with their own images. Does the game still look ok if you change the TILESIZE constant to 100 pixels?

< Prev  |  Home  |  Next >