Page 1 of 2

Help:gnerator level's

Posted: Mon Jun 04, 2012 5:01 pm
by l3crafteur
Hello,

I try to do a random world generator with different block but I can not do it! :/
I think to do a table but I do not think that's necessary.
The variables of block (image block) are:

Code: Select all

local pierre = love.graphics.newImage("fond.png")
local lumiere = love.graphics.newImage("lum.png")
local arbre = love.graphics.newImage("arbre.png")
Thank you in advance.

Re: Help:gnerator level's

Posted: Mon Jun 04, 2012 5:31 pm
by Robin
Welcome.

Could you upload the complete game for us, please?

Also, what do you want exactly? What do you mean by "with different block"?

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 5:04 pm
by l3crafteur
Ok, here is the game
And also, it must be LOVE in 0.7 and not 0.8 (required)
(Because of a plugin)
test.love
(1.04 MiB) Downloaded 339 times
Ok, here is the game

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 5:24 pm
by coffee
l3crafteur wrote:Ok, here is the game
And also, it must be LOVE in 0.7 and not 0.8 (required)
(Because of a plugin)
test.love
Ok, here is the game
pfff... oh la la... je pense que votre personnage est totalement saoul! :D

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 5:26 pm
by l3crafteur
Nan suis français, j'utillise juste un peu google trad la x)

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 5:43 pm
by coffee
l3crafteur wrote:Nan suis français, j'utillise juste un peu google trad la x)
lol, I'm not too, but I didn't have translate for my simple speech (so probably have errors). Since your game was wrote in french you fool me well! :)
Welcome to the forum.

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 7:56 pm
by l3crafteur
coffee wrote:
l3crafteur wrote:Nan suis français, j'utillise juste un peu google trad la x)
lol, I'm not too, but I didn't have translate for my simple speech (so probably have errors). Since your game was wrote in french you fool me well! :)
Welcome to the forum.
Thank you: D

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 8:26 pm
by Roland_Yonaba
Français
Salut,

Mis à part le fouillis dans ton code (certaines choses peuvent être simplifiées), il nous faudrait un peu plus de détails pour t'aider.
je comprends juste que tu veux écrire un générateur de "monde", 2D apparemment. Comment représentes-tu ton mode ?
Tu pourrais, par exemple, concevoir un monde "à la main", pour nous faire mieux comprendre.
Ensuite, l'étape suivante serait mettre au point un code qui ferait cette génération de manière automatique.

English
Hi,
We'll need more details to help you, though.
Right now, the only thing i can get is that you need a basic flat 2D world generator.
But I can't clearly understand how you represent your world.
Are you using tiles, tables ? Dunno.
Why not make an example, so that we'll help you through ?

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 9:20 pm
by Lynesth
Français
Serait-ce le légendaire "French Thread" ?! :p

Bon en tout cas, je suis du même avis que Roland ici. C'est vrai qu'il nous faudrait plus de détails quand à ce que tu souhaites faire exactement sinon on ne pourra pas t'aider plus que ça :)




English
Roland_Yonaba wrote: We'll need more details to help you, though.
Right now, the only thing i can get is that you need a basic flat 2D world generator.
But I can't clearly understand how you represent your world.
Are you using tiles, tables ? Dunno.
Why not make an example, so that we'll help you through ?
That.

Re: Help:gnerator level's

Posted: Tue Jun 05, 2012 10:18 pm
by coffee
Well, let's not stay off-topic with the french "affair". I'm trying to guess if his problem is not simple like random select from a table (like he thought he needed).

If it's the problem, there is several ways of random select one of the tiles you have in your code:

An easier one ( you can add other properties to you table in each row/tile like name and whatever)

Code: Select all

function love.load()
	
tiles = {
	{ img = love.graphics.newImage("fond.png") },
	{ img = love.graphics.newImage("lum.png") },
	{ img = love.graphics.newImage("arbre.png") }
}

rnd = math.random(#tiles)

end

function love.update(dt)

end

function love.draw()
	love.graphics.draw(tiles[rnd].img,0,0)
end
A long one (because we need this way use extra code for get info from the table since is not organized by numeric index)

Code: Select all

function love.load()
	
tiles = {
	pierre = { img = love.graphics.newImage("fond.png") },
	lumiere = { img = love.graphics.newImage("lum.png") },
	arbre = { img = love.graphics.newImage("arbre.png") }
}

count = table_count(tiles) 
rnd = math.random(count)
selected = table_get_index(tiles,rnd)

end

function love.update(dt)

end

function love.draw()
	love.graphics.draw(tiles[selected].img,0,0)
end

function table_count(t)
	local count = 0
	for _ in pairs(t) do count = count + 1 end
	return count
end

function table_get_index(t,pos)
	local count = 0
	for k,v in pairs(t) do
		count = count + 1
		if count == pos then return k end        
	end
	return "Error: Out of Range"
end 
I hope didn't a mistake. As you see you random choice a value from table and present it.