Creating Minecraft in Python [with the Ursina Engine]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there in this tutorial we are going to create a really basic minecraft clone in python and well it works like any other minecraft game you can create blocks you can destroy blocks and i also have different blocks that you can just switch to just to make it a bit easier and there are quite a few different ones and you can just work with them and play around pretty straightforward when it comes down to it and of course with that you can make well in my case a really simple house but if you want the tube you could just add more stuff to it or get rid of stuff well it's basically how minecraft works and all of this is made with the usina game engine so let's talk about that one the ostina game engine was released sometime last year and it's a really neat engine it can do really powerful stuff with very few lines of code for example the entire game you just saw took about 90 lines of code to write and you can make it in about an hour it's really easy so it's quite a good engine for beginners i feel and especially for 3d games osena is quite a bit more powerful than pygame for example but that doesn't mean it doesn't have problems and there's one big warning i do have to give that your cena game engine is only available for windows and linux so if you have mac os i'm really sorry this tutorial is not going to be for you but with all of that out of the way let's first do a brief introduction to the cena game engine and once we have the basics covered we can actually come to making the game so for this part we're talking about how cena works and how we can make some basic stuff with it and obviously the very first thing you have to do is to install it so in the powershell type pip install cena and then you should see a fairly lengthy dialog to install it and once that's done you should be good to go this works like literally any other module for python and once you have installed it go to the code editor of your choice in my case sublime and type import or cena and now if you run it you should be getting a message that is something like this the really important part you're looking for here is that you're not getting an error message if you don't you have installed it properly and now that we have that let me close it we can actually start working in oceana and the first thing we need to do is that i don't want to import usina by itself instead i want to go from from yocena import everything so star and the reason for that is that there are lots of objects that rely on oceana and having to type ocena every time is going to be quite cumbersome and now we need two lines to create the entire game the first line is to create the basic instance of the game and this has to be stored in a variable that i'm going to call app and to create this one all we have to type is orcina and make sure the first letter is capitalized that one is important and once we have that what i want to do is app.run so i create an instance and i run the instance and with that if i run my code now we get a really basic window we can see our frame rate and we can close the window that's about it nothing much happens yet but it's already a really good start that we have a window with just two lines of code so for example this would be much easier than pygame for example now we have to figure out how can we actually put stuff on the screen and for that we have to understand the most important concept for oceana and that is called entities and an entity in oceana can basically be anything it can be square it can be a cube it can be a circle it could also be a button basically anything you see on the screen is going to be an entity and then when you create this entity you can customize it quite a bit and once it's created it's automatically added to the game so all you have to take care of is creating it and then you're good to go so let's create one i want to create let's say let's call it test square where i just want to create a basic square on the screen and for that we have to create an entity and now we have to give it a couple of arguments the first one is what's called the model and this one determines what kind of shape it's going to take so is it going to be a cube is it going to be square is it going to be a circle and for now let's just go with circle that tends to be a really easy shape and with that we would get a circle and now let's give it a color argument and for that i need the color keyword and to assign it any color i need the keyword color and then the color i want to go with let's say for now let's go with red and with that we should have a red circle so let me run the code and we can see a red circle right in the middle of our screen so this one's working really well and what you can do now is change this circle to something else so for example if you want to square you would need the quad keyword and if i want to go now we get a square now you could if you wanted a cube so a three-dimensional object you could type cube in here although if i run this because we're looking at only one side of this cube we can't really see it but we're going to come to that in just a bit for now don't worry about it and let's leave it at the quad for now that one's the easiest to see and what you can also do in the parameters here is you can for example set a scale and then they can pass in a tuple with the x and the y scale so if i passed in let's say one and four we would stretch it four on the y and one on the x axis and of course you could also change the position and this could for example be let's say five and one and let's see what happens so now we have moved the entire thing one unit upwards and five units to the right and a really important thing here is that the origin point is in the center of the screen so y has to be positive if you want to go up has to be negative if you want to go down kind of like it would make sense and just to demonstrate it let's make this a higher value to 4 and now we get even higher so this would be quite different compared to pie game for example so now we have a basic thing on the screen how could we move it and that is also really easy in oceana because all we need is to create a function so def and this function has to be called update it doesn't need any arguments and this update function is going to be called biocena on every frame automatically so as long as you have this name and function you are good to go so for example what i could be doing in here is just to print test and then run the entire thing and now in the console you can see we get test quite a bit and now if i wanted to move this test square all i would have to do is to get the object itself and then influence one parameter for now let's go with x and i could just change the values so i could go with minus equal 1 which would move it to the left although if i were to run this right now we go really fast so this is way too fast and this would also not adjust to different frame rates so this would be quite inconsistent but all we have to do to fix that is to add times time dot delta so this is the time between different frames so if we multiply this with the movement speed our object is going to move in accordance with the frame rate which is going to make our game quite smooth so now let's try it again and there we go this feels much better cool and we could even make it a bit faster let's go with minus equal four and yeah that feels better cool now you could make this even more sophisticated by adding keyboard input and for that all you need is held keys and from that we just have to pass in one specific key let's say my case a and now i have to indent this and i can just run the game again and now this thing is only going to move to the right if i press a and that's all we need and this could be any letter on your keyboard any number or even your mouse keys it's really flexible and all right with that we have our basic object and we have a way to move it now what we can also do let me add another square and let's call this sun's you've seen a second why and for this one i want to add a custom texture but i can add any kind of picture i want into this and for this i am still going to need an entity and the entity is supposed to be a quart again so we're getting a square and now i want to add a custom picture to this and for that i will need the texture keyword and now for the texture i have to create a texture and there are a couple of ways of doing it the one i would recommend is to create a texture in its own variable and then we need the keyword load texture and then you can select from your folder in my case i have a folder called assets and in that folder i have a file called sans.png and now that i can just pass in here and let's try now let's see what happens and now we get suns from undertale pretty nice and easy and we can actually make this easier we don't actually have to do this entire line we could just pass this straight into here and it would load automatically so if i run this now this would also work perfectly fine so this would be fine but i generally feel like importing all your textures at the beginning is a more readable way to approach this but it's ultimately up to you so with that we have a couple of really simple objects in our game but in an actual game you really want to have more control over all of these things so this kind of thing is generally just to create really simple ones if we wanted to create more complex ones we could also do that and for that we have to create an entirely class that inherits from an entity for example so let's create a more complex cube and with that we can also go into 3d so i want to create a new class and let's call this one test cube and this one has to inherit from entity and now and there i want to create an init method it needs self and nothing else or you could pass something in there would be fine and then there i want my super method and then the init and now when i initiate the parent i can specify a ton of different arguments so in here for example i could create a model for now i want a cube i could give it a color let's give it let's say the color white just for now and then of course i can also give it a texture and osena has a couple of textures in build that you can use one of those is called white underscore cube so this one you don't have to load it's inbuilt into a c now and with this we have our own class that we can add lots of stuff to that is something we are going to do in just a bit and now all we have to do to create an actual block from this class is well to call it so let me call my test cube and this is supposed to be my test cube class and now if we run this we can see a white cube right in the middle of our screen and you can't really see that it's a cube yet so let's give it some rotation and for that all i have to do is to give it a rotation argument and this one needs to be a vector 3 with the x y and z rotation and let's just go with 45 45 and 45. so now if we run this we can see our cube so this one is working pretty well and you could still move this thing around with position and this would work perfectly well now with that we have already quite a few things covered but there's one more concept we need before we can get to the actual game and that is to create a button and buttons work slightly differently or well not that much let's actually create one that's going to be the fastest way so to create a button i still have to create a class and i'm going to call it test button and this one has to inherit from a class called button itself and now here i have to create again a done there init method that needs self and inside of that i want to get my super method and init that one and in here i can create lots of different stuff for the button so for example my button could be a cube just like my test cube i could give it a texture and let's say another inbuilt one is called brick i could give it a color and this one would be let's go with color blue just to use one we haven't seen yet and with that we have a really basic button let's actually create it and let me get rid of the test cube just so we don't have it in the way so now instead of test cube i want a test button and now if i run this we can see a giant button and you can see if i hover over it it gets slightly brighter but now it is kind of weird how buttons work because this button is significantly larger than this test cube and the reason for that is that a test button needs one more argument and is called the parent argument and the parent we need is the scene so the actual game scene again and now if i run this again now we can see the normal size button i am not actually sure why the parent argument is needed for the test button but not for the test cube it's a little bit weird but if you want to create a button this has to be parented to the scene and that's the actual game what we can also do for a button is to give it different colors depending on what you do with it so for example there is a highlight underscore color argument that changes the color if we hover over the button so this could for example be color let's go with red and then we also have a pressed underscore color and this is the color we get when the button is pressed and for this one let's go with color dot lime and now if we run this again we get our button if i have over it it becomes red and if i click it it becomes green so this one is working quite well and now how could we use a button and well this one is also incredibly easy all we have to do is to create a new method that is called input it needs self as usual and then it needs one more argument that is called key and that's the key we are pressing to activate it and now inside of that method we have to create an if statement that if self dot overt so if our mouse is over the button and inside of that what we want to check is if key so the key we pass into it is equal to the left mouse button argument which is called left mouse down and if that is the case let's just print button pressed and now if i run out of this it's still working and if i press on the button we get button pressed so this one is working pretty well and with that we can actually come to the game so let's talk about minecraft and really the one important thing you have to know about minecraft is that minecraft is a voxel-based game and really all that means is that every single block that you see in minecraft is a voxel so these are the things that we have to create ourselves but besides that there really isn't other much else that we do need so let's actually jump straight into our code again and let's have a look at this all right welcome back i have gotten rid of all the code i have used to explain with cena itself so all we have now if we run the code is an empty window that we can use to create an actual game and the first thing i have to do is to create a new class for all the voxels we want to create so the class is going to be called voxel and this one has to inherit from the button class for the simple reason that whenever i click on a voxel i want to create another voxel right next to it so i need to know where each voxel is that's why it's a button and in here we need our init method again itself and nothing else for now at least and let me just type it properly and in here we again need the super method with the underscore init and now we have to specify a couple of arguments the first one is parent the one that we have seen earlier this would be scene so the actual scene of the game next up we would need a position and the position for now let me just place it at 0 0 and 0. although this we are going to change later when we set up the game next up i want to create a model so what the thing is going to look like and this one for now is going to be a cube although this also is going to change at least somewhat then i need the origin y so effectively the height and 3d space of this cube and this one is going to be 0.5 and once we have that we need a texture so we can actually see the cube and for the texture for now i'm just going to go with white underscore cube the one that we have seen earlier and this also we are going to change in just a bit for now i just want to have a basic setup and next up we are going to need a color and one important thing you need both a texture and a color and both of these colors are going to be multiplied together so if you only have the texture and no color it is going to look weird and for now let's just stick with white i think that's going to be fine and besides that i also want to create a high light underscore color and this one let's go with color dot lime so really all that's happening here is we create a button that is going to be a cube with a white texture and if we hover over it then it's going to be lime colored then we have a position 0 0 and 0 so it's right in the middle except it's slightly lifted up by 0.5 that's really that's all that's happening here so now that we have all of that we have to create our button and for that let me put it right between those two lines of code i could just create voxel is equal to voxel and let's actually run this and let's see what happens so now we can see one button and it becomes greenish when we hover over it so this one well it's a start but i don't just want to create a single button i want to create multiple and to create multiple buttons really all i need is for z in let's go with range of 8 so i want to create eight blocks in the z space and inside of that i'm going to go for x in range eight so effectively what i have done is i have gone forwards and backwards by eight units and then i've also gone left and right for each of these units and now what i can do in there is to create a voxel and then this voxel is always going to get the voxel class itself so this way we are creating 64 voxels and now if we run this we still can't really see it and the reason for that right now is because they are all in the same position so this one doesn't really help us so i have to place in some kind of information in here to customize the position so when i call this class on the init method i want to give it a position that by default is supposed to be zero zero and zero so that we always end up with this position if nothing is passed in here and this one is getting position so if i run this again now nothing is going to change but what i can do now when i create all of these voxels i can pass an x 0 and z so that we actually use this information and this information to place each individual voxel so now if i run this again we are getting an error because all of this has to be a tuple and i could even give it the position keyboard and now let's try this again there we go now we can see all of them right next to each other the problem now is how can we actually create a first person character in all of this and in here usina makes this incredibly easy because it has a couple of predefined classes that we can use to just create a first person character we don't really have to do anything ourselves for that and really all we have to do is to import something else first and what we have to import is from usina dot prefabs dot first underscore person underscore controller and then import first person controller i hope i spelled that right so this by default is not being imported into oceana so we have to do it ourself but once we do have it all we have to do to create a first person character is to create a new variable where we store it and then call first person controller and this is also class so we have to call it and now i can run the game and we get a first person player so well with that we already have really the basics of what we need for a game and the buttons also work and the collision between them also works automatically so you don't have to worry about this at all which is really powerful and now if you do want to close the game because you can't use the mouse anymore i just switch between my windows and then close it from there this tends to be the easiest and cool now we have our first person controller and if you want to make all of this larger we could go with something like 20 times 20. and now we have a much larger field although one of the problems with the game right now is that if you added too many of these fields the game would slow down so there would be quite a bit of optimization work to do but all right what we have to figure out now is how to make all of this more interactive so how can you create and destroy blocks and again this is going to be super easy because effectively what we want to do is that if you press on the voxel button then we want to create a new block on that position so the first thing we have to do is to create a new button press functionality and this is something we have seen earlier because this voxel is just a button that we can press so we can give it an input method and this one itself and key separated by a comma and in here again i need if self dot avert and now i want to check is if e is equal to left mouse down and if that is the case i want to create a new voxel and this one again is going to need the voxel class so really what's happening in here is if we are pressing this button we are creating a new button in a certain position that we can specify and now we actually have to specify the position of this button and there are two parts we have to combine the first one is self dot position so that we get the position of the button we are pressing right now but then we have to add mouse dot normal and once we have that i can actually try all of this and see if it works so now if i press on any button we get a new well voxel button cube thing so this one is actually pretty good start so what's happening here and let me explain in the game that's going to be the easiest so here we have some more space so right now i'm looking at this button here or this voxel so i get the position of the voxel itself and the normal is the surface we are looking at so right now the normal is pointing upwards and this is what we are using when we create a new voxel button that we want to get the position itself plus the upward direction so when we press it that's where we are going to create the new voxel button and this we can do for any kind of surface that we just get the position itself plus the surface we are pointing at and in what way it's facing and once we have that we can really create all the different cubes that we wanted and this is pretty much a perfect minecraft functionality so really nice what we can do now is to add another if statement if we wanted to destroy all of these boxes so if key is equal to right mouse down and all i need to destroy a button is the destroy self and this is literally all we needed so now i can run the thing again and if i left click i create a voxel if i right click i destroy it and with that we can even create our bottom itself and fall into a bottomless pit of nothingness hey it's working and one more thing that we could be doing is to change the color and give it a bit more variety so right now every single block is perfectly white which well tends to get a little bit boring even if we added textures so instead what we can do is to give it color.color and in here we can specify rgb values and in my case i want this to be 0 and 0 and then i want random dot uniform and this is supposed to between 0.9 and 1 so that the color of every block is going to be slightly random and now if we run this it still works and now each of these blocks gets a slightly different shade of gray although there's one more thing that i am slightly confused about is that what these specific arguments in here mean is a bit confusing because if you change this one from zero to one nothing really seems to change however if you change the second one to a one now the entire thing is going to be red so i assume these values are going to be rgba but i'm really not entirely sure but let's leave it for now as it is and it's perfectly fine and all right with that we have a really basic setup for a very simple and nice game setup that works kind of like minecraft and all of this is exactly the same setup for one of the demos for usina and this is exactly what i have copied so if you've gotten this far you have basically replicated one demo from the cena game so definitely check out the github page and there are lots more examples i would really recommend to check them out they're really fun to play around with but alright now that we have our basic setup we can make all of this look much better and there are a couple of things that we need to make all of this work and let's start by creating proper cubes that we can use this is going to be the biggest change that we can and to create proper blocks with the proper textures we do have to cover one specific topic that right now we have used an inbuilt cube which worked decently fine but it's very limited in terms of how you can add a texture to it and the reason for that is that there's no uv map for it and a uv map is basically how you wrap a texture around a cube or really any 3d object and the default cube in oceana doesn't really have a uv map so when we apply the proper texture to it it wouldn't really work so what we have to do is to create our own block and apply texture to it and then import all of that into oceana which fortunately is really easy and i have used blender to create a basic block and in the project folder for this game i'm going to link the blender file in case you want to have a look at this but i'm going to import the finished file itself which is going to be the most straightforward way but let's go through it step by step that's going to be the easiest one so here i'm back in my code and the first thing i want to do is to get rid of this cube and instead what i want to do is to import from my assets folder and there i have a file called block and this is assets block and this block is a block i have created in blender that has a uv map so if we applied a more proper texture to it it would show up properly as a matter of fact i have created a couple of textures and just to save me some typing let me paste them all in so i have a grass texture i have a stone texture i have a brick texture and i have a dirt texture and all of these get a texture loaded right into the game and now i don't want to use the white cube texture anymore instead for now let's just go with the grass texture and let's actually look how this looks ah and if i run this now we get an error but a simple reason that we first have to create oceana and only then we can load textures so i need app is equal to cena first and then i can run all of this and now let's try it again this should be working now and there we go now you can kind of see the problem that the positioning is kind of messed up and the reasoning here is that the default buttons are a different size from the buttons we have imported but that we can change very easily all we need is scale is equal to 0.5 so now if i try this again now this looks much better and i can still create all of the blocks and i get my basic blocks so this one is still working exactly the same way except now we have a nicer looking texture edit and also what i want to do now i want to get rid of this highlight color because it makes the entire thing look kind of weird so now let's try it again and yeah i feel this is looking a bit better but you could leave it if you wanted to alright so now we're making some progress but i don't want this grass texture every time instead i want to be able to pick from any of these textures so what i want to do is when i create this voxel class i want to assign it a texture and by default this should be the grass texture but if i specify the keyword this could be any texture in here so now if i run all of this again we should still see the same outcome cool but now what we could be doing is when we are specifying the voxel itself let's do it down here actually let's do it up here so you can see the difference a bit better so whenever i click on a voxel i want to give it a more specific texture and let's go with the stone texture so now the default voxels are going to be the grass texture but when i click on one i'm creating a stone texture or a stone so now if i click on something we are getting a stone cool this is working pretty well and really all we have to do now is to figure out some kind of input that we can select specific kind of textures and what i have done is i have created an update function so the same thing we have seen earlier and this one is going to be run on every single frame and effectively what i have done in here i have created a new variable actually outside of it that i've called block underscore pick and by default this is one and then all i'm doing in here is if held underscore keys one then i want to set block pick to one and now i can copy this thing a couple of times and change this to two three and four and then 2 3 and 4. and i have to set this to global block pick so really all that's happening in here is that if i press any of this button this block pick gets a different number and this we can then use further down here to influence how this entire thing is going to look so instead of just creating a texture itself i also want to check if log pic is equal to 1 and if that is the case only then do i want to create a voxel with the let's put this one for the grass texture and i think can put all of them on the same line that makes it a bit more readable and with that i am only going to create a grass texture if block pick is equal to one but let's say if i pressed two then i want to create a stone texture if i picked 3 i want this to be a thing i call this a brick texture it was indeed a brick texture and then for number four i want this to be a dirt texture and all right let's try this now let's see what happens so i'm still in my basic game if i clicked just by itself we get this but now if i press two on my keyboard and try this again we're getting a stone block if i press three we're getting a brick and if i press four we're getting some dirt or however you call this one and alright this is really starting to come together so this is already helping to make the game look nicer but there are three more elements that can really help to bring the game across number one is the skybox number two is a hand and number three is sounds and let's go for them step by step the first one is a sky box and a skybox basically is what we can see as sky but to emulate this in our game all we basically do is we create a giant sphere that has a sky texture on it that's really all it is and well we can go straight to creating it it's super easy to do so here i'm back in my code and what i want to do is to create a new class that i'm going to call sky and this one is just going to inherit from entity and in there i need def init and it needs self nothing else and in there i need my super and then init and in here we have to specify a couple of things the first one just to be sure is the parent which needs to be the scene so we're part of the actual game but now for the model we need something new and that is a sphere so well a round object and now for the texture i want to create a sky texture and this one doesn't exist yet but all we have to do is to import it so in my textures i want a sky texture and let me line it up properly i want to lower texture again and in my assets folder there is one file that is called sky box dot png and this is the one i want to use let me add a bit more space below the class itself and this would actually already give us something so let me actually create it so below the player i'm also going to create a new variable called sky and this one gets my sky class and let's run the entire thing and see what happens i'm getting an error because this is supposed to be a comma now we go okay right now i can't see anything but if i turn around there we can see a very tiny world so this thing we want to scale up massively and really all we have to do is to give it a scale argument and in there i passed in 150 so now if i run this again we can't well we can't see anything and well the reason for that is that this texture right now is only on the outside so if we are inside of this object we can't see it but we can change this very easily all we need is double underscore cited and this needs to be true and now if i run this again this should be working and there we go now this is looking much nicer although this isn't the perfect sky texture especially you can see there there's one seam this is where the texture start and end connect so well this isn't great but i think it's good enough for now so with that we have our sky now i can close this class and never think about it again now the next thing i'm going to need is a hand and this one is purely decorative it doesn't really do anything besides simulating having a hand it's a really simple thing and for that we are going to learn one new thing but i think this is best explained by actually implementing it and i want to create a new class that i call hand and this one is also going to be an entity and in there as always i need my done there init method that needs self and nothing else and inside of that i need my super and then init for that one and in here we have to specify the parent but the parent is not going to be the scene instead it is going to be camera dot ui and let me explain what that is so far we have only used the scene and this is the actual 3d space of our game the camera ui is the actual 2d space of our camera so if you want to create a ui it would be on this space and this one is not going to move along with the game itself it's just a static space that is kind of on top of the game itself it's essentially a glass sheet that the player is looking through or in most other game engines this would be a viewport this would also be a good way to think about it now what i also want is to give this a model and again i have a custom model that is in my assets folder and it's just called arm and this also has a texture and the texture let's load it straight in there and i call this one arm texture that needs an equal and load texture and this one is also an assets and i've called this one arm texture dot png and now i can assign this texture it's arm texture and with that we have our basic hand let's actually create this object using the class so i call this hand and let's see what happens so well um it's a touch large i feel so what we have to do for now is to make this entire thing a little bit smaller so i want to go scale 0.2 an equal sign and let's try this now and now we get a much better proportioned hand although it's pointing right at us so that's not great and for that all i have to do is to give it a rotation and a position and the rotation is going to be a vector3 and the rotation i went with is 150 negative 10 and 0. and let's try this now and there we go now we can see our hand a little bit better although it's still in the completely wrong position but well we are making progress and the rest still works perfectly fine so now let's give it a position so position is equal to and this needs to be a vector 2 because we're moving in a 2d space and i have moved this 0.4 to the right and then downwards by negative 0.6 and now let's try this again and now this is looking much nicer cool so with that we have a basic hand but right now it doesn't animate and well that looks a bit weird so let's add a really basic animation although calling it an animation is well kind of overkill of course all i've effectively done is that if the player presses the mouse button their hand is in one position if the mouse button is not pressed the hand is in the default position that's really all that's happening here it's not really an animation but you could very easily make it one all i really have to do is to create a method for this hand that i called active and in itself and in there i changed the hand position and rotation to be more in the middle of the screen so i need self position and self dot rotation and no comma or bracket afterward and for the position i went with 0.3 and negative 0.5 and the rotation i actually didn't touch so we can just leave it as it is and then for the other state passive ozone itself and for this one i just took this position and assigned it to it so self dot position so now we have two methods that can influence the position of the hand and if i click the mouse i want the active method to run if i don't click the mouse i want the passive method to run so with that i have to go to my update function and add another if statement in here and let's do it right at the top although it doesn't really matter and really all i want to do is if held keys as left mouse or held keys is equal to right mouse so for pressing the left mouse button or the right mouse button we want to trigger one of these and here's something slightly weird that if you use the update function you have to use the left mouse however when you use a button you have to use the left mouse down so it's a slight difference be careful with that but right now we have our if statement and all i have to do in there is either hand dot active and if that's not the case i want hand dot passive and that's literally all we have to do for the hand and if i run the code now and if i click my hand moves a tiny bit or at least we get the illusion of a movement but everything else still works really well and well this is quite nice so we are really making some good progress cool and really all that's left to do now is to add a sound to it and this is also really easily done i first have to import a sound and i have called mind punch sound and this now happens with the keyword audio and this is also new class and when we initiate this sound we need again a file and i have one in assets and i called this punch underscore sound and i didn't need the file ending and now we have to specify a couple more things the first one is loop and this one is supposed to be false because we only want one punch sound and i need autoplay and this is also supposed to be false and with that we have imported our audio file so now we have to figure out when to play it and the one i went with let me minimize all the other parts is that whenever you click or delete one of these cubes then we are going to play the sound and all i have to do to play a sound is to get the sound itself and then play and i want to do this for both creating and deleting a block so let me put this above destroy it feels better and now if we try all of this we ah i think i made one mistake let me get out of it so right now the sound is kind of double playing and the reason is well quite simple that whenever i call the input method and we're hovering over any of the buttons then we are playing the sound but i only want to play the sound if we're actually pressing it so that way it's going to work properly and now let's try this again and this is feeling so much better and cool this is basically the finished game there are a couple of tiny things that you can do and well they're really tiny basic things so let me do an all the way to top what we could do for example is window dot fps underscore counter dot enabled a build is true right now but i want this to be false so we can see a tiny number in the top right i hope this i feel makes the game look a bit nicer and since we're not using the escape button we can also hide that one so window dot exit underscore button dot visible is equal to false and now we get the whole window and this is literally what i have showed you earlier at the beginning of this video really what you can do now is just keep on building different blocks and just add more and more stuff towards it and get rid of stuff if you don't like it it works pretty well so well that's pretty much it there are a couple of things you do want to be aware of number one is that well lots of things are missing that we don't have an inventory we only create a very basic square and not much is happening yet so if you wanted to expand this entire thing you would have to add quite a bit more code because in the current setup if you had too many blocks the game slows down very noticeably so this would be one thing to work on number two is that if you look very closely at the textures you can see it very well here is that there are lots of little seams between them which happens because i well i didn't spend too much time making them because this is just a demo but if you spend a bit more time on them you can make them look much nicer and well you can also add an inventory and lots more tiny things but well what you have so far is essentially a basic start for the game so if you play rhombus more you can probably make quite a bit more of this so i hope you enjoyed and i will see you around bye
Info
Channel: Clear Code
Views: 1,180,845
Rating: 4.939362 out of 5
Keywords:
Id: DHSRaVeQxIk
Channel Id: undefined
Length: 48min 53sec (2933 seconds)
Published: Wed Dec 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.