How do I randomize a path for tower defense

0 favourites
  • 5 posts
From the Asset Store
Move around the rectangular and travel as much as you can!
  • I've been banging my head against the wall trying to figure this out for days and all I can manage to create is a buggy mess.

    I'm currently working on a smaller td game called TIki Taka TD.

    To add some replayability to the map I have plans on creating a level editor and a randomizer. The level editor shouldn't be too difficult, but this godforsaken level randomizer is making me throw a fit.

    I have indeed found some randomizing tutorials, but none of them share how to create just one path. And the one that I thought I'd be able to use haven't got any capx files so I'm completely at loss.

    Criteria:

    I'd rather not have my path branch into several ones. I would be ok with several paths as long as they are separate.

    It cannot run into itself.

    I'd prefer if there was some kind of way to make sure it was atleast 30 units or so long before it ended.

    It needs to start at certain spots so that my coding for waves always works.

    Thank you so much in advance!

    The game can be found here if you'd be interested in checking it out: https://www.scirra.com/arcade/strategy- ... a-td-10773

  • I've done some things like this, one option is to have sprites that the minions aim for, then on reaching them, aim for the base. (or 're randomise for another sprite with a higher var)

    on created make a random number, for a minnion with 1: go to sprite 1, if 2, aim for sprite 2 (or give the sprite a corrisponing variable, and minnion on created, pick sprite where variable=minion.variable: find path)

    In effect this makes them choose a random path.

    Trouble is, if you have blocks that can block paths, they will head to the sprite reguardless

    Would work well on random maps, as you could place the route sprites.

    Love TD! Good luck dude

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've done some things like this, one option is to have sprites that the minions aim for, then on reaching them, aim for the base. (or 're randomise for another sprite with a higher var)

    on created make a random number, for a minnion with 1: go to sprite 1, if 2, aim for sprite 2 (or give the sprite a corrisponing variable, and minnion on created, pick sprite where variable=minion.variable: find path)

    In effect this makes them choose a random path.

    Trouble is, if you have blocks that can block paths, they will head to the sprite reguardless

    Would work well on random maps, as you could place the route sprites.

    Love TD! Good luck dude

    You lost me

    Have sprites that enemies aim for and when the enemies reach them they go towards the base?

    If I have blocks that can block path? That'd be the entire map that isn't supposed to be a path?

    Could you give me an example of how you imagine this'd be done?

    Thank you for your help so far!

  • I guess I was writing in responce to the topic name sorry. I may have been clubbing lol.

    I made league of legends (ok I got stumped on ai for champions) and the minions needed to go top mid and bot . To do this, on created at the nexus, i assigned them 1,2,or 3

    If 1, i had a sprite in the top left to pathfind too, on reaching it, they would go towards enemy nexus (base)

    On route they would stop when targeting. this isn't randomized in the slightest. Sorry.

    I see what your saying sorry, getting carried away. .

    If I wanted one path, I'd fill the map with blocks, and randomly place the base. Have the base spawn a larger sprite. And each block it overlaps needs a variable set to 1.

    Next. Pick 1 block that =1 and spawn another large sprite over it. (This sprite may have to be a plus shape to avoid diagonal blocks. )

    Set the next wave of blocks that are overlapping the checker to 2. Pick one block =2. Spawn checker.

    This can be done In a loop, where the given value = the GV, and after its done, add 1 to the gv. You may want to consider setting all blocks next to the destroyed block as walls, using a booleon. And on checking blocks. Only pick one that has a false booleon. or only change the variable on a block if it =0

    If you want real randomness, just continue until you reach the spawner . But it may be easier to have the player set a path distance. And when a block variable= path distance. Spawn the spawner, and destroy the final block and stop The loop . Multiple paths could be interesting..

    Hope thats clear? No images to send sorry. It's the easiest was I could think, otherwise you could make random shapes and just destroy the blocks it overlaps.

    There's a more dificult way to connect two objects, but programming is about finding easy ideas to solve hard problems.

    You could also have a driller that enters the level first, and maybe give the player slight control over its random path making, prior to the game. just destroys randomly as a slow bullet that changes direction after it destroys block slightly, like rotate random (-30,30) +5' towards base. after a set time, find the path directly to the base, and destroy it, then start the waves.

  • I guess I was writing in responce to the topic name sorry. I may have been clubbing lol.

    I made league of legends (ok I got stumped on ai for champions) and the minions needed to go top mid and bot . To do this, on created at the nexus, i assigned them 1,2,or 3

    If 1, i had a sprite in the top left to pathfind too, on reaching it, they would go towards enemy nexus (base)

    On route they would stop when targeting. this isn't randomized in the slightest. Sorry.

    I see what your saying sorry, getting carried away. .

    If I wanted one path, I'd fill the map with blocks, and randomly place the base. Have the base spawn a larger sprite. And each block it overlaps needs a variable set to 1.

    Next. Pick 1 block that =1 and spawn another large sprite over it. (This sprite may have to be a plus shape to avoid diagonal blocks. )

    Set the next wave of blocks that are overlapping the checker to 2. Pick one block =2. Spawn checker.

    This can be done In a loop, where the given value = the GV, and after its done, add 1 to the gv. You may want to consider setting all blocks next to the destroyed block as walls, using a booleon. And on checking blocks. Only pick one that has a false booleon. or only change the variable on a block if it =0

    If you want real randomness, just continue until you reach the spawner . But it may be easier to have the player set a path distance. And when a block variable= path distance. Spawn the spawner, and destroy the final block and stop The loop . Multiple paths could be interesting..

    Hope thats clear? No images to send sorry. It's the easiest was I could think, otherwise you could make random shapes and just destroy the blocks it overlaps.

    There's a more dificult way to connect two objects, but programming is about finding easy ideas to solve hard problems.

    You could also have a driller that enters the level first, and maybe give the player slight control over its random path making, prior to the game. just destroys randomly as a slow bullet that changes direction after it destroys block slightly, like rotate random (-30,30) +5' towards base. after a set time, find the path directly to the base, and destroy it, then start the waves.

    Thank you for your helpful reply, I'll look into it more tomorrow.

    The next issue would be making sure the path creates the right tile ex. if it's a corner or a straight way.

    I tried working with a sprite walking around laying out a block depending on what block it was currently on, but that totally made construct bug out.

    Have a nice evening ^^

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)