Everyone, well, almost everyone, loves video games. So even if you are not going to be a professional game developer or just don’t know for sure, to learn a programming language through practice and creating your own video game project is an excellent idea. Furthermore, it could be a good motivation for your learning.
This article is addressed to all the prospective and beginner Java students as well as everyone who thinks of creating their own Java game project and don’t know where to start and how to learn this language the best way.
Is Java bad for GameDev?.. Myths and reality
If you read some forums and articles about game development, especially those that have been around for a while, you might get the impression that Java is not a good choice for game development. However, this opinion is somewhat outdated and inaccurate. Video games world is highly diverse. Conventionally, you may divide games into the following categories:
“Big” games. Such as 3D-shooters, large-scale action adventures/action RPG. This category includes AAA-level projects as well. Usually, they are high-budget games designed for a mass audience such as Red Dead Redemption 2, Assassin Creed Origins and so on. This kind of games is usually written in C++ and accompanied game engines.
Java is a rare guest in this kind of game development due to the peculiarities of the JVM. More precisely, it can be used, for example, to create back-end parts.
Indie games. One gamer treats indie projects with contempt and the other loves them with passion. The indie game means an independent game created by a small team or even one developer.
There are many amateur projects among Indie, some of them don’t make money to their creators. Indie is more about original idea and gameplay, good scripts and subjective vision rather than performance and high-end graphics. Nevertheless, such Indie projects burst out of the market and become megapopular. A good example of such a game is Minecraft, originally created by one person, Markus Persson. As of May 2019, over 176 million copies of Minecraft had been sold. That makes it one of the best-selling video games of all time. In 2014, Microsoft bought Minecraft and Mojang, for the US $ 2.5 billion. By the way, Markus Persson is a Java Developer, so he wrote his prominent brainchild in this language. So, yep, Java is really good for Indie projects.
Mobile games. This huge market keeps growing together with the quantity and performance of smartphones. Almost everyone has played a game on their mobile device. It could have been 2048, a mobile remake of an old game or a game with an original idea. Is Java good for mobile game development? The answer is a solid “yes”. The market share of Android smartphones takes 80% now. You may think about Java as of the native language for Android, so there are really many mobile games written in this programming language.
Conclusions. Java is good for Mobile games and Indie projects development (these markets are somewhat intersected) and for the development of server part of high-loaded online games. Now is Indie growing time, so if you are interested in such games, you can try to make some during your Java learning.
Moreover, Java is a universal language. It is used in server-side Enterprise development, in Big Data, Mobile and Web apps, Trading apps, Embedded Space and so on. Java Developer is free to switch their programming role. Hence, Java sets you free to choose maybe more than any other programming language.
If you are sure in your decision to be a big games developer, then C++ and some game engines such as Unity and Unreal is your choice for learning.
Can a newbie programming student create their own game? How to do it?
In fact, even the simplest video game is not quite easy to write, especially for one without coding experience. Luckily, we are living in open information epoch, so we can find different step-by-step instructions and courses for different levels. In this paragraph, we will discuss three options for creating games in Java by newbies.
Case 1. From scratch using step-by-step instructions. CodeGym, Games section
This feature is appropriate for early beginners. You may create your version of 3 (for now, 3 more are in development) classical games with very basics of Java knowledge. Games section on CodeGym is apart of the main course and available for free to all users, not only for CodeGym students.
CodeGym Games section lets you create your own versions of the legendary video games such as Minesweeper, 2048 or Snake (Space Invaders, Moon Lander, and Racer are in development).
Each game is a task with two dozen subtasks and step-by-step instructions. Student gets the subtask and tips, writes code, then it checks by auto CodeGym System. If the code is working the right way, the student goes to the next step. All the code is writing in CodeGym site directly or in IntelliJ IDEA via special plugin you that you can get on the CodeGym.
Completing the last step you have a ready-to-use game, you may publish on the site, customize it according to your creativity and sharing with your friends. The games use the simple CodeGym game engine, which structure you can learn from this article.
What should you know for coding these games? This is the level of the first Java programs: initial knowledge about classes and objects, basic primitive data types, String, loops, and branches, as well as arrays and initial knowledge about the ArrayList structure. The authors of CodeGym recommend completing the first 5 levels of the course to get such knowledge. If you feel not confident enough here is a useful theory that helps you to solve the tasks. If you know Java Core but never tried to make games, CodeGym Games are still interesting for you, especially the opportunity to modify and customize your standard solutions after their approving.
Payment: CodeGym Games is free to use.
Case 2. For a rookie to middle-level Java Student who loves Minecraft
If you like Minecraft it is a really good idea to try doing some mods (modifications) with Java. Most mods add some content to the game to alter gameplay or give the player more options in how they interact with the Minecraft world. For example, you may code a new more precise bow or something like that. Some people create mini-games right inside Minecraft.
Even if you are not a big fan of this game, it would be beneficial for every newbie to work with decompiled code, trying to understand it and change it for you. Later you may play Minecraft with your own modes.
To start with modding, you should have your IDE and JDK installed as well as a modding tool. Forge is one of the most popular tools for Java modding. There are myriads of tutorials and courses of Java Minecraft modding.
Here are some of them:
- The Ultimate Guide to Minecraft Modding with Java in 2019
- Minecraft modding tutorial 1.12 (video)
- Modding Tutorial 1.14 (video)
What should you know for modding Minecraft with Java?
It depends on the complexity of the mode you want to do. You should know at least Java Classes and Objects, the basics of Data Structures, however, it would be much more useful if you have more or less solid skills of OOP using, introduction to threads and streams and Java Collections.
Payment: usually you should buy your own Minecraft version. If you don’t want to learn modding by yourself, it is easy to find some paid courses on the internet.
Case 3. I have a solid knowledge of Java Core, I am ready for my own game project
Sure this case is not about complete newbies. At this point, we will tell you what a Java novice programmer who decided to create a game project should pay attention to.
Do you have an idea for an indy cross-platform or mobile project? Maybe you know how to create your very own version of the popular game? Well, what should you do if you know Java Core and nothing more about game development? Writing a game with raw Java is pretty tough perspective, but there are really interesting and useful frameworks and libraries to help you with your idea coming to life.
What does the game consist of?
- Graphics
- Physics (the way of objects interaction in a game)
- AI (it is not represented in each game, but pretty often it is)
- GUI
- Sound
OpenGL is a cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. In Java, you can use OpenGL functions with some libraries — Java3D, JOGL (Java OpenGL) and LWJGL (Lightweight Java Game Library). They all are cross-platform, free and open-source.
The most popular is the last one, LWJGL. It is a core technology for many other game engines and libraries. LWJGL gives you access to the OpenGL graphics library and contains everything you need to create 2D and 3D games. LWJGL also supports the powerful cross-platform API for creating music and sound effects OpenAL and supports OpenCL, a standard for cross-platform parallel programming.
libGDX is an LWJGL framework for cross-platform games. It contains a useful Box 2D engine that allows you to create a game physics, many graphics classes, tools for working with audio.
libGDX consists of several modules, so you can use it to create AI-based characters, control light behavior, sound, and physics.
With libGDX and box2d you can develop games for different platforms, such as Android, iOS, Windows, Linux, macOS, and Web. You don’t need to recreate the code for each of them, write it once and it would be work on every system due to cross-platform.
Therefore it is a good idea to learn libGDX for beginner Java game developer.
What else?
Game development is not clear programming only. If you are planning to work with your project all by yourself, you should as well:
Make some pixel art, textures, sprites of characters. You need an image editor for this. For example, Pinta or Paint.Net.
Design level maps. To create a map, you need a tileset. You can create it in a graphic editor. To create a map from tiles you may use a map editor Tiled.
Create texture atlases. A texture atlas is one big image that contains all our sprites. Atlas definitely speeds up the development process. You may use free Sprite Sheet Packer for this task.
Create a graphical interface. Use, for example, Overlap2D
There are many good tutorials of working with libGDX. Here is a link on the official one.
Conclusions
Whether you will be a game developer or prefer the other branch of programming later, creating your own game is definitely great for your Java learning. Coding a game, you are involved in all processes of a typical software development project from the beginning to release. You see the results of your work and may demonstrate it to your friends or even publish it somewhere (Google Play, for example).
Even if you are an absolute beginner, you can try to create a video game using some web tutorials and tools such as CodeGym Game Section.
You may also try to create some modes of existing games and Minecraft (Java edition) together with Forge is extremely good for this.
If you know Java Core well enough, libGDX framework is a good choice to learn and use for your first game project.
Good luck with your games!
The article was originally posted on Hackernoon.