This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-01-23 02:06:37

JTxt
Scratcher
Registered: 2010-05-19
Posts: 100+

Chunkdata created as needed in a list for a Minecraft like game.

I copied this conversation from the byob thread so I didn't derail it.

Lucario621 wrote:

And, I've recently just about half an hour ago been working on a new project (tile-based), however, because there's no good way to copy lists, I have to use BYOB.  smile  I can't even individually copy items - because I want to have a "Visible chunk" list, and it has the visible chunk out of all of the chunks in the game (a chunk is a part of the world - so it can be rendered separately). So I can't just say copy from chunk1 to Visible Chunk - it has to be from chunk # (visible chunk (variable)) to Visible Chunk. Which isn't currently possible.

I was trying to figure out how to do that too.   smile
I don't think it's necessary to copy lists.  Although BYOB blocks would make it easier to keep track of the code.

Here's how I'd do it:

The game starts off with a seed for procedural generation.
The first time the player visits a chunk it's calculated and saved, so that they can add and remove blocks in that chunk.  (Another bonus is that it's faster to read from a list than to recalculate terrain each time you visit a block. caching.) 

For chunks:
You can keep multi dimensional arrays in a list, so a 10x10 chunk would take 100 items in a list... (sortof like this, look at edit mode) This list (chunkdata) can hold all your chunks as you generate them.  Chunks will be out of order...  created as needed.  You then have another list for keeping track of chunk references (chunkreference) 100 items long, starting out as all "0" for no references to the chunkdata yet.  100 long so it can hold references to 10x10 chunks, so a 100x100 world. But chunkdata only grows as the player explores.
(You could make chunkreference list/array much larger.)

So the player starts out at x50 y50, with division and rounding it figures out they're in chunk x5 y5 or chunkreference item 50 (x5*(y5*10), which is "0", and there's nothing in chunkdata so it starts at item 1.  It calculates the blocks based on the seed, while saving it to the chunkdata and drawing it on the screen.  So chunkreference item 50 was changed to 1.  Now the player can also change the chunk directly effecting that list by destroying or adding blocks.

The player then goes to x51 y56 moving the player to chunk 5x 6y, chunkreference item 60, is "0" so it does the same thing, saving it to the end of chunkdata (starting at item 101) and changes chunkreference item 60, to "101".
And so on for each chunk visited.

Does that make sense?

(edited: cleaned up the math and grammar some.)

Last edited by JTxt (2011-01-23 02:44:20)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#2 2011-01-24 17:55:27

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Chunkdata created as needed in a list for a Minecraft like game.

Ok, so I was typing a long response to this, however I was being a bit unorganized, and going off on many tangents, so I'm just going to say that after a while, I see what you mean, so my main information is this:

-This is all top-down view
-The grid is 16x12 (so one 16x12 area is a chunk)
-For testing purposes, I'm going to set the current limit to an array of 5x5 (25) chunks.

My main question is:

-How to I randomly generate a world from just one seed?

Here's the base if you want to make an example, and/or see how I made the rendering and what not, download it. Link (google docs).


http://i.imgur.com/WBkM2QQ.png

Offline

 

#3 2011-01-27 13:51:31

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Chunkdata created as needed in a list for a Minecraft like game.

Bump...


http://i.imgur.com/WBkM2QQ.png

Offline

 

#4 2011-01-31 16:20:45

JTxt
Scratcher
Registered: 2010-05-19
Posts: 100+

Re: Chunkdata created as needed in a list for a Minecraft like game.

Lucario621 wrote:

-How to I randomly generate a world from just one seed?

You probably want to look at noise functions.
http://en.wikipedia.org/wiki/Perlin_noise
http://freespace.virgin.net/hugo.elias/ … perlin.htm
http://www.student.kuleuven.be/~m021692 … noise.html this one may be simpler, yeah, look at psudorandom. I made an example (linked above), but may not be the best way.

I may have time to help, sometime, or at least I'll try to give pointers. Let me know how it goes.


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#5 2011-01-31 17:00:17

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Chunkdata created as needed in a list for a Minecraft like game.

JTxt wrote:

Lucario621 wrote:

-How to I randomly generate a world from just one seed?

You probably want to look at noise functions.
http://en.wikipedia.org/wiki/Perlin_noise
http://freespace.virgin.net/hugo.elias/ … perlin.htm
http://www.student.kuleuven.be/~m021692 … noise.html this one may be simpler, yeah, look at psudorandom. I made an example (linked above), but may not be the best way.

I may have time to help, sometime, or at least I'll try to give pointers. Let me know how it goes.

I see how that could be used to create texture of different heights of land, but I also want each chunk to randomly have a randomly set biome based on the seed, which are:

-Ocean
-Beach
-Hill
-Valley
-Pond

And with each of those multiply by 8, because of the 8 directions (certain ones will be the same at different angles, such as ocean). Also for all of them, the chunks have to match - there can't be an immediate land next to an ocean - there has to be a beach. This includes the directions. ALSO, I want different properties for each biomes. For example, for the beach, there would be a random 40-80% of it being a beach, and layered on top of that there would be 20-50% of ocean. And that has to be generated accordingly. Also, as another example, there would be different heights for the different sides of the valleys and stuff - and the x and y length of the hill, valley, and pond. It's a lot  smile

HOWEVER, I'll start with your idea  tongue . However, in that last link, what programming language? It looks like javascript from what I've learned (I'm still a newbie at it, but I can translate it to Scratch probably). What I don't understand though is "double" and "#define" and "void" and "int". Of course, all programming languages look quite similar  tongue .

After looking actually, it appears that it's "QuickCG" which is - foreign to me of course ^_^.

Anyway, I really don't know how to implement this Perlin Noise stuff into Scratch....  tongue


http://i.imgur.com/WBkM2QQ.png

Offline

 

#6 2011-02-12 16:44:42

JTxt
Scratcher
Registered: 2010-05-19
Posts: 100+

Re: Chunkdata created as needed in a list for a Minecraft like game.

Hey, this explanation for generating chunks may be helpful.

edit: Corrected changed link. (was this) Thanks Lucario621.

Last edited by JTxt (2011-02-27 00:32:41)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

#7 2011-02-15 22:57:27

vfire27
Scratcher
Registered: 2008-06-06
Posts: 21

Re: Chunkdata created as needed in a list for a Minecraft like game.

look at my minecraft project its not bad

but i got lazy to finish

Offline

 

#8 2011-02-25 21:03:00

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: Chunkdata created as needed in a list for a Minecraft like game.

JTxt, that link didn't work for me, but this one did: http://www.gamedev.net/blog/33/entry-22 … world-gen/

(I'm *guessing* it's the same post)

It's seems similar to the Perlin noise thing, and although all of these formulas are great, it might be a bit difficult for Scratch (well technically BYOB in my case) to interpret. I mean, it seems in the examples I've seen, they're only using Lua. Not that helpful.


http://i.imgur.com/WBkM2QQ.png

Offline

 

#9 2011-02-25 21:08:42

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Chunkdata created as needed in a list for a Minecraft like game.

... To hard for my young brain to comprehend///


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#10 2011-02-27 00:25:44

JTxt
Scratcher
Registered: 2010-05-19
Posts: 100+

Re: Chunkdata created as needed in a list for a Minecraft like game.

Lucario621 wrote:

JTxt, that link didn't work for me, but this one did: http://www.gamedev.net/blog/33/entry-22 … world-gen/

(I'm *guessing* it's the same post)

It's seems similar to the Perlin noise thing, and although all of these formulas are great, it might be a bit difficult for Scratch (well technically BYOB in my case) to interpret. I mean, it seems in the examples I've seen, they're only using Lua. Not that helpful.

Yeah, that's it. I'll fix the link, thanks.

The ideas are the same regardless of the language. 
Yeah, you're trying to do a difficult problem.  You can do it!

It is possible in Scratch, though I would simplify it.  Yes, Perlin may be too slow for scratch.  Earlier, I referenced another faster algorithm for making similar (kinda) smooth noise based on a seed.

Perlin or anything else, you'll use the data the same way to generate the landscape.  That's what the article is demonstrating.

To simplify, It'd just do 2d, then use it as a heightmap.
Then you can use a larger noise to decide the bioms... (in the article, they also use another one to decide caves...)

Does that help? 
(You didn't really ask for my help, you just said it was impossible in Scratch.  So am I feeding a troll?)

Last edited by JTxt (2011-02-27 00:27:19)


http://scratch.mit.edu/static/icons/buddy/524717_med.png?t=2010-06-15+09%3A48%3A36

Offline

 

Board footer