Minecraft, Graphics and Game Design

It’s great to see people’s imaginations fired up after they learn a new coding skill, and I often get asked how difficult it would be to make Minecraft / Flappy Bird / Portal, etc. Although the games they want to recreate are often complex, the ideas behind them sometimes aren’t as complicated as they think.

For example, last year I made a very (very) simple 2-dimensional clone of Minecraft in Python (using Pygame):

Minecraft 2D

In this game, the map is stored as a 2-dimensional list of resources, and the graphics for each resource  are stored in a simple dictionary:

#a dictionary linking resources to textures
textures = {
               DIRT : pygame.image.load('dirt.png'), 
               GRASS : pygame.image.load('grass.png'),
               WATER : pygame.image.load('water.png'),
               BRICK : pygame.image.load('brick.png')

This means that the game graphics can easily be modified, just by editing the images:

Moderately improved graphics

New resources can also be added to the game, by adding them to the relevant lists and dictionaries, and a dictionary of ‘crafting rules’ tells the game which resources can be made from others:

#rules to make new objects
craft = {
            BRICK : { WATER : 1, DIRT : 2 }

I’ve put these challenges together into a new (beta) Code Club project, which can be accessed through the Python projects section of the website. If you’re a volunteer, feel free to try this project out with your club and let me know how you get on: projects@codeclub.org.uk (or use the feedback form on the website). I’d also love to see the finished games that your coders create!