How (I assume) Minecraft mobs move around!

Im not 100% correct ok!

Javascript stuff

This is how I assume Minecraft mobs move around like sheep!

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.

Step 1: Directions!

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!

Step 2: Random stuff!

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!

Step 3: Switch statements!

What is switch? The switch is a statement that is basically a bunch of if, 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!

Learn more about switch for JS Here!. Its the same thing for C++ but Im going to link it for C++ Here!. Its also a same for a few other languages.

Step 4, applying it to some pictures!

Now all we have to do is apply it to some pictures! Here it is in HTML:

In JavaScript (Its actually ALL the code from the js file):

I will make some tutorials for the images. In the meantime, here are some other tutorials:
MDN web docs

What does this have to do with Minecraft?

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.

The end!

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!

You are viewing a single comment. View All