Home > Books > Mission Python > Adding an atmospheric soundtrack

Mission Python: Adding real sounds from Mars to the Escape game

NASA's InSight Mars lander arrived on the surface of Mars in December 2018, following a six month journey. The lander's instruments will look for tectonic activity on the planet and meteorite impacts, study how hot the planet surface is, and track the planet's wobble as it orbits the sun. The lander is an utterly incredible technical achievement.

InSight Mars Lander

An artist's impression of the InSight lander working on the surface of Mars. Courtesy of NASA/JPL-Caltech.

One of the first pieces of data it's returned is a recording of Martian winds, picked up by the seismometer. I had a sense of awe when I heard the recording of sounds captured so far away.

I thought it would be fun to add NASA's sound recording to the Escape game from Mission Python, so that players can hear real sounds from Mars when they step onto the planet surface. Half of the game map is set aside for the area outside the space station, to help create a sense of the vast, unpopulated Mars when you step out of the crammed and contained space station.

I've created code to play the Mars atmosphere sounds when you're on the planet surface. The easiest way to do this is to add code to the start_room() function, which runs when the player enters a new room. To avoid the sound being audible inside, the code stops the atmosphere playing, and then starts it if the player is on a planet surface room. Stopping and starting the sound can lead to audible pops, which might be fixable by only stopping and starting the sound if moving between inside to outside rooms, but that would require more extensive edits to the code, including using a new variable to remember the old room number. The pops aren't too distracting in the context of the static-like Martian wind.

Here's the code to add at the end of the the start_room() function:

### Additions to enable atmosphere sound to play on planet surface
if current_room in outdoor_rooms:

The sound effect is called mars_atmosphere.wav and needs to be added in your sounds folder. The sounds.mars_atmosphere.play(-1) instruction sets it to repeat indefinitely, so it keeps playing if the player stands still on the planet surface. Although the untreated recordings are audible to humans, they're very bass-heavy so NASA also made a version that's easier to hear on the typical computer device by upping the pitch by two octaves. That's the sound recording I've used.

Click here to download the sound effect and the modified Python file for the game. I've re-enabled the teleporter in this version of the game, so you can easily jump to a planet surface room by pressing X and entering a room number between 1 and 25. Remember that you'll need to switch to the command line window to enter the destination room number.

Thanks for NASA/JPL for making these sounds available for use in projects such as this, and for the inspirational work they carry out too.

Find out more about the sounds from the InSight Mars mission

Find out more about Mission Python


© 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!

Discover my latest books

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Coder Academy book

Coder Academy

Learn to make games and other programs in Scratch, and make a web page in HTML. Highly interactive book for 7-10 year olds.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Blog | Copywriting Services | Books | Free book chapters | Articles | Photos | Games | Shop | About