Java Game Development Tutorial
Tower Defence

Welcome to the Java Game Development Tutorial. Tower defence games are a great start to begin your game dev journey. They contain stuff such as:

  • Animations

  • Gameloop

  • Pathfindings

  • Event Handling

  • Rendering

  • and much more

And we will learn all of this in this tutorial. We will implement the most basic way to solve a problem and then work our way up from that to make it better.

All of the code and resources will be listed below.

 

Episode 01

In this first episode we start by setting up all the tools.
We make our first window and draw something onto it.

Download Episode 01.zip


Episode 02

in this episode we create a grid of colors and slowly move towards adding sprites and ends up making a grid of Sprites.

Download Epsiode 02.zip
Download spriteatlas.png


Episode 03

We learn what a game loop is and various ways of implementing it.

Download Episode 03.zip


Episode 04

Inputs and game state. How it all is connected.

Download Episode 04.zip


Episode 05

Now we added a way of building the level. The simplest way of doing it of course.

Download Episode 05.zip


Episode 06

Making our own buttons.

Download Episode 06.zip


Episode 07

This contains the code for episode 7 part one AND two.
We make it way easier to change tiles instead of looking into an int array

Download Episode 07.zip


Episode 08

We finally learn how to save, load and also create files the simple way. Code is for both part one AND two here.

Download Episode 08.zip


Episode 09

Adding a proper edit scene and we move a lot of code around to make it all work.

Download Episode 09.zip


Episode 10

We are finally adding more sprites. We are also doing so with code?

Download Episode 10.zip


Episode 11

Adding the rest of the sprites and make it so we can rotate our sprites.

Download Episode 11.zip


Episode 12

Finally, we are adding sprites to our game.

Download Episode 12.zip


Episode 13

We are adding enemies! First of a few episodes that will contain this subject.

Download Episode 13.zip


Episode 14

Today we create a pathfinder for our Enemy.

Download Episode 14.zip


Episode 15

We add all the enemies and work on making our pathfinding better with start- and endpoints.


The code in this zip file contains the code for next episode as well. Episode 16.

Download Episode 15.zip
Download Spriteatlas.png


Episode 16

We continue from last episode. Adding more functionality to our pathfinder.
Same code as episode 15

Download Episode 16.zip


Episode 17

This will be the start of our tower work. We create our first tower in this episode.

Part 1.

Download Episode 17.zip



Episode 18

We continue our work with the towers. Adding buttons etc.
Part 2.

Download Episode 18.zip


Episode 19

In this one, we make our towers clickable and also, disable the ability to place a tower on top of another tower.

Download Episode 19.zip


Episode 20

First part of the combat section of our game.
Fixing some stuff from last episode and also adding the variables and values we will need later.

Download Episode 20.zip


Episode 21

In this episode we continue our work for the combat system. Also adding a tower range visual

Download Episode 21.zip


Episode 22

Today we add the range check and also begin with our projectiles.

Download Episode 22.zip


Episode 23

In this episode we make our turrets target our enemies no matter what direction they are at, and we add damage to the projectiles.

Download Episode 23.zip


Episode 24

We talk about how to rotate and translate, and why we need them both for a successful rotation.

Download Episode 24.zip


Episode 25

In this episode we add explosions and change some constant values.

Download Episode 25.zip


Episode 26

Last episode for a while about towers. Lets finish this off with the slow effect by the wizard. What will come next ?

Download SpriteAtlas.png
Download Episode 26.zip


Episode 27

In this episode we add enemies in waves. Starting to look like a real TD game now!

Download Episode 27.zip


Episode 28



More than just one wave, and they are coming! Also adding some status test about the current wave of the enemies.

Download Episode 28.zip


Episode 29

Today we add the economy. Gold income and cost for towers are added. Good luck!

Download Episode 29.zip


Episode 30

We finish what we started last episode. Now we can sell and upgrade towers.

Download Episode 30.zip


Episode 31 & Episode 32

Adding pause button to our game. Now the player can take a break if needed! In the other episode, we added game over scene.
There is two episodes in the same zip file. But two videos.

Download Episode 31_32.zip


Episode - Completed

This is the completed version of the game. You will still need to change the values for health, speed, damage and such.
You will also set the amount of waves you want as well as the amount of enemies in each wave.

I also added a fix that needed to addressed. You will also need a name for the game.

Download Episode - Completed.zip


Bonus Episode 1

Adding an quick method to reuse the inactive projectiles of our game.

Download Bonus Episode 1.zip


Bonus Episode 2

This is about a different kind of pathfinding. Scales better than our current. Both got different use cases. Pick whichever you like.
Note:
Worth knowing. I added a - return; after we killed off the enemy in case we were at the end. No point of continuing after that. I also moved the check:
if(isTilesTheSame(newTile, end)) {
e.kill();
playing.removeOneLife();
return;
}
Inside the check for isTheTilesTheSame(curr,newTile);
No need to check for end tile if the tile never changed.

Download Bonus Episode 2.zip


Bonus Episode 3

Hey.
The last bonus episode for this tutorial. Finishing off by learning how to play the game outside eclipse.

Download Bonus Episode 3.zip