Project Description
Shape Scramble is a 2D shooter game programmed in python that implements math concepts involving vectors and matrices. The objective of the game is to survive for as long as possible while enemy shapes chase you. You gain points by shooting enemies and collecting triangles, and lose points when you collect red traingles, enemies collide with you, or your shots hit the boundaries. This is a class project, and the concept is not original.
Accomplishments
- Built an optimized collision system which performs a simple check to decide whether to run more complex calculations.
- Programmed accurate 2D collision detection between circles and polygons.
- Produced all of the sound effects myself.
Objectives and Implementation
My primary goal for this project was to build the program according to the specs of the assignment, but also, I wanted to find out if I could increase the accuracy of collision between shots and enemies. While programming the assignment, I struggled with the idea of how to determine collision between the player's shot and polygons with sides greater than four. This was not a problem that was solved in class, and using the approximations that I had learned resulted in what I felt was janky gameplay. I spent most of my time with this project on developing an algorithm to remedy this.

First, the game would detect collision between the shot and an axially-aligned bounding box. If the colliding shape was a square, the collision would immediately return true. If the colliding shape is a triangle, the code jumps to the further step of calculating circle-triangle collision. If the colliding shape is any other polygon, the program calls the more intensive circle-polygon collision function to determine whether a collision occured.

This code applies the same methods used to determine collision between a circle and a triangle, but for an entire polygon. The function determines the total area covered by triangles that span from the circle's center to each point in the shape, then subtracts the area of the circle's sector that was counted in this calculation. If a collsion occurs, this should result in the total area calculated being less than or equal to the actual area of the shape.
Reflection
While it seems like this solution may not be perfect in practice, it did result in significantly improved collision detection. Working on this project taught me how useful documentation can be. I would come back to the above function many times and forget exactly how it worked, causing confusion and costing me time. Eventually, I added in the comments you see that help to walk through the logic, which made it much easier to come back to working on the project after breaks. Working on this project also reiterated to me how passionate I am about both problem solving and game development. I greatly enjoyed working through the solution to my issue and I also had fun with the whole project, creating custom sound effects and implementing the specified mechanics in my own interpretation.