Pithon Protector’s journey 🐍 🎮

In this class, Python Math Entrepreneurship, Andrew, Adrian, and I (Jonny) created the team. Our mission is to create a fun and educational game to help the underserved communities and enhance their learning. This game that we are making is free and aims to help middle school students. After discussing it for a while, we finally chose to make a tower defense game with math implemented into it which will probably be called Robots vs Math. We chose the name PiThon Protectors later on, for a few reasons. “PiThon” represents the coding language that we are writing this in, with a “Pi-” instead of “Py-” to implement the math aspect into our name, and finally “Protectors” because we are making a tower defense game where we “protect” our exit from enemies.

After finalizing our team name and the game we are making, we started working on it. First, we created the map and tower designs, then learned more about pygame. We loaded the images into the game file first, then created a window for the game. Then, we made “enemy” and “tower” classes. We split into two groups, one focusing on enemy movement, and one focusing on tower shooting. For the enemy movement group, we made “waypoints” for the enemies for a map, and at first, just set random points. Then we made enemies go to each path. If there are multiple paths for the map, it creates a random path for the enemy to go. For example, the map “Gift of Nature” had 3 different paths, and the enemies, consisting of only skeleton and ghost enemies at that point, were each given a random path from those options. If it reaches the end of the path, the enemy gets deleted. For the tower shooting group, we used math to calculate if a tower is in a range, although we didn’t make the towers shoot projectiles yet.

After tower shooting and enemy movement, we split into two different groups, one for the instructions/how to play page, and one for making the main menu with buttons. For the instructions page group specifically, we created a Google Doc and wrote all the instructions. Then we implemented it into the code. We made the instructions scrollable, and made it so that we can change the color/font size of each line of instructions. For now, it is stored in a separate file and is not in the main code. The button group added buttons that started the game. They made one button to click to start playing. We used this code to make the start round button later on.

With small steps like these, we were eventually able to create a working single-player tower defense game. All we needed was to edit the images of towers/enemies(tower sprites were mostly finished, but we only had 3 enemies), and add those to the game. We have a non-scrollable shop that can only display 3 towers at a time, a map, a number of lives, a number of coins, enemies with individual stats, and towers that can’t be placed in certain areas like the map path. With this working game, we were able to figure out which towers/enemies were too strong, and which were too weak. We tweaked their stats to balance them out.

Throughout creating this game, we encountered many difficulties. For example, in the beginning, we either had no experience or little experience with Pygame. We had to learn even the most basic things like importing images and resizing them. We also encountered many bugs when adding new things, which caused us to backtrack at times to fix them. Once, we multiplied the enemy list by a number, which caused them to re-spawn at the point where it died every time it encountered an enemy. For example, if we had an enemy list containing enemy1 and enemy2, and we multiplied it by 5, the list would become enemy1, enemy2, enemy1, enemy2, enemy1, enemy2, enemy1, enemy2, enemy1, and enemy2. That means every time enemy1 gets destroyed, the next time it spawns, it spawns right where it just got destroyed. This caused a game crash, and we had to backtrack a lot in order to fix this. Another example of a difficulty is when we were creating the lines of instructions. If we wanted to change the font size, we needed to change the spacing of each line, or the text would overlap. We also had to manually change the font sizes of certain lines.

Essentially, PiThon Protectors learned a lot since we launched almost 9months ago. First, we learned a lot about Pygame and Python. We learned the basics of pygame. As we went on and gained more experience, we started to learn more about pygame and the different things you can use it for, including writing text onto the screen and scrolling it up or down. The more we learned and the more we worked, the closer we got to making a fully functional game. About Python, some of us learned about classes, and how they work. Some never knew you can use var += 1 instead of var = var + 1. Same for var *= 1, var /= 1, and var -= 1. We learned that you can’t put code anywhere after something happens and hope it will succeed. For example, in the loop of spawning enemies, if we just make the game wait one second there before spawning anything, everything will stop for one second, instead of only being used to delay the time taken between each enemy spawned. We also learned how to make it so that the game detects when the player clicks something with their mouse, which was used when we created the start game and start round buttons. These are just a few of the many things we learned throughout taking this class.

Develop mastery in technical and collaborative skills; Empower young leaders to drive change in communities