3

Code a Java Game with (almost) Zero Coding Skills

 3 years ago
source link: https://hackernoon.com/code-a-java-game-with-almost-zero-coding-skills-z442w31dh
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Code a Java Game with (almost) Zero Coding Skills

July 26th 2019 44,300 reads
8
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png

@johnnythecoderJohnny

A senior Java developer and Java tutor at Learning Tree International programming courses.

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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: 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

“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 are usually written in C++ and accompanied game engines.  

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

1 reactions
heart.png
light.png
thumbs-down.png
1money.png

Indie games. One gamer treats indie projects with contempt and the other loves them with passion. Indie game means an independent game created by a small team or even one developer. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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 the market and become megapopular. A good example of such 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 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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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, 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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Case 1. From scratch using step-by-step instructions. CodeGym, Games section 

This feature is appropriate for the 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. 

2 reactions
2heart.png
light.png
thumbs-down.png
money.png

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).  

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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, 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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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 to complete the first 5 levels of the course to get such knowledge. If you feel not confident enough here is 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.  

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Payment: CodeGym Games is free to use. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Case 2. For rookie to middle level Java Student who loves Minecraft 

If you like Minecraft it is 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

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

To start with modding, you should have your IDE and JDK installed as well as modding tool. Forge is one of the most popular tools for Java modding. There are myriads of tutorials and courses of Java Minecraft modding.   

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Here are some of them: 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

What should you know for modding Minecraft with Java?

It depends on the complexity of 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.   

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Case 3. I have 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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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.     

0 reactions
heart.png
light.png
thumbs-down.png
money.png

What does the game consist of?

0 reactions
heart.png
light.png
thumbs-down.png
money.png
  • Graphics
  • Physics (the way of objects interaction in a game)
  • AI (it is not represented in each game, but pretty often it is) 
  • 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.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

libGDX is a 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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

libGDX consists of several modules, so you can use it to create AI-based characters, control light behavior, sound and physics. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Therefore it is a good idea to learn libGDX for beginner Java game developer. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

What else? 

Game development is not a clear programming only. If you are planning to work with your project all by yourself, you should as well: 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Make some pixel art, textures, sprites of characters. You need an image editor for this. For example, Pinta or  Paint.Net

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Design level maps. To create a map, you need a tile set. You can create it in a graphic editor.To create a map from tiles you may use  a map editor Tiled

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Create texture atlases. 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. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Create graphical interface. Use, for example, Overlap2D

0 reactions
heart.png
light.png
thumbs-down.png
money.png

There are many good tutorials of working with libGDX. Here is a link on the official one

0 reactions
heart.png
light.png
thumbs-down.png
money.png

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).

1 reactions
heart.png
light.png
1thumbs-down.png
money.png

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

0 reactions
heart.png
light.png
thumbs-down.png
money.png

You may also try to create some modes of existing games and Minecraft (Java edition) together with Forge is extremely good for this. 

0 reactions
heart.png
light.png
thumbs-down.png
money.png

If you know Java Core well enough, libGDX framework is a good choice to learn and use for your first game project.  

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Good luck with your games!

0 reactions
heart.png
light.png
thumbs-down.png
money.png
8
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
Share this story
Join Hacker Noon

Create your free account to unlock your custom reading experience.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK