Dodge

This is the first part of a series of posts where I will be going back through old github repos, revamping them, and doing a little retrospective. We begin today with Dodge.

Intro

I made Dodge in my senior year of high school as a part of a game development class. Our teacher supplied us with some initial assets and logic, all of which I threw away. I had, in a previous semester, done work in two other classes which came together into this project: 2D Graphics and Modeling and Simulation. In my 2D Graphics class I made the DoubleBufferedCanvas class that I ended up using wholesale (this class also appears in many of my other projects). In Modeling and Simulation I did the physics work to simulate gravity by modeling acceleration and velocity vectors. Throwing these two things together, along with collision detection, resulted in a pretty easy game.

Retrospective

After fiddling with the newest IntelliJ IDE for about an hour, trying to get it to download and use my code, I finally was able to launch the project. But, to my chagrin, the canvas painted exactly one frame and froze. After inserting a copious amount of System.out.println("ASDF"); I traced the problem to an if statement in the run method of the Runnable DoubleBufferedCanvas. It seemed that my previous decision to keep track of state in a global variable called initialized caused the compiler to optimize out the entire interior of the if statement: aka all the logic that made the program run. By removing this if statement I don’t think I caused any harm, and allowed the program to actually work. At least it never crashed any time I ran it after. This was fixed in 70b96a3.

Another interesting insight: I had my roommate and my girlfriend play the game (for fun) once I got it working. They both immediately discovered a bug that I never once found anytime I played the game: if you hit the ‘start’ button (space) after you had lost a game, it would start going again, counting your score up just the same, doing everything just the same. This allowed a player to get indefinite score, even if they crashed into an object, by just hitting ‘space’ and starting the game up again. I played this game many, many times in high school while testing it, but I never once found this bug. They both found it in their first play through. Speaks to how a developer can be blind to their own mistakes sometimes.

Conclusion

Anyways, this was a fun little project I made in high school that didn’t take much work since I swiped previous code I’d done. Downloadable as an executable jar here if you want to give it a try!

Written on February 18, 2017

Leave a comment!