Web Design IES
Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.
My Python programming book Mission Python shows you how to code a space adventure game. The great thing about the game is that the book explains how the code works, so you can customise it with your own map designs and puzzles.
To help you to create your own space station layouts, I've created a PDF map template you can download and print out. You can use it to mark where the exits and walls are on the rooms, and can also annotate it for room layouts and object locations.
While you're playing the game, you could also use this template to build your own map and mark useful locations you might want to return to. (Use the Mission Python free PDF sampler for game installation and play instructions.)
Rooms do not all need to be the same size and do not need to be square. This map template simplifies the layout compared to the real game map. The 5x5 markings on the grid are there to help you add notes and shouldn't be considered tile positions in the room design. A 5x5 room is too small for most purposes.
Note that if you change the room sizes in the final game code, you might cause errors because objects might be positioned outside the walls of rooms. You can remove or comment out the code for scenery and props, or go back to Listing 4-3 to safely build your own map layout and view it using the Explorer code.
Although the space station is fairly compact, you can make it more interesting by having lots of corners to explore. Use this maze generator to get some ideas for possible space station layouts. You'll need to seal off the bottom right wall.
Chapter 4 shows you how the game map is created using a list called GAME_MAP, which contains a list of data items for each room. To define the map layout, you just need to say whether each room has an exit at the top and/or the right. Because all the rooms interlock, the code can look at the adjacent rooms to see whether there is an exit on the left or at the bottom of the room. This code ensures that the map is logical (doors don't disappear after you walk through them) and also cuts down the amount of typing you need to do.
To change the layout of the space station, change the data in the GAME_MAP list, which is shown in Listing 4-1. If you want to make a quick change, the answer to Training Mission #2 in Chapter 4 shows how you can add a corridor at the bottom of the map. You can then add scenery to these rooms as described in Chapter 6.
In the Escape game, room numbers 0 to 25 are on the planet surface, so the space station locations start at room number 26. There is an exit at the top of room 26 onto the planet surface. I recommend you keep this.
If you don't want to use the planet surface locations, the simplest thing to do is to block the exit to them. The exit onto the planet surface is in room 26. Change that room's entry in the GAME_MAP list so it doesn't have a top exit. Note that you'll need to remove the door in room 26 too (see below). You can then use room numbers starting at room 26 and extend the map downwards to make a game that is completely indoors, without making any further code changes to account for the planet surface.
If you prefer, you can reclaim room numbers 0 to 25 for your own use. Their room data is generated automatically. You can remove the code that does this, shown in Listing 4-1, if you want to add your own room data for these locations. You will need to add a list entry in GAME_MAP for each room in the map.
The scenery for the first 25 rooms is also generated automatically, as shown in Listing 6-2. You should remove or comment out this code if these locations are not planet surface locations with fences and random scenery.
In the MAP section of the progam, the instruction outdoor_rooms = range(1, 26) is used to describe which rooms are on the planet surface. Inside rooms have floor and walls, and outside rooms have a soil surface and no walls.
If you change which rooms are outside rooms, you will also need to modify the code that creates the room map, shown in Listing 4-2. This uses room numbers to work out whether there should be a wall at the bottom or side of a room (see bullet 3).
One of the planet surface locations
You can avoid the complexity of removing doors by using any of the game listings before Chapter 11.
If you remove an exit at the top of a room in the final game, note that you may also need to separately remove its door as described on p195 of the book. The location of doors can be seen in Figure 11-1, reproduced below:
To remove a door from the game, change its entry in the props dictionary, so its first number is a 0. For example, to remove the door which is object number 24, make its first list number 0 as shown in Listing 15-6. Any props with a 0 as the first number in their list do not appear in the game (unless this number is changed later on by the program). To remove all the doors, change the first number after the opening square bracket [ to a 0 for each of the props 20, 21, 22, 23, 24, 25 and 26.
props = {
20: [31, 0, 4], 21: [26, 0, 1], 22: [41, 0, 2], 23: [39, 0, 5],
24: [0, 0, 2],
25: [32, 0, 2], 26: [27, 12, 5], # two sides of same door
If you're customising the game, you may also need to remove the code that automatically closes and opens the doors in the engineering bay and the airlock. See p196 of the book for guidance on which code to comment out.
If you create a cool map layout or room layout, I'd love to see it. Please do send me a screenshot and your game code!
© Sean McManus. All rights reserved.
Visit www.sean.co.uk for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!
Web Design in Easy Steps, now in its 7th Edition, shows you how to make effective websites that work on any device.
Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.
This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.
Code a space adventure game in this Python programming book published by No Starch Press.
Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!
In this entertaining techno-thriller for adults, Sean McManus takes a slice through the music industry: from the boardroom to the stage; from the studio to the record fair.