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 book Mission Python shows you how to build a space adventure game, in which you collect objects and use them to make your escape from a space station. Part of the challenge is to find the right objects, spread across the space station and sometimes hidden from plain sight.
There are three ways to hide collectable objects (called props) in the Escape game from Mission Python:
In this article, I'll talk you through them. The book explains how the code works in more detail, but even if you haven't read the book, you can use the code here to add the Easter egg hunt to the game. If you haven't read the book, download the PDF sampler of Mission Python for instructions for getting started, including details of how to download and install the game. Mission Python is available to buy now, including in ebook for immediate delivery direct from the publisher.
The simplest approach is to position a prop behind a piece of scenery. To make sure the game is fair and players don't have to examine every hidden floor space to find something, you should ensure that the object is still partially shown. In room 39, pictured below, I partially hid the spoon behind the table. I considered hiding the hammer behind the robot arm in room 50 but wasn't sure that would be clear enough to be fair, given that players wouldn't have seen any other robot arms by that point in the game, and might just think the hammer was part of the arm. You can have some fun repositioning objects so they're partly obscured by other objects. Use the map here for inspiration!
Crew's quarters, showing a spoon partially hidden behind a table
Alternatively, you can position a prop inside a piece of scenery. When the scenery is examined, the prop will be discovered. For example, prop 76 (scissors) is located in room 41 (shown below) at y=3, x=5 (coordinates are numbered from the top left, starting at 0 and including the spaces occupied by the wall). The scenery for room 41 also includes item 10 (a cabinet) at that position. So, if you examine the cabinet, you'll discover the scissors. It's important to give players a strong hint about where to search, either by introducing a new and distinctive piece of scenery or by making the scenery something that naturally can contain things. The game would be frustrating if players had to examine every piece of wall or table to find an important object.
The sick bay in Mission Python, with cabinets you can hide things in
The third way you can hide things is to randomly position them. An earlier iteration of the Escape game included a puzzle where you were trapped in your bedroom and had to find the access card to get out. The card was positioned somewhere randomly in your untidy bedroom, hidden in a random piece of scenery. I received feedback that this wasn't especially enjoyable, and took it out when redesigning the map. Games like Animal Crossing have shown that search puzzles can be fun, though, provided that there's enough of a hint to the players so that they don't have to search everything. You can hide inessential items as a reward to players who explore the game more fully.
I'm going to show you how to add an object to Escape and how to randomly position it, so that you can have an Easter egg hunt on the space station.
###############
## OBJECTS ##
###############
objects = {
0: [images.floor, None, "The floor is shiny and clean"],
--snip--
81: [images.access_card, None,
"This access card belongs to " + FRIEND2_NAME, "an access card"],
82: [images.egg, None, "This chocolate egg looks delicious!", "an Easter egg"]
}
items_player_may_carry = list(range(53, 83))
###############
## PROPS ##
###############
# Props are objects that may move between rooms, appear or disappear.
# All props must be set up here. Props not yet in the game go into room 0.
# object number : [room, y, x]
props = {
20: [31, 0, 4], 21: [26, 0, 1], 22: [41, 0, 2], 23: [39, 0, 5],
--snip--
78: [35, 9, 11], 79: [26, 3, 2], 80: [41, 7, 5], 81: [29, 1, 1],
82: [31, 3, 3]
}
### commented out following code to add EASTER EGG ###
##checksum = 0
##for key, prop in props.items():
## if key != 71: # 71 is skipped because it's different each game.
## checksum += (prop[0] * key
## + prop[1] * (key + 1)
## + prop[2] * (key + 2))
##print(len(props), "props")
##assert len(props) == 37, "Expected 37 prop items"
##print("Prop checksum:", checksum)
##assert checksum == 61414, "Error in props data"
standard_responses = {
--snip--
75: "You are at Sector: " + str(current_room) + " // X: " \
+ str(player_x) + " // Y: " + str(player_y),
82: "You nibble at the chocolate. It tastes divine!"
}
You should now be able to start the game as usual, and see the Easter egg in the start room. You can pick it up, drop it, and use it to eat a piece.
You can now hide it behind scenery by changing the room number and y and x positions for the egg (object 82) in the props list (see Step 4 above).
To add more eggs, add additional objects (83, 84 etc) that use the same images.egg file.
The next step is to hide the Easter egg in a random piece of scenery, so it is revealed when that scenery is examined. Below is a new function for hiding objects in the scenery in a room. You tell it which object to hide, and which room to hide it in. The code chooses a random piece of scenery to hide the object in. Remember to provide a strong hint about which room an object is hidden in, so that players don't waste time hunting in rooms where nothing is hidden. For example, you could modify the room description to say there's a lovely chocolatey smell here.
I've included an instruction to hide the Easter egg in the crew's quarters (pictured at the top of this page). You can easily find this room, and there's a map of the Mission Python game here if you get stuck.
Add this code before the START section, near the end of the program.
########################
## HIDING OBJECTS ##
########################
def hide_object(room_number, object_to_hide):
# this function puts an object into a place where there is already a piece of scenery
# it can be used for hiding things in a random location in a particular room
# for example an Easter egg in the crew room
global props
number_of_items_in_room = len(scenery[room_number])
item_to_hide_in = random.randint(0, number_of_items_in_room - 1)
print(item_to_hide_in)
props[object_to_hide][0] = room_number
props[object_to_hide][1] = scenery[room_number][item_to_hide_in][1]
props[object_to_hide][2] = scenery[room_number][item_to_hide_in][2]
hide_object(39, 82) # hide object 82 (egg) in room 39 (crew community room)
You can download the modified game including a hidden Easter egg here (right-click that link and use Save As to download the file). It downloads as a .txt file, so you'll need to rename it to a .py file.
Happy hunting!
© 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.