Help:gnerator level's

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.
l3crafteur
Prole
Posts: 9
Joined: Mon Jun 04, 2012 4:33 pm

Help:gnerator level's

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Help:gnerator level's

Post 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"?
Help us help you: attach a .love.
l3crafteur
Prole
Posts: 9
Joined: Mon Jun 04, 2012 4:33 pm

Re: Help:gnerator level's

Post 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 340 times
Ok, here is the game
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Help:gnerator level's

Post 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
l3crafteur
Prole
Posts: 9
Joined: Mon Jun 04, 2012 4:33 pm

Re: Help:gnerator level's

Post by l3crafteur »

Nan suis français, j'utillise juste un peu google trad la x)
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Help:gnerator level's

Post 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.
l3crafteur
Prole
Posts: 9
Joined: Mon Jun 04, 2012 4:33 pm

Re: Help:gnerator level's

Post 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
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Help:gnerator level's

Post 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 ?
User avatar
Lynesth
Prole
Posts: 30
Joined: Sun May 16, 2010 8:47 am

Re: Help:gnerator level's

Post 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.
I'm always happy to be corrected if needed. I still have a lot to learn.
By the way, excuse my english.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Help:gnerator level's

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

Who is online

Users browsing this forum: Amazon [Bot] and 3 guests