jTDF - High-Performance Tower Defense Framework | Parallel Luau

Baj’s Tower Defense Framework

jTDF_logo

Tower Defense framework built for performance and ease of use

Github | Download | Documentation | Demo game | Discord community | Donations

What is this?

jTDF is a fast, easy to use tool used to create Tower Defense games, which allows developers to focus on writing the actual game instead of hundreds of lines of boilerplate code.

jTDF makes extensive use of Parallel Luau, which allows it to calculate over 300 enemies and 50 towers simultaneously at smooth 60FPS.

It handles enemy detection, enemy paths, data structures and provides a simple interface to define, create and change towers and enemies.

Features

- Insane performance with multithreading
- Simple API which is easy to grasp for beginners
- Flexible enemy detection zone system allows for complex tower behaviors
- Built-in path functionality

Performance

jTDF can handle hundreds of enemies and towers without lag.

During testing I was able to summon 50 towers and 300 enemies: all enemies were in range of all towers (worst case scenario)
jTDF only took up ~6ms of frametime, with the game running at 60 fps.
Keep in mind that tower performance depends on the following factors:
- How many enemies are on the map
- Whether there are any enemies within the tower range (if there are none, the tower will throttle)

Example usage

Define new enemies

local jTDF = require(ReplicatedStorage.jTDF)
local CEnemies = {
	["Normal"] = {
		["BaseHealth"] = 4,
		["BaseSpeed"] = 1
	},
	["Big"] = {
		["BaseHealth"] = 5000,
		["BaseSpeed"] = 1
	}
}
jTDF.Enemies.Define(nil, CEnemies)

Define a simple 1-upgrade tower

local jTDF = require(ReplicatedStorage.jTDF)
type Unit = jTDF.Unit
type Enemy = jTDF.Enemy
type Radius = jTDF.Radius

local towers = {
	["Pistol Guy"] = {
		["Upgrades"] = {
			[1] = {
				["Range"] = 6,
				["FireFunction"] = function(self:Radius, Unit:Unit?, Targets: {Enemy})
					if not Targets[1] then return end
					Unit.LastTimeShot = os.clock()
					Targets[1]:Damage(1, Unit)
				end,
				["CheckFunction"] = function(self:Radius, Unit:Unit?)
					if not Unit.LastTimeShot then return true end
					if os.clock() - Unit.LastTimeShot >= 0.5 then return true end
					return false
				end,
				["RadiusConfig"] = {
					["CanLock"] = false,
					["MaxLockedTargets"] = 1,
					["TargetType"] = 1,
					["IsPassive"] = false
				}
			}
		}
	}
}

jTDF.Units.Define(nil, towers)

Spawn an enemy

local jTDF = require(ReplicatedStorage.jTDF)

jTDF.Enemies.new("Normal", "Path1")

Place a tower

local jTDF = require(ReplicatedStorage.jTDF)

local Player = game.Players:GetPlayers()[1] -- example

jTDF.Units.new(Player, "Pistol Guy", vector.create(10, 10, 30))

Help make jTDF better

You can contribute to this project by creating a pull request on Github.

Plans for the future

All that being said, this module is still in version 1.0.0, so it is not at all perfect. I am open to any feedback, suggestions, reviews and critiques.
Here’s what I currently have planned for the next versions of jTDF:
- Further optimization of the module, specifically enemy detection
- TargetType 2 (closest)
- Ability to define custom TargetTypes
- Expand documentation
- Update demo place scripts to be more readable

Polls

Will you use jTDF?
  • Yes
  • Might use in the future
  • No
0 voters
Rate this resource
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
0 voters
21 Likes

THANK YOU FOR THE RESOURCE, MY GLORIOUS KING

2 Likes

baj you’re awesome sauce thanks

2 Likes

Solid resource. Greatly looking forward to the next version, hoping to take some of the practices here on an existing game.

2 Likes

PEAK​:100::100: BrainrotFrameworks is coming soon..

1 Like

Thank you! I’m not sure about integrating it in an existing game (you’d essentially need to rip out the entire tower logic), but if you do end up using it, please, let me know! I’ll gladly put your game in the Games using jTDF section in documentation.

2 Likes

Is there support for multi-path upgrades like in the later Bloons TD games? If so, this is even cooler!

2 Likes