AWS Logo
Menu
Disaster Bomb Game: An online survival game powered by Amazon Q!

Disaster Bomb Game: An online survival game powered by Amazon Q!

I am elated to share with you the first game I have ever built to submit for the 2024 AWS Game Builder Challenge, called Disaster Bomb Game. It is built using Python as the primary programming language with the assistance of Amazon Q, a powerful coding assistant bot. I used pygame as the primary library for my game to create a dynamic graphical user interface for players. I also integrated both Amazon S3 and Amazon DynamoDB as valuable tools for storing, tracking, and processing game data and assets.

Published Dec 19, 2024
Last Modified Dec 24, 2024
Cover photo credit: TV Asahi Video

Inspiration

Disaster Bomb Game was heavily influenced by episode 502 of the popular Japanese manga/animated series Doraemon (ドラえもん), titled "Incident Bomb (ジケン爆弾)". In this episode, Doraemon, the cat-like robot from the future, sees his friend Nobita's incomplete diary with only a few repetitive lines that he is supposed to write for his summer vacation homework. Nobita complains that he has nothing to write in his diary and asks if he has something fascinating and interesting to write in his diary. Doraemon later takes out "Incident Bomb", which is a futuristic technology gadget that tells him about future incidents that are scheduled to happen. The bomb has a red and a blue cord attached to it. Nobita is also given a scissor to cut the correct cord within a given time frame. If he cuts the correct cord (bomb fuse), he can avoid the incident by coincidence. If not, the bomb will explode, and the predicted incident is guaranteed to happen. When Nobita presses the button to activate the bomb, he is warned with the first incident, "In 30 seconds, your mother will be mad at you". As a kid who is frequently afraid of his mother, he is put into a difficult situation where he has to cut the correct cord without knowing which cord is correct. After he cuts the correct cord randomly, he avoids being scolded by his mom for his poor test scores. The bomb then keeps following Nobita and tasking him with a series of incidents, and he has to keep cutting the correct bomb fuse to either avoid or accept the incidents by fate until the end of the day. I have watched this episode and learned the logic and functions of the bomb gadget that the two main protagonists use in this episode and tried to implement them for my game.

Game description

This game is the online version of the "Incident Bomb" in Doraemon. In this game, the player will play a role in the Bad End World, with multiple disasters can occur. The task is simple. The player will choose the correct colour of the bomb fuse/cord to cut to prevent the disaster from happening within 30 seconds. If, within 30 seconds, the player chooses the correct colour, the incident will be prevented. If the selected colour is incorrect or the player fails to select a colour within 30 seconds, the incident will occur as predicted. There will be three sets initially for players to choose, a set of 10, 15, or 20 scenarios. The set of 10 scenarios will have two colours (red and green) for players to select. The sets of 15 and 20 will have three and four colours (red, green, yellow, and violet) for players to choose, respectively. The correct cord is unknown. For each set, the player has to pass at least 60% to win the game and "save the world". There will be a limited number of "helps" that help the players cut the correct bomb fuse and prevent the disaster scenarios in each set.

Game purpose

There are often problems in life with constraints where we need to make ultimate decisions to solve them. A lot of them require some fortune and luck to solve to be successful. In the Disaster Bomb Game, you will be playing a hero/agent in an imaginary world to make decisions to save the world. Your time is limited, so you have to make an ultimate decision, and your chance of success will be based on your choice with some luck. This game is designed to train your brain, decision-making, problem-solving skills, patience, passion, and persistence to prepare you to handle real-life situations. I hope that you will enjoy it.

Game building process

Amazon Q Installation and Setup

I started with installing the Amazon Q extension for my VS Code editor. Then, I authenticated my AWS identity and learned how it works by working with small, simple programs.

Logic/Backend Implementation

The next step I did was to implement the game logic based on the game description. Everything was done in Python and tested in the VS Code console with the assistance of Amazon Q Developer. The list of more than a hundred scenarios is stored in a separate file to be read and chosen randomly from the main program for players.

DynamoDB Implementation and Integration

When I felt like the game logic worked as expected, I implemented a function to store the player's data in the Amazon DynamoDB database. The database initially only saved items of two attributes, player ID and score, with the player ID being the primary key. Its code structure would look something like this:
First, I configured my AWS credentials according to the AWS Toolkit for VS Code User Guide. To integrate a Python application with any AWS services, Boto3 has to be installed first using the following command on the VS Code terminal:
After successfully creating and configuring my IAM credential, which allowed it full access to DynamoDB, S3, and other services, I made the database directly on AWS DynamoDB. This step is where we need to be careful because if the database structure (attributes, settings, names, etc.) is not correct, the program will not successfully store the data. Make sure the created database aligns with everything in our program.

S3 Implementation and Integration

I also wanted to utilize Amazon S3 in my program because S3 is best for storing and retrieving data and is known for optimized throughput. I initialized the S3 client and created a function to store game data in an S3 bucket like this:

Pygame/Front-end Implementation and Design

To create an attractive user interface design for players, I utilized the Pygame library, with full of fascinating components, items, shapes, and features. I used this command line to install Pygame into my VS Code:
I implemented the screen settings, the desired colours and fonts for my game:
Then, I edited and refactored my game loop and logic and directed all inputs and outputs to the Pygame console instead of the VS Code console. I also implemented a 30-second timer for each scenario while the game was active. The testing process of my game was performed on the Pygame console. To enhance the game's visual and player's experience a little bit, I also added some generated AI visuals and depictions of imaginary worlds as backgrounds. Initially, the game read user inputs from keyboards. However, later, I refactored my code and made my program accept user inputs from clicks instead of keyboards, enhancing the gaming experience.

Cumulative Score and Best Score

To enhance my game's scoring system, I added some functions to calculate each player's cumulative score and best score. The game calculates a cumulative score for every scenario and game set that the player passes and resets when the player loses a game set. The best score is initially updated when the player completes the first game set and then continuously updates with a higher cumulative score.

Enhanced DynamoDB and S3

Instead of manually creating the DynamoDB database and S3 bucket on AWS, I implemented some functions to create the database and S3 bucket if they do not exist yet:
S3
DynamoDB

Challenges

The most difficult challenge while working on this project was the syntax of Pygame and AWS services like Amazon S3 and DynamoDB, and since this is the first time I learned Pygame and AWS in Python programming. But with the assistance of Amazon Q Developer, I was able to learn from its error and code explanations and debugging sessions. I continued to make changes to my game the way I desired to complete my game as much as possible. Another challenge I faced was the cumulative and best-score verification because, after multiple tests, the program sometimes failed to retrieve the correct cumulative and best scores of players. Still, Amazon Q Developer has helped me write debug statements to identify where the problems lie and fix them accordingly.

Utilized tools

These are the Amazon Web Services (AWS) tools that I have utilized and implemented for Disaster Bomb Game:
  • Amazon Q Developer: Amazon Q has played a significant role in helping me finish my code, assisting me where I struggled in my game development process, generating practical methods and functions, analyzing and explaining my code, and helping me debug my code and generate proper debug values to help me track my code execution whenever my game does not work as expected. I consulted with the Amazon Q Developer chatbot frequently during my game development process. Even though Amazon Q Developer might make mistakes sometimes in analyzing, generating code and helping me fix my programs, it still provides several advantages such as capability, adaptability, flexibility, and reliability.
  • Amazon S3: I implemented S3 to store game data in a bucket as an object. Initially, I created the S3 bucket myself on AWS so that my program could automatically store game data in the existing bucket. Then, with the assistance of Amazon Q Developer, I implemented a function to create the S3 bucket if it did not exist yet. S3 simply stores and retrieves data in text files. Some Amazon S3 advantages are high scalability, security, low cost, ease of migration, and simple management.
  • Amazon DynamoDB: I implemented Amazon DynamoDB in my game to store game data like player ID, scores, chosen set, and winning/losing status in the form of tables, items, and attributes based on my knowledge in my Database Systems course. Initially, I also created and configured the database on AWS for my game to store, track, and process game data in the existing database. Later, I also implemented a function for my program to create the database itself if it does not exist yet, with the assistance of Amazon Q Developer. Beyond allowing the user to store data, DynamoDB also enables users to search, retrieve, and sort data quickly based on keys and attributes. It also offers scalability, fast performance, complete management, security, and full-grained access control.
Beyond AWS tools, another significant tool or library that I used for my game is Pygame, a robust cross-platform set of modules that includes computer graphics, animations, and sound libraries to write video games. It allows me to design attractive assets and components of my game and include attractive visuals that can provide players with the best experience possible. When running and testing my game on the Visual Studio console, I had to use my keyboard to enter inputs. However, with the help of Pygame, the players will be able to control the game with clicks instead of keyboards.

What I learned

Throughout this project, I have gained more programming experience in a language that I barely used, like Python. I also gained game development skills with Pygame, and most significantly, I learned more about the usefulness of AWS tools like S3 and DynamoDB, which store, track, and process application data so developers can utilize them to solve problems that relate to multiple things like software and security. I will use all the knowledge and skills that I have obtained from this project to build more fascinating video games in the future.

Next steps

If possible, my next steps may be to deploy my game to a web game or a game application that will be accessible to everyone using tools like AWS Amplify Hosting or AWS Elastic Beanstalk if I have more time and resources to learn and utilize them.
Player has to choose the correct colour to cut the bomb cord and prevent the disaster from happening. For each correct, player receives 10 points.
 

Comments