Video Information
We’ve got an awesome let’s build today um this is me jim digital adventures we are going to be creating a minecraft map generator it is going to be awesome so one of the great things about minecraft is that it has a world that is generated somewhat randomly
Uses an algorithm or a pattern to create really cool uh endless worlds so we’re going to do that today first thing i need to show you is inside of my blocks right here i have three colors here that represent the different blocks that we’re going to
Have you can have more if you’d like but this project i’ll start with three each one is about the same size or exactly the same size and it’s called one’s called grass dirt and water first thing i want to try to accomplish is creating a line of top here of one color
And to do that i’m going to use the pen so i need to use grab the pen extension there if you don’t have it and let’s get started when green flag clicked what are we going to do um the first thing i like to do is erase the world
You don’t have to do so actually you can just kind of draw over it over and over again i’m going to have it erase each time so it makes more sense and i’m going to place that block this block sprite at the very top left so that would be
Minus 240 and 180 which would be the top minus 240 is the most left you can be then i want to create a loop so that it creates a block and moves forward or moves to the right so creating a block is going to be stamping i’ll explain the repeat until in a
Second and then we will change x which is moving to the right by 5. now that should work but then when i reach the end unfortunately we kind of stop i want to create code so that it will when it reaches the edge it will reset and draw my next line
So that’s going to need an if statement saying if it reaches the edge here move back and down and create another line operators we will need to see if the x position is greater than um let’s do 230 um 230 that’ll mean that’s about the edge 240
The true edge but scratch is a little weird around the edges so you have to kind of do lower numbers uh if it’s greater than 230 what i want to do is teleport that block or set x to minus 240 and then i want to move the y downward
Change y by minus five that’ll move it down five pixels and you will see i have the map being drawn maybe 230 maybe we could do 235 what do you think about that that probably reach the edge better let’s see if this works yeah that’s good you might want to turn
On turbo mode so that it draws it instantly but it’s also kind of cool to watch it go so why repeat until instead of forever because i need to end it once it reaches the bottom so i’m gonna say is if my y position is less than minus 175
Uh then this loop breaks so we’re gonna do this loop until the y position of the block is below here about here i don’t know i don’t know where exactly minus 175 is but it’s near the bottom when that happens we’re just going to end the program
And the map will finish drawing you don’t have to really end the program i don’t know it’s really up to you how do we change the blocks in there so one cool thing about minecraft is it doesn’t just pick random blocks and just like place them all over the place in minecraft it
It sees where you are or the block kind of can see where it is and see the blocks around it and then based on that it chooses a black as well as a little bit of randomness so like water blocks will be next to water blocks a lot of times
Because you need to create ponds and oceans and stuff so how do we program that into our project well i’m going to create three variables i’m going to create one called water dirt and i’m going to create a final one called grass for all sprites is fine
And these three are going to give us scores pretty much so every time a block goes to get created we are going to create a score and whoever has the highest score is the winning block and that one will be placed down it’s going to happen very fast
So let’s um get started with that i first want to just set them all to zero that’s always just nice dark grass and water at the beginning just set it to zero when green flag clicked forever and if else so it’s either going to be touching a
Another blue block or it won’t be and that’s gonna be in sensing if touching color if it is touching a blue block we are going to tell the game to set my water value the score for the water to a random number we’re going to say pick random number 1 to 10.
So that’s what i’m going to start with so it could get a score of 1 to 10 if it hits the blue but if it doesn’t we’re going to make it lower so one to three points so if it’s touching blue it could get 10 points and that’s pretty high score and
It’ll probably be a blue block but it could also get a one be you know a little bit random and um not be a blue block or water block i should say okay moving on after done with i’m done with water i’m going to try the dirt
I’m just going to duplicate this code here instead of touching this color i have to run this again to try and get the dirt color on there i’m going to grab dirt there and i will set my dirt so if it’s touching a dirt block there’s a chance it’ll get a high score
One to ten but if it’s not it it’ll get a low score and finally let’s do the grass blocks pop it right in here it’s a third one i’ll try and run this so i can get that color there i will grab my green i can make this
Bigger so it’s not so hard so i can do that grab the green block and if it’s touching green you will get a possibly high score otherwise a low score and you’ll see these numbers go crazy when we uh when we run it but they will be affecting what block will be placed
And to do that we have to make some comparisons forever if where’s forever okay so what we’re going to try is is we’re going to say if the dirt is the highest number change it to a dirt block if it’s if grass is the highest number change it to a grass block
And i like to use two ifs instead of using the am block sometimes because uh this can get a little bit hard to organize so it’s going to say if the dirt points is higher than the water points and then also the dirt points higher than the grass points it’s a dirt block
So we need two greater than blocks and we’re gonna grab the dirt we’re gonna say if dirt is better than grass and if dirt is better than water change switch to costume dirt okay dirt is complete now we need two more for uh what happens if grass is the highest number
And what happens if uh water so i’ll turn this to grass i’ll move grass over here and over here to help move water and dirt over here i did that kind of fast you can simply go into the variables and grab those out but now i have my grass
Is better than water grass is better than dirt code block and lastly we need water water needs to be better than dirt okay if water is greater than grass and if water is greater than dirt it will be a water block we’re going to switch to water let’s take a look and see
How this goes i’m you guys see these numbers go crazy i’m gonna get rid of those so we can see a little better go to full screen all right the map is being generated as you can see the blobs of uh you know green and the blobs of the
The dirt blocks and the grass blocks and the water blocks are all kind of sticking together you can see some rivers being formed and some an excellent world is being generated it will go a lot faster if you run this on the web it’ll probably be somewhat instant if
You go to scratch.mit.edu when you make your games the offline one that i’m using right now is a little bit slower in turbo mode there we go there’s my world it’s being created i can admit like there’s a nice peninsula here with some grant nice grass here’s another one
With a nice river here so you can imagine uh this would be a really fun map to play on and this is a you know how minecraft kind of in a way generates their maps now if you wanted to sort of change how this world would would look in general you can adjust
These numbers here to kind of create a new biome so let’s say i wanted it to be way less water what i could do is switch this to one to five and a one to two for the water points code and then we could take a look you’ll notice
Should be a lot less water there you go there’s a biome with a lot less water because i adjusted those numbers for how many points it gets and you can still see it kind of group up a little bit which is cool so this was uh the minecraft map generating
Project i hope you enjoyed it try it out remix it add some more blocks that would be sweet and you can check out more of our videos in our let’s play playlist and check out some of the classes at digitalventures.com we have tons of great instructors
And you can learn all sorts of stuff just like this so thank you very much and bye
This video, titled ‘Let’s Build Tutorial: Minecraft World Generator Game in Scratch’, was uploaded by Digital Adventures on 2021-02-03 22:43:04.
It has garnered 4923 views and 81 likes. The duration of the video is 00:12:04 or 724 seconds.
Jim uses Scratch to create a Minecraft world generator in this Scratch game tutorial. Learn how to create an algorithm that will create a random world like pattern similar to the one Notch developed!
Sign up for coding classes to learn how to build more great games and programs at https://www.digitaladventures.com