Let's say you are a person who is particularly sensitive to the issues of energy sustainability and responsible consumption.

And let's say you've recently read that even small gestures are important to reduce electricity consumption, such as turning the lights off when you leave a room.

Supplementary readings: Top 5 Steps to Reduce Your Energy Consumption by Harvard University and The 10 Biggest Energy Wasting Habits At Home by Alliance to Save Energy.

Let's suppose also that you like computer programming and videogames programming, with Scratch in particular.

One day you decide that it’s time to make a difference and raise awareness among your friends and even the youngest ones about energy saving issues: but how to do it?!?

Got an Idea!!!

You’ll make a videogame that raise people’s awareness and stimulate them not to waste energy.

Yes, but what videogame?

It could be a quiz where the player, faced with a series of situations, must choose between good behavior and wrong behavior. For example: for a long time you want to buy a radio-controlled car and you can choose between a car powered by disposable batteries, another powered by rechargeable batteries and one powered by solar panels. Which one do you choose?

Another could consist in a simulation game where the player has to impersonate the Mayor of a small town who has a budget available to install plants for the production of electricity and must choose from time to time the most appropriate plant (or the combination of them) for the needs of his city in respect of the budget: wind plant, coal-fired plant, solar panels, etc.

And again, a game where the player has to turn off the lights of a house that turn on when a person randomly enters inside a room: the goal is to save the energy and make the consumption counter sign a lower amount of energy consumed at the end of the game.

The game and its rules

After a careful evaluation of the possible ideas based, for example, on the complexity of the game, the time you can spend developing it, the appeal that you think it may have on the players and after consulting with your friends and your computer class teacher, you decide to opt for the latest idea.

Now you have to decide the rules of the game: the house simulated in the videogame consists of 3 rooms. When a person goes into a room she turns the lights on. As long as the person is inside the room the player cannot turn the lights off: if the player turns the lights off while the person is still in the room, the game ends and the player has lost. While the lights are on, the consumption counter is on: for each hour in which the lights remain on, the counter measures a consumption equal to 0.03 KWh. The player who at the end of the count down (30 sec = 30 h) consumes less electricity without leaving the inhabitants of the house in the dark will win.

Now that you have established the rules, you can start coding.


First you need to get the materials: the sprites and the background.

You can draw them with the Scratch editor, or with your hand, or search for images on the Internet and then import them into Scratch.

If you import your design or you look for images on the Internet it is likely that you’ll need a tool to remove the background. You can use the same Scratch editor, or the tool in the latest versions of MS Office, or even the free tools available online such as RemoveBg.

Or you can import vector images in the native Scratch format (.svg): usually this type of images are more appealing and give the game a more professional look. Free SVG and Clker are a couple of sites where to find them.

If you use images from the Internet, pay attention to the type of license they are released: if the images are covered by copyright you will probably need to buy them in order to use them. If they are covered by a Creative Commons license (or a license that grants you free of use) you will need to follow the license type requirements: for example, you will need to mention the author in the "credits" section of your videogame.

Divide et impera!

Now that you have retrieved all the resources you need you should try to highlight all the aspects of the videogame that will have to be translated into programming steps: remember that even the most complex problem can be addressed by breaking it down into many simpler problems:

Supplementary reading: Divide-and-conquer algorithm by Wikipedia.

What problems will you face?

Problem 1: a person must appear in one of the three rooms and turn the lights on inside that room and only inside that.

Problem 2: people must remain within the perimeter of the house without materializing behind the walls. It is not a videogame that deals with ghosts!

Problem 3: when the switch is pressed, the room lights turn off.

Problem 4: if the player turns the switch off before the person has left the room,  the game ends.

Problem 5: when the lights are switched on, the consumption counter starts.

Problem 6: when the player turns the lights off, the consumption counter stops.

Problem 7: when the countdown reaches zero the game ends and the consumption counter shows the total consumption expressed in KWh *.

The solution

Of course there are many different solutions to these problems (and consequently many possible algorithms). After a careful evaluation of the solutions based on your computer skills, the time you have to spent and your knowledge of Scratch, choose the solution to implement.

Remember that, usually, the simplest solution (which is generally the one that requires less code) is always to be preferred.

Here you can find the link to the videogame created with Scratch:

* For the consumption calculation you can assume that each of the light bulbs consumes 10 Watts (3x10 = 30 Watts in total) and that the timer marks the passing of hours instead of seconds (1 h = 1 sec). The three light bulbs within 1 hour consume 30 Watts x 1 h = 30 Wh or 0.03 KWh

Supplementary reading: How to Calculate Kilowatts Used by Light Bulbs by WikiHow.