Tree generation from quads.

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
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Tree generation from quads.

Post by Ryne »

So, I have these trees generating as I want them to, the only issue is that it's with single images and the code is kind of ugly and not really universal.

This is what I have

http://d.pr/YZYR

Basically I have a tile grid of all 0's, and any tile that is a 1 has this tree drawn on it.

Code: Select all

function drawTrees()

	for i = 1, #map do
		for l = 1, #map do
			if map[i][l] == 1 then
			love.graphics.draw(images.treetest, mapToWorld(l-1, i-2))
			end
		end
	end

end
now this works fine for just one tree, but now I have a quad for my tree tile set.

Code: Select all


	quads = {
		love.graphics.newQuad(0, 0, 16, 16, 64, 64), -- big white
		love.graphics.newQuad(32, 0, 16, 16, 64, 64), -- big green
		love.graphics.newQuad(32, 32, 16, 16, 64, 64), -- big blue
		love.graphics.newQuad(0, 32, 16, 16, 64, 64), -- big orange
		love.graphics.newQuad(0, 16, 16, 16, 64, 64), -- med white
		love.graphics.newQuad(0, 48, 16, 16, 64, 64), -- med orange
		love.graphics.newQuad(32, 48, 16, 16, 64, 64), -- med blue
		love.graphics.newQuad(32, 16, 16, 16, 64, 64), -- med green
		love.graphics.newQuad(16, 0, 16, 16, 64, 64), -- 2 white
		love.graphics.newQuad(16, 32, 16, 16, 64, 64), -- 2 orange
		love.graphics.newQuad(48, 0, 16, 16, 64, 64), -- 2 green
		love.graphics.newQuad(48, 32, 16, 16, 64, 64), -- 2 blue
		love.graphics.newQuad(16, 16, 16, 16, 64, 64), -- single white
		love.graphics.newQuad(16, 48, 16, 16, 64, 64), -- single orange
		love.graphics.newQuad(48, 16, 16, 16, 64, 64), -- single green
		love.graphics.newQuad(48, 48, 16, 16, 64, 64) -- single blue
	}
So, It would be great to be able to specify numbers as trees or other objects. Similar to how I have "1" as that single orange tree, except with ALL of the trees. you know?

As always, any help is appreciated. Thanks guys!
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tree generation from quads.

Post by Robin »

Something like this?

Code: Select all

function drawTrees()

   for i = 1, #map do
      for l = 1, #map do
         if map[i][l] ~= 0 then
         love.graphics.drawq(images.treetest, quads[map[i][l]], mapToWorld(l-1, i-2))
         end
      end
   end

end
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Tree generation from quads.

Post by kikito »

Hi there!

I explain how to do that on my tile tutorial.

If you are in a hurry, read just part 1b, in which I do exactly that. You might want to also read 1c (the next one). It will save you some typing.
When I write def I mean function.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tree generation from quads.

Post by Ryne »

Robin wrote:Something like this?

Code: Select all

function drawTrees()

   for i = 1, #map do
      for l = 1, #map do
         if map[i][l] ~= 0 then
         love.graphics.drawq(images.treetest, quads[map[i][l]], mapToWorld(l-1, i-2))
         end
      end
   end

end
Now I feel dumb, though yeah it worked great. Thanks Robin :)
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tree generation from quads.

Post by Robin »

No problem, mate. :)
Help us help you: attach a .love.
Post Reply

Who is online

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