How to Make a Landscape Generator in Scratch
by CodeBuilder in Circuits > Software
721 Views, 2 Favorites, 0 Comments
How to Make a Landscape Generator in Scratch
In this step-by-step tutorial, I will show you how to make a super easy random terrain/landscape in Scratch.With this generator, you can make all kinds of games including: Adventure games,Minecraft related games,random animated adventures and so much more!
Supplies
Good news! You only need Scratch, a block programming website.This is the link https://scratch.mit.edu/.
One more thing you will also need these files so make sure to download it.
Prepare the Project
Once you are in Scratch find the “create” button, this is how you make a new project.Then press the costume section.On the bottom left side of the screen there is a cat with a “+” ,you will need to click it and upload a costume.Make sure to choose files and upload the three files.Afterwards,delete the cat costumes.
Congratulations, you finished the first step!
Programming
Ok time for programming, make two variables, name one Height and name the other, Slope. Now copy this (See pic 1):
when flag is pressed
set Height to pick random 2 to 4
hide
clear graphic effects
set slope to 0
set size to 75
After you copy this down you will have to go to “my blocks” (it’s red) and you need to make a block and name it “Generator” ,make sure it is running without screen refresh (makes it fast). Add the generator block to the pre-existing script.
Now under the larger “Generator” block copy this (See pic 5):
Define - Generator
go to -216 -157
repeat 10
repeat ({height}-1)
switch costume to “Landscape dirt”
create clone of myself
change y by 48
set rotation style left-right
if {(slope)=0}
switch costume to “Landscape grass”
else
if {(slope)=1}
switch costume to “Landscape slope”
point in direction 90
else
switch costume to “Landscape slope”
point in direction -90
create clone of myself
set y to -157
change x by 48
if {(slope)=-1}
change Height by -1
Height (height) //explained later ,it is another “my block”//
if {(slope)=1}
change Height by 1
Yep another “my block” ,but it’s okay because this will improve the speed of the generator, and is the the last one.In this “my block” name it “Height” ,just like the last one make sure it is running without screen refresh, one difference though because there is an input for a number or text.
Now this is for the “my block” named “Height” (See pic 6):
Define - Height (Number)
if {not{(pick random 1 to 2)=1}}
set Slope to 0
else
if {(pick random 1 to 3)=2}
set Slope to -1
else
set slope to 1
if {4<(Height)}
set Slope to -1
if {(Height)<2}
set Slope to 1
We are almost done (See pic 7):
when I start as clone
if {costume name = Landscape slope}
change size by 2.5
change y by -3.6
show
Now we are done!
Finished
Your done!Use your imagination to make this into anything.If you did it correctly it should look like the picture above, to make sure just click that flag and see it generate a random landscape.Hope you like it!