My thoughts on video game design with Java
By Hogan Wong
Want to contribute? Contact us!
By Hogan Wong
NOTE: This article will be updated whenever I make modifications to my game. The game repository can be found here.
Recently, I stumbled upon a tutorial that was about how to create a platformer game (basically, a game where you avoid obstacles and defeat enemies to complete certain levels) in Java. Although Java is not the best language to create video games with (since C++ and C# are more widely used), it's still useful for the sake of this project (see here for some examples of games made with Java).
The tutorial that I used to create this game can be found here. In my opinion, episode #15 can be skipped since it's more of a visual design thing and doesn't really deal with the video game mechanics. Currently, I am using the same sprite designs in the video, but I will eventually switch to my own sprite designs (I still haven't figured out which software to use in order for this kind of graphic design).
Above: Picture of the IDE Eclipse
Below: Screenshot of Visual Studio Code
Before I did anything, I had to make sure Java was installed on my laptop. Although you can download it online, I highly suggest installing Java with a package manager such as Homebrew or Chocolatey as this will make the process easier (I'll write about this someday). If you decide to follow the given tutorial, make sure that you get the latest version of Java since there will be some slight syntax differences between the versions.
Aside from that, installing an IDE (integrated development environment) was a must. Either Visual Studio Code or Eclipse (the IDE specifically for Java) should suffice, but VScode has some slight differences that I found out when I started this project (which I'll mention later).
Although this is not a must, I would recommend understanding the fundamentals of Java/computer programming, which includes stuff such as variable declaration, conditionals (if, else if, else), iterations (while and for loops), creating classes/object-oriented programming, try/catch error handling, and arrays. These aren't too difficult and can be learnt quickly, but it is perfectly fine to learn these coding concepts along the way.
Overall, this experience was fruitful and helped me learn more about Java programming/coding logic in general. Additionally, it taught me how to debug programs in a more systematic way. Instead of asking AI to solve every single coding problem I had (which I used to do before it got way too difficult), I am now able to deduce where an error might potentially be in my code. For example, if the space bar suddenly did not elicit a response on the game screen, I simply checked the player class to make sure that everything was running smoothly.
One problem you might encounter if you use Visual Studio Code is image uploading. Whereas the video recommends using a res (resource) folder if you only use Eclipse, I recommend creating a res folder as well as a separate images folder in the src (source) folder, as shown on the right.
Above: How I dealt with the image loading error on VScode
Example of commenting on code to help yourself learn!
Be sure to understand the logic and how the code connects with one another- this is especially useful while debugging.
Since Java is an object-oriented programming language, remember to master the fundamentals of OOP (especially since enums pop up).
Use comments to highlight important sections and remind yourself about the logic behind the program.
Don't give up! Even if it gets hard, remember that it is not impossible and that every solution is solvable!
It's OK to use AI for assistance, but be wary of the tips it provides and always try to understand the code first.
Finally, be creative and have fun!