Predefined grids?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Predefined grids?

Post by GungnirDev »

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
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Predefined grids?

Post by Helvecta »

Could you explain in more depth please? Just so I can get on the same page :megagrin:




Personal, responsibility,
Personal, responsibility
"Bump." -CMFIend420
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Predefined grids?

Post by davisdude »

You could easily make a grid-looking thing by doing

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
That much should give you a grid. Then you just have to gridlock everything, basically by getting the 'tile' they're in.

Code: Select all

tile_x = math.ceil( love.mouse.getX() / tile_width )
tile_y = math.ceil( love.mouse.getY() / tile_height )
Then just make it so that all operations of mouse and such are based on tile_x and tile_y.
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
User avatar
GungnirDev
Party member
Posts: 119
Joined: Thu Jun 28, 2012 10:31 pm

Re: Predefined grids?

Post by GungnirDev »

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.
Bullets are the beauty of the blistering sky
Bullets are the beauty and I don't know why
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Predefined grids?

Post by micha »

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?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Predefined grids?

Post by Plu »

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)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests