# OpenGL Tower Defense Indie Game Dev Blog #1: 3D Models and Pathfinding

1482 views

As you probably have guessed from the title, the game I'm working on is a Tower Defense type of game. At this point I'm still not sure what theme it's going to be in, but I think I will go with military based theme. The game itself is inspired by Red Alert, Robo Defense and Kingdom Rush. For development side of things I'm using Java/Kotlin (mostly Kotlin) + OpenGL and LWJGL with the IntellJ IDEA editor.

### 3D Models

In the last couple of weeks I've been learning how to make 3D models using Blender. After few days of modelling I got hang of the basics and could model few simple trees, turrets and a car which I then imported into the game "engine".  Here are few screenshots of the models that I have created during those days:

### Pathfinding

I have programmed a pathfinding management system, which uses flood-fill pathfinding algorithm to calculate where the enemies have to go. The way it works is pretty simple. You start by splitting your game map into square nodes and then generating a gradient map which will tell how far away the current node is from the target node. To do this, you firstly start at the target node, assign its value to 0, then for all the neighboring nodes increment their value by 1, or whatever number you want, as long as its a positive number. If the neighboring node is non-collidable, assign its value to something very large, like 999999.

To get the path from the start node to the current node you start at the start node, and select its neighboring node with the lowest value. Then for that selected node, do the same process until you reach node with the value of 0, which will mean that you have reached your target node.

This is how the gradient map looks in my game:

Here you can see the numbers at the center of each node which represent its value. The cars are moving towards the surrounding nodes which have the lowest values until they reach 0, that's when they stop.

Okey, so why did I use this method instead of the famous A* algorithm? First of all. This is heck of a lot faster. Instead of always calculating a path each frame for each entity. You just generate the gradient map once, and update it every time an object is placed on the map. The drawback of this method is that all the entities can only go to a single target destination. If you want multiple target destinations, you will have to recalculate the gradient map with different target nodes.

### Gameplay

There's not much of a gameplay at this stage of development. As of now all you can do is place turrets, watch them shoot the enemies and that's pretty much it. Nonetheless this is the gameplay footage:

Website: http://extrabitgames.com

My website: http://extrabitgames.com

This is looking very good already! You can do it as part of the gamedev challenge too, there are several of us making tower defence games at the moment.

2 hours ago, lawnjelly said:

This is looking very good already! You can do it as part of the gamedev challenge too, there are several of us making tower defence games at the moment.

Thank you!

Is just a bit of fun, but I don't see why you can't put yours as an entry even if you are planning on selling your game after. Rutin, Awoken, Dexter and I are doing games I know of so far.

43 minutes ago, lawnjelly said:

Is just a bit of fun, but I don't see why you can't put yours as an entry even if you are planning on selling your game after. Rutin, Awoken, Dexter and I are doing games I know of so far.

Oh sounds very cool  I just don't know if I will be able to finish this game by the time the submission date ends. Though I could try making a minimal viable product and submitting that. And then continue working on the game after submission. Anyways, thanks for letting me know. This community is so friendly

1 hour ago, EddieK said:

Oh sounds very cool  I just don't know if I will be able to finish this game by the time the submission date ends. Though I could try making a minimal viable product and submitting that. And then continue working on the game after submission. Anyways, thanks for letting me know. This community is so friendly

If you do meet the minimum requirements for the challenge you can earn yourself the 'Tower Defence Badge'!

Great job by the way.  Your turning mechanism is very fluid.  I also like the military theme you're going with.

1 hour ago, Awoken said:

If you do meet the minimum requirements for the challenge you can earn yourself the 'Tower Defence Badge'!

Great job by the way.  Your turning mechanism is very fluid.  I also like the military theme you're going with.

Thanks! I will certainly try to get my game submitted there

Awesome TD development bro ^_^y It's nice to know your using KOTLIN... I'm learning the language but on early stage.

37 minutes ago, DexterZ101 said:

Awesome TD development bro ^_^y It's nice to know your using KOTLIN... I'm learning the language but on early stage.

Thanks! I've have been using Java for few years now and then decided to switch to Kotlin like a month ago. And all I can is that it is AWESOME  Less boilerplate code, operator overloading (especially useful in game dev) and many more things which make programming faster. The only thing that I don't really get is the whole thing about non-nullable objects. I mean I understand how it works, but there are lots of parts in my code where I need to have a null object referance. Anyways, good luck with learning! It is really a great and modern language

I really like the art work!  You should be able to meet the min. requirements easily before the due date. I hope you submit an entry! Great work!

16 minutes ago, Rutin said:

I really like the art work!  You should be able to meet the min. requirements easily before the due date. I hope you submit an entry! Great work!

Wow, thanks! Didn't expect to get such a positive feedback  I will try to submit an entry, so I better go back to work now

I found the pathfinding part very interesting!

By the way, which Red Alert did you take your inspiration from? I'm certainly not a huge fan of Command & Conquer and Red Alert

Posted (edited)

Just wanted to thank you guys for all the kind feedback, you guys are the best!

40 minutes ago, thecheeselover said:

I found the pathfinding part very interesting!

By the way, which Red Alert did you take your inspiration from? I'm certainly not a huge fan of Command & Conquer and Red Alert

Thank you! Although I have played all of the Red Alert installments, I think my inspiration comes from the original Red Alert which I played on my PS1  I'm actually thinking of making tesla towers inside my game, just because I loved them in Red Alert so much ﻿

Edited by EddieK

## Create an account

Register a new account

• ### Similar Content

• Does your code use one of the most popular graphics or compute APIs? Here is a map of Intel® processor series to each graphics generation to add to your dev docs.
Developer Documents for Intel® Processor Graphics
Intel® processor graphics provide the graphics, compute, media, and display for many of our processors including the 6th gen Intel® Core™ processors. Does your code use one of the popular graphics or compute APIs? Do you want a deeper understanding of our graphics hardware architecture? In the table, you’ll find the right documents to help you write and tune your software so it runs great on Intel processor graphics.
If you’re developing compute applications, the compute architecture guides give foundational reading and the OpenCL™ optimization guides show you how to optimize. If your code uses the graphics APIs, read the graphics dev guides or programmers reference manuals.
• By _Flame_
Hello.
I'm tring to implement opencl/opengl interop via clCreateFromGLTexture (texture sharing)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
With such texture I expected that write_imagei and write_imageui would work but they don't. Only write_imagef works. This behaviour is same for intel and nvidia gpus on my laptop. Why is it and why there is no such information in any documentation and in the entire internet? This pitfall cost me several hours and probably same for many developers.

• When importing sprites in Unity, we get a Pixels Per Unit option. The smaller the value, the larger it looks on screen. This is great for very small (50x32px) sprites I download.
My question is, how can I accomplish this with OpenGL? Should I make the sprite larger in the frag shader? I don't want to scale the game object, I'd like the image to be rendered at the size I need without changing the scale, similar to Unity.
No code needed, just some suggestions that put me in the right direction. Thanks!

• Hello there!
So I want to understand this better. With OpenGL 4.6, support was added to be able to run SPIR-V compiled shaders. I've messed around with it, gotten it to work. It's a little bit more complicated to have to use UBOs for most things now. What I mainly want to know is what the benefits are. So I understand SPIR-V is bytecode, and that it's used by Vulkan and that because it's bytecode, there isn't any worry about wild inconsistencies across GPU vendors. When OpenGL is using SPIR-V, does it also benefit from this?
I have some application that uses some really old version of GLSL, like GLSL 120, and I'd been thinking about updating it and properly supporting GLSL 460 compiled to SPIR-V. The application also uses DX9, so I was just curious how updating and using these new techniques with OpenGL 4.6 would stack up against the old GLSL or DX9 methods. I'm not expecting some magic performance benefit, I'm just legitimately curious if it'd be worth it to try.
• By Sultown
Good evening.
Before I get to my question, I'd like to clarify that this is in a 2D (2.5D) view with pixel graphics. While making mockups, a question on map design came to me. If I were to draw an entire section of a map, including stairs, buildings, etc. would I be able to set constraints so that a character could move realistically on one asset (the room, I guess), Instead of having to place each and every tile for every corner, or variation in design, or every stair?
I feel like this would be much easier when it comes to very intricate room designs that would be much cleaner and aesthetically pleasing if I could just put wall barriers (native to my engine) where the player can not go.
Let me know if this needs clarification or if this is in the wrong subforum.
Thanks.
×