Gluttonous Healthy Snake
If you ask me, which restaurant do you visit the most often? The answer is definitely “Mcdonald”! I like burgers, chicken wings, fries and of course, cocacola! All these are called “Junk food” in the eyes of my mum. I still remember how many times my mum tried to explain to me, what is junk food and what is healthy food. Like it or not, I can only drink coca cola once a week!
Understanding how difficult it is to persuade young kids not to eat too much junk food, I always want to “invent” sth that could help, a comic, a game? Yes, a game! When I came across the game gluttonous snake, the two combined perfectly in my mind. So, I designed and implemented this small game: healthy snake! The rules were tweaked a bit to echo the theme of the green plan 2030.
The objective of the game is to keep the snake alive as long as possible, without getting too fat due to eating too much junk food, but taking in healthy food and exercising regularly.
What to expect in the game?
First of all, the game will not be played on a computer, but a simple 8x8 neopixel panel, which provides the excellent condition to represent the earth, as earth is of limited space. The snake can cross the boundary to the other side.
The snake represents human beings, who live on earth and solely depend on what earth can provide. It is represented by a red dot for its head and a yellow strip for its body.
The next thing you know, a green, and a purple dot are on the screen. The green and purple dots represent a piece of healthy food and a piece of junk food respectively. There will also be a white dot representing the damaged area and a dark blue dot representing the exercise panel.
How does this game work?
At the start of the game, 3 dots will appear, they are the snake’s head, a piece of healthy food and a piece of junk food. You will have to use the PS2 button to control the movement of the snake.
The snake will grow 1 dot longer by eating either 1 piece of junk food or 12 pieces of healthy food.
An exercise panel will appear when the snake eats 10 foods (it can be a mixture of junk and healthy foods). The snake just needs to go onto this spot to exercise and get rid of one yellow dot from the body.
This game promotes eating less junk food (which causes the snake to grow fatter very fast) and more healthy food like fruit and vegetables (which also helps the snake to grow fatter but at a much slower pace). It also reminds the snake to exercise regularly after taking 10 foods to keep healthy. These rules echo the Goal #3-Good Health and well-being.
A damaged area will appear when the snake eats two junk foods. The damaged area will be removed when the snake eats 5 healthy foods and exercises once.
This rule mimics the fact that human beings have to consider environmental tolerance when people are demanding too much from earth. The rule that allows the damaged area to revive reflects that people not only need a healthy and happy life, but also need to consider the sustainability of the earth we live on. This rule echoes the Goal #11-Sustainable cities and communities.
The snake needs to move fast. Food will be relocated and the exercise panel will disappear when the number of movements exceeds certain thresholds. Here are the limits: Junk food: snake movements = unoccupied dots / 2 Healthy food: snake movements = unoccupied dots / 4. Exercise panel: snake movements = unoccupied dots / 4.
This rule promotes the snake to move minimum steps to reach the food or exercise panel, to reflect that in real life, we waste as little as possible. The healthy and junk food, and the exercise panel will stay in its position only within a limited number of moves the snake passes, otherwise they are considered “wasted”. So if you want to catch healthy food and/or do exercise, plan your route before it is relocated to another place randomly or disappears. This rule echoes the Goal #12-Responsible consumption and production.
When the snake grows too fat, it could use up the space on the panel, like our earth is getting too crowded. The snake may also be moved into the damaged area by the careless player, like the polluted areas on earth. In both cases, the snake will die. The snake may also die if it hits its own body (war?). The symptoms of the snake being dead is the whole body becoming red, followed by a lightshow you can admire.
Final tips.
DO plan the shortest route to get a piece of food or an exercise panel as they will disappear if you travel too long to get them. Remember, the things provided are limited as resources on earth are limited.
DO NOT touch the neopixel panel while playing.
Problems during coding and learning points
I learnt to use “while” loop to continuously monitor if the snake is alive or not, and take in PS2 input to determine the next movement of the snake.
I learnt how to use an array to store the snake’s position. I use array.insert and array.pop to control the length of the snake.
I also use array.count to determine whether the snake came across a lighted dot, be it a healthy food, junk food, exercise panel or damaged area, and even the snake body itself. I used random.choice and array.remove to randomly remove a damaged area. I used array.append to create additional damaged area at a random position that is not occupied.
I managed to map the row and the column into the neopixel panel LEDs index so as to show all changes to the user.
Under the supervision of my father, I learnt how to do analogue to digital conversion so that the program can read PS2 input.
We did encounter some problems while coding.
After I added 1 line of code, the whole snake became red even though it's alive. We found that the error was due to a missing condition to check if the snake really moved 1 step.
Index errors “list elements out of range” popped up and it took us a bit longer to fix it. We found that we didn’t check whether the list is empty or not before removing the last element. So we added an if condition to check it.
In general, I had a wonderful time delivering the project, together with my father. Through every obstacle we overcame, and every milestone we achieved, I have experienced project development life-cycle, and sharpened my Python programming skills. Most importantly, I started to appreciate the Green Plan 2030, and the role that technology could play in conquering the challenges.
Built With
- micro:bit
- neo
- ps2
- python
Log in or sign up for Devpost to join the conversation.