How (I assume) Minecraft mobs move around!
Lets say there is a sheep. It moves around randomly, right? Right. But how does it move around? This is a lesson on how (I assume) it moves around.
Lets start with directions. There are 4 directions. Top, down,(Front and back for 3D, but for now, were keeping it 2D) Left and right! Keep this in mind for later!
And now we will be focusing a bit on
random. We all know that computers can pick random stuff right? Well, for those of you who somehow don't know, they can. And now we can make the mobs move around! Not yet. But were almost there! And now we have our first tiny bit of code!
Learn more about JS random Here.
All we need is 2 more things!
switch is a statement that is basically a bunch of
else if, and
else stuff made a LOT less messier. For those of you who only know Python, than you might not understand this stuff. Anyways, this stuff will help us a bit in this. It SHOULD have worked for me, but for some reason it did not for reasons that are a bit too complicated. So were going to keep it with good old if, else if, and else. And we now have more code!
Now all we have to do is apply it to some pictures! Here it is in HTML:
<!--HTML--> <img src="black_image.jpg" alt="pixel" id="Pixel" width="25px" height="25px" onclick="poop()">
This is just a really-simple version of what Minecraft mobs do. Except they are WAY more advanced because if a hostile mob detects a player or if a you are holding wheat and sheep are nearby. And flying mobs are WAY harder to code I guess.
I hope you enjoyed this tutorial and PLEASE upvote it if you learned something new! And check out the repl below to see it all in action! And thanks to @Coder100 for helping me with the images moving around!
I dont know how to conclude this so bye!