The first few tutorials will work like this: we’ll provide you a sample project, and explain the various aspects of how it works.
From there, we’ll guide you through building new features and enhancements on to the game.
We have written a little helper project, which you can find at https://github.com/dgmp88/MyGdxClasses. It contains a template layout for setting up a Libgdx application, as well as various utility functions.
We install this via gradle, which you will need on your machine. Once you have got that, run the following commands:
git clone https://github.com/dgmp88/MyGdxClasses
Getting the source code
We are assuming you’re familiar with Git. To directly check out the example project, run the following command:
git clone -b Base_project https://email@example.com/dglencross/zombiegametutorial.git
This checks out a specific branch for just the Base_project – in future we’ll check out different branches to see different examples.
We created this tutorial in Android Studio, and all examples are going to assume that is your IDE, but in reality most stuff should be the same with other IDEs. This may vary when it comes to exporting the project to Android or iOS.
We’re assuming you have Java set up properly on your machine – this tutorial isn’t going to cover that.
Once you’ve checked out the code and opened Android Studio, choose ‘Open an Existing Android Studio project’ and locate the project.
Start the game by opening the file ‘Desktop Launcher’ and Run. This will probably fail first time, but that’s just because we haven’t set up the run configuration yet. Click the down arrow next to ‘DesktopLauncher’ to open it up.
Make sure you have the following settings:
Main class: com.boondog.games.desktop.DesktopLauncher
(for example, on my Mac the path is /Users/dave/git/zombiegametutorial/android/assets/)
Use classpath of module: Desktop
Now try running the game again. If all has been set up correctly, you should see something which looks a bit like this:
If you see this – success!
What am I looking at?
This is the base project, which is just a randomly-generated map. At the moment, there’s not much you can do here. Try navigating around with the arrow keys, try zooming in and out with the Z and X keys.
Also – try pressing R to regenerate the map. Neat eh?
Why does it look so crap?
We haven’t provided any logic for drawing edges properly, so it looks quite blocky at the moment. You can decrease the ‘blockiness’ by changing a couple of parameters.
Open up ZombieGame.java and look for:
float viewWidth =32;
Try changing the value to something bigger, and you can see the effect. Have a play around with the other variables in there and see what happens. You can make it look like this:
Why wouldn’t you just make it really high-definition? Well, further down the line we’re going to introduce some path-finding. Each block on the map is a node, and the higher number of nodes, the slower it is going to be to generate paths. This is a real issue we came across when creating Dinowar, so we had to find a balance between the detail of the map and the speed of path-finding on a mobile device.
But in the end, you can make the map look a lot better by drawing edges properly:
If you like these tutorials, or want to see a game that was written in much the same way, please download Dinowar from the Google Play Store. It costs nothing and is ad-free.