Predefined grids?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- GungnirDev
- Party member
- Posts: 119
- Joined: Thu Jun 28, 2012 10:31 pm
Predefined grids?
Does anyone know how you could make a pre-defined grid for a 2D tower-defense-game where you build your tower like Minecraft? It's easy enough to produce the player's tower (you place blocks by clicking) but I need some method of spawning predefined enemy Towers as well. Taking any and all suggestions on where to look.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Bullets are the beauty and I don't know why
Re: Predefined grids?
Could you explain in more depth please? Just so I can get on the same page
Personal, responsibility,
Personal, responsibility
Personal, responsibility,
Personal, responsibility
"Bump." -CMFIend420
Re: Predefined grids?
You could easily make a grid-looking thing by doing
That much should give you a grid. Then you just have to gridlock everything, basically by getting the 'tile' they're in.
Then just make it so that all operations of mouse and such are based on tile_x and tile_y.
Code: Select all
for i = 1, math.ceil( love.graphics.getWidth() / tile_width ) do
for ii = 1, math.ceil( love.graphics.getHeight() / tile_height ) do
love.graphics.rectangle( 'line', ( i - 1 ) * tile_width, ( ii - 1 ) * tile_height, tile_width, tile_height )
end
end
Code: Select all
tile_x = math.ceil( love.mouse.getX() / tile_width )
tile_y = math.ceil( love.mouse.getY() / tile_height )
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- GungnirDev
- Party member
- Posts: 119
- Joined: Thu Jun 28, 2012 10:31 pm
Re: Predefined grids?
No, I already have a grid. What i mean is this that I use this code to spawn the blocks:
for i=0,5 do
block = {}
block.material = nothing
block.width = 50
block.height = 40
block.y = ground - 50
block.x = i * (block.width)
table.insert(blocks, block)
And so it appears as this red grid. Then, you can select block types and click on the grid squares so that you can make a fortress out of blocks. This works fine for human players but not computer players (obv. the computer can't click blocks with the mouse) so I was wondering if there was a way you could make a system to pre-generate the grid for the computer player.
for i=0,5 do
block = {}
block.material = nothing
block.width = 50
block.height = 40
block.y = ground - 50
block.x = i * (block.width)
table.insert(blocks, block)
And so it appears as this red grid. Then, you can select block types and click on the grid squares so that you can make a fortress out of blocks. This works fine for human players but not computer players (obv. the computer can't click blocks with the mouse) so I was wondering if there was a way you could make a system to pre-generate the grid for the computer player.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
Bullets are the beauty and I don't know why
Re: Predefined grids?
I don't understand the question completely.
Is this a matter of AI and the technical question how the AI "clicks" buttons to create towers?
Or do you have a prepared layout of enemy towers and want to create them on start up?
Is this a matter of AI and the technical question how the AI "clicks" buttons to create towers?
Or do you have a prepared layout of enemy towers and want to create them on start up?
Check out my blog on gamedev
Re: Predefined grids?
Put all the code that the player uses to build a tower in a big function that takes as arguments the player, tower type and the tile. Then let the AI call that same function with its own player variable. Then the AI will build players just like the player does, and you'll just have to program the right way for the AI to call the functions (but that's AI design and highly dependant on your game)
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests