holy Japan PC in today making health tour if you guys now I’m sit like I thought I’m recording this but I’m experimenting with different screen recorders because lately chemist chemist Eddie hasn’t working for me it’s been like a bad mesh between Sony Vegas and my loot my laptop and camstudio and it is I’m just trying new things so hopefully this the quality for this video will be a little better than previous ones so this is part 2 of my Angry Birds tutorial in the previous tutorial I talked about the physics and it’s favor can go into game maker and I’ll be showing you how to use those physics concepts in our game so start off we’ll create two sprites first one kspr bird click Edit sprite add some image transform resize the canvas and set 24 by 24 that’s just the size that I felt worked pretty well with them our sling so now we got our edit mode I’m just gonna select right accepts the clutter the main bird and I didn’t make a quick circle there we go that’s it for the bird one last thing is make sure that origin is at the center did this make the coding work better for us and then next we can create two sling that’s right again new subpage transform and resize and it’s like keep asset ratio set the width ur t2 and the high ticket support alright then I think I’ll go in there now it’s like a line tool and orange coloring and make the line a little bit thicker and then I’ll just draw a quick sling this tutorial isn’t about graphics about programming so I’m not gonna spend lot of time on this kind of stuff so there we go that’s the rather horrible sling and we’re gonna set the origin to X X 16 Y and 0 so be like right between sling all right now moving on let’s create our first object we’ll call obj slowly in the Krrish mint all we can do is create one variable I’m gonna call it I’m gonna call global dot it’s true true this way this vapor will represent whether or not the the Burgess is has been shot yet Oh is the bird still in the sling or is it out in the in space and subject to gravity so sling equals true me is still attached to the string we made it’s a global variable so that we can be accessed by other objects so that’s it that’s the circumstance we need use global alright moving on Larssen go to the draw vent and we only drew the stick for the sling who wouldn’t want to draw the actual band for it so first offices for the draw of in we’re gonna need to draw the sprite because whenever you go into the draw in it overrides everything else that’s happening everything else is being drawn so the first argument is sprite so we have a sprite index cuz that’s the index of the sprite we can only have next one some image so when I set my image index which is the in the subject we currently have and then like some X&Y and that’s all there’s to it and if you have game maker 8.1 or higher you could type down the draw itself like so that way it’s the same thing as the collage but definitely it’s a lot quicker as you can see all right now we’re gonna draw the two lines that rubs in the band go around the bird and so I’m gonna type down so we want drug bands only if Goldust triangles true only if we’re in the stage where that were in this link so if global dot swing equals true we’re gonna draw two lines one one coin from the less left front and clean from right from wrong so draw line X minus 14 comma Y so this is B the coordinates of the left front we want to talk to the bird obj bird X comma obj bird Y now OPG a bird is not yet so highlighted because we haven’t created it yet but we’ll be creating the second next line we’re gonna draw is exactly the same only the x coordinate is X plus 14 right of X minus 14 all right and that is all we’re gonna need to do for this link make let’s make sure that this there and move on to create our bird obj virgin yeah that’s right and I didn’t move on to Trish in it so all I want to put down we want to make two variables first mass equals one we’ll be using the mass for some of our calculations it’s technically not necessary from programming point of view but I also want to make sure you guys understand the physics behind add mass is important in physics so um next thing is clicked

we’ll be using that for our calculations so if it’s clicks we want to be able to we won’t feel the drag it if it if it’s in the sling that is so first off he goes false because we haven’t clicked it and then we do click it so mouse left pressed and that happens we want to its that clicked we call it true all right and then if the mouse button if the left button is being held in at any point time so global Mouse left button then that means that we would want it to move with the mouse if um it’s in the current if we’re in this link stage and if it’s being clicked so if global dot slang equals true and clicked equals true then I want to move it the mouse so set X equal to the what the x value that my mouse which is stored in the constant Mouse X and it was at y equal to the Y value the mouse which soared the constant that’s why like so all right there we go now now I need to take care of when the mouse is released so when we want to want the bird actually launched so would a mouse global left released so again we’re going to check if it’s in this sling stage and it also going to need to check if it’s if the mouse of the what birds being quite so clearly goes it’s true all right well you just check my notes all right so this is where all the magic happens of the initial movement so first off click equals false because once we release it you know every being clicked so plays equals false and next global Oxley equals false cuz it’s been released so it smooth moved on from the stage of being in this link to being shot out into space and then here’s the here’s the important part where I set the H speed equal to obj sling X minus X and so the further away um so let’s see this will be the same but we’ll be controlling this value depending on how far we dragged on their mouth so the further we drag it AIESEC is rejected left so the further we drag X to the left the smaller it would get and therefore making this a bigger number so the biggest is the further way we dragged her from dragging it from them from this sling fast the H beat is and we’re it’s almost like a point 1 5 just to make sure it doesn’t get too hectic on the first part of speak code and then and then this we want to be equal to our force so we’re gonna go ahead divide that by mass like I said earlier um it’s not really important for programming expect perspective but I want to use I understand that we’re making a start force and force equals mass and acceleration so I’m divided I’m ask ourself acceleration and we’re setting a speed equal to our initial acceleration no other speed affecting at that point and then we can do something pretty much exactly the same for the RV speed so obj sling Y minus y times 0.15 and then all parentheses and divided by mass there you go simple not okay and I believe that’s all everything alright one more thing so we shoot the bird and then it moves but but we want to be able to test it a few more times than that so when you put some code in there to make it um restart from the beginning so I’m gonna say to you guys even other outside grams so once the bird it’s outside the room we’re gonna restart the room surround restart well set and I’ll sell burger let me test it it’s like I said huh and I’m going to set go to settings and change the dimensions to make it fit my recording window better and to make it look nicer overall and then we’re gonna go down to the bottom left corner so I’ll be down this area when I just make go and make this bigger so I’ll put the catapult down for this thing I guess give it a little bit space over here in this area for um for the bird to be dragged back and forth as far as the Brits are inefficient it’s gonna be right there the center but we got it I’m afflicted underlining there you go right there at the center so we can go and plate now

okay so now I click it now move it around we just click to go chew it within the bird and lines are being drawn from the catapult over to the bird show that we’re being good speed right back and once I release it it shouldn’t move it doesn’t I I the variable is clicked but I tacked on click at one point I apologize for that but no worries it’s the glitch told us exactly happened so we just go right and the kodan fix it so that was right here and see I’m talking click we want to be clicked all right no worries test out together okay so now click and everything else about us what we can find and I release it now it was actually moving you know good southern room it goes didn’t restart so that no matter what direction I go see it goes in the direction and accordingly very good now that was the initial part now we’re gonna add on some planets so today we’re gonna create two sprites yeah first one called SPR planet one that’s right add some just transform resize and then I’m gonna make this one nine six by ninety six and then let’s see else like blue and I make a circle just like we do at the bird these are alpha sprites presumably if you were making and using these concepts you’d make them a lot better okey okey I’ll create another planet it’s pure planet – that’s right now um earth of physics soil we want bigger planets orbit plants the one has to have a stronger gravitational pull so we’re gonna make this one bigger to illustrate that concept so two five six by TV excitedly but not as I go back to 128 by 128 that’s what I did yes that’s what I did and we’re gonna make this planet green it’s a very bright green for planet but it will we don’t care there we go and it’s important that we Center both these planets for that coating okay now I create hajeck both of them Oh Jake planets one side sprite now there’s two variables who want to set even the first night 1st of April is mass equals 3 x power 10 comma 13 all right this is a very big number so 3 you know 3 we’re multiplying through by this number and I’m if you’re in let’s see if you’re I suppose if you started algebra you’ll be familiar with 10 squared or 10 to the power of 3 times power 4 and those type of things that’s what this function does it takes this person over in this case 10 and puts it to the power of this number and this kid 13 so this number is equal to 10 or actually it’s legal to 1 and 13 years buying it so it’s a very very big number that’s some that’s important for gravity to work because gravity’s very weak force and therefore we need to make the math extremely high in order for gravity haven’t effect at all and next variable is gonna be we’re gonna call it gravity range and this can be the range of grip of the gravity now in real life regarded to infinite range just becomes so small it’s in significant at one point but you know Angry Birds aim to have a little circle around the planets to show that’s the range so that’s why we’re created as gravity range this will be the radius around the planet to where our birds can be affected by its gravity so we’ll set this one to go 200 so it’ll be raised to 200 around the planet and then we’ll go ahead and draw that circle I guess it really regatta it go ahead and draw the sprite because we blend job in it overrides everything that’s right index major index you do this often you’ll have a complete memorize no time don’t don’t worry next we’re gonna draw a circle a circle first argument is X next argument is why because we want to be senator XY and cuz it’s centered in our planet it’ll be right in center next is radius and we’re gonna sit equals like art gravity range

but you know I said in the creation event I can make a bigger small depending on how far we want to be able to affect the bird and the outline is the width of the why not just make that five doesn’t really matter all right I will duplicate this and oh would you plant to skill the cone was exactly the same difference one be change sprite the difference to we make the mass a little bit bigger so he’s instead three of identified and also as a side now um these values was a little hard hard to figure out um you have to pinpoint it because if you do too low it won’t affect the bird at all do you – hi it’ll be have such a high effect on the growth of the bird just directly crashed land into the plant so you’ve got to keep that in mind when you’re doing it and if you’re making a game you want to have it act in a certain way be prepared to do lot of tweaking and changing numbers around it okay so now we’re gonna make a another object called obj planet this Kamino code in this one but it’s gonna serve as the parent to book these planets so we’re running through the code later that makes things a lot easier for us so as parents said what would you plan it for both the planets okay and they are going to go through all that physics stuff any Christian person who’s creating right I have an array this tutorial on YouTube that I’m quite proud of that you can check out if you don’t understand arrays I believe last time I checked if you typed on game maker arrays tutorial it’s one of the first results on them youtube search click clip and on yes you can go ahead and watch that few confused about arrays but for now I’m gonna type 2-0 I said equal to the first planet so this will be the first index in our array and then I make it an X index of our array it’s a planets 1 is equal to obj find it – so the reason why I do this is because later on the code we’re gonna need to calculate gravity for all the planets and I just want to create a list of planets so that we know what we need to go through to check for it because yeah sure if you um if you have like two plans you can I just go through the code twice once for both the planets but if you have more planets or different types of plants you want the regular track – it’s far more efficient just to do it like this and then we’re gonna create another variable call it a number of planets I’m gonna set equal to two because there’s two planets in this list this is necessary for the code later so now we’re gonna go through the big long code that’s probably the most confusing and it’s also than it was funny okay so I can create two variables you said GF 0 0 and Q y equal to 0 no this is Devon so every time goes to the stub event which is like about the rate times per second it’ll set these variables equal to 0 so we have a fresh light to work with every time I go through this code and this is the acceleration so we’re gonna moon it so it’s gonna change every second so so yeah what’s go through could I create a for loop so I’m gonna go ahead and type it out and you don’t have to understand it yet but I’ll explain second no worries all right so we’re gonna have our code here to Calcutta copy so what this does it’s crazy variable is equals zero and then there’s another section here this is the condition so keep with this loop as long as I could in this minute and then that’s called a increment decrement or the change wouldn’t this is what will happen to I every time goes to this loop so in this case I is equal to zero so this condition is still met I is still less than number of plants and never plants is equal to two so to go through this code then then it would go through this step and add one dies now I is one it still meets this condition so it goes to the code again and now I add another one I and now I is it go to so now it no longer means this condition so stop going through it so it’ll go through this loop once for every planet in this case twice first thing we check whether we’re within the range of the planet so arm inside not if point distance which is distance between two points and the first moment we’re gonna check is XY and the other point is planets I dot X now this is confusing lots of to a lot of people this will call the planet we’re working with because my recording array and planets planets with the zero here is planet one and a plant with the one there is planet too okay so since I is equal to zero the first time through this vehicle zero so I’ll call up planets zero which will

give us obj planet one and we’ll find the x value of that object and then that’s all we needed and we’ll go through the same logic here and we’ll get the Y value and we’re gonna make sure that that’s what less than the gravity range of that ticket planet so call that to go planet so planets I and we’ll ask for the gravity range of that planet so this codon here will ensure that our bird is within the range of our planet and therefore you want to be affected by the gravity so now if you remember um in the physics 12 week we talked about axial Ursa polar coordinates so we’re gonna first use axial coordinates attack that the force and then we’re going to convert over to UM I’m sorry we’re gonna first use polar coordinates check with force then we’re gonna career it over to axial coordinate so that we can add on to our initial acceleration pretty easily so we’re gonna have a create available for us which is magnitude of the the polar coordinate thing and and this is gonna be equal to the big equation that we saw in the trailer and I also explained it in the previous tutorial so first thing is the gravitational constant so Oh gravity shear force constant that’s equals six point six seven four times power and then parentheses when we tie down ten comma negative at 11:00 all right so this is a very small number we can use this power function to create big numbers and small numbers so since this is negative 11 that means that it’ll be a zero point zero zero zero zero and so V zero point ten zeros and then you’ll get started with this number so it’s a very very small number at which and has to be very small because that’s that’s the way it creates an accurate representation of the force of gravity it’s a multiplied by the mass of the object we’re dealing with or mass of the first object which is the bird and time is mass the planet so we call the planet its I dodge mass that’s everything we have an enumerator up for the parenthesis and then we’ll divide that by the distance between two squared so the distance is equal to this thing right here and that we just used that’s equal distance and then I’ll put that in a power function of square root so power that distance comma 2 all right now so this big long thing is equal to the force and if you understand this in your then you’re pretty well off you probably get this trophy pretty well and if you don’t understand it go back to my physics tutorial look through the equation and and put all pieces together ask yourself what you two set means make sure you understand each that means because I’m here to make sure you understand it and I want you to understand I don’t want yours copied in code next thing it’s theta the angle of which this force is pulling us because you know if it’s pulling us to the right that’s completed from scenario where that’s pointing us to the left and in this case doing in terms of 300 degrees and it’s a little bit different than that okay so theta so I’ll be fine so there’s a handy function in game maker that will on find the direction that that is um pointing from the birds to the planet pretty easily so that motion is point direction and the first two arguments are the coordinates of our R versus X Y and then the next two arguments are the coordinates of the planets planets IX and applying it it’s I don’t why these are the exact same inputs as our weight distance function but it does different stuff with it and they multiply that by PI divided by 180 this is important because we’re going to be plugging this into a trigonometric function in a second and the trigonometric function will only accept radians radians basically a new unit that bunch of mathematicians made up to make them feel smarter but it’s not too hard converted so you can multiply it by PI divided by 180 if you want to Kurt from their action degrees or sorry degrees to radians and you can you can multiply it by 180 over PI it’s a greater from radians back to degrees so that’s all I really need to know there’s more significance to it but I don’t feel like explaining how to employ I understand it myself so I wouldn’t be qualified to explain so now we have GX what’s gonna be equal to our overall

gravitational force so we’re gonna add to it so every time it goes through this loop it’ll add add to it the force we got from the individual planet so GX and this is the X direction so I’m going to do force multiplied by cosine theta I went over this equation um in the physics tutorial so it’s you basically think of as a triangle and you take the X part of that triangle and the way you get the X part is that by taking the cosine of the angle and then there’s similar logic we can do Y minus equals Force Times sine data um I assign there is important because the ax is flipped in game maker and in math in math class um the positive y-direction is up but in game maker in all programming programming basically the positive y-direction is down so that that’s why I need to flip it flip it and using that all right and that is all for for loop so now we’ll we’ll add this GX and Gy to our H beaten to make it change so HB plus 2 equals G X divided by mass GX is a force so don’t get the acceleration wait / – capiche so these speed and we’re gonna add G Y divided by mass same thing so this is the big important code if you understand this to you that aren’t happy this is the point of this tutorial all right into into our room again I’m gonna make the background black because you know after office space game you make it black and well it was go ahead and I had our two planets so I’ll make this one here and this one here are you going hoping that their range intersect cuz that that’s a that was the that made a lot whole lot more complicated went through a lot effort to make it work that way so I’m hoping the ranges in your sex I don’t test it out it’s like there’s a first planet and there’s our other client alright oh what a problem I know this I drew line I drew circles on the planet but the default color of the circle is black so that’s silly of me to make the background black let’s see it I think I remember off top of my head how to change a colored I don’t know this for certain but we’ll just try experiment a little here so I think it’s draw set color please turn red be the result turns red and the color will make it seem we think should make it let’s make it orange cuz my favorite color and then we’re gonna set the color for our other planet as well and this will make government whenever they’re drawing stuff they’ll use this color oh my gosh my voice is going anyway okay test it lovely see these orange circles now we know exactly when the our Birds within the range of their our planets see this is also orange that’s unexpected okay so we’ll shoot a shoot like that it doesn’t even come within the range of the planets nothing happens if I shoot it like that it just goes straight towards the planet and that’s all if I shoot it like that you can see gets well I make countless see I gets pulled oh it’s fine we really shot too fast for it to be fed by planet but this should shoot a slower you can see it’s pulled in by the planet but not quite enough so get got through and then it got killed by that before you plant I had meant to code a collision with the bird and the planet and make the Rimmer start every time it collide but I think you see the point still after this okay so and and well I had nothing where to say this is the end of the tutorial so this is how you how the physics works and it succeeds being pulled in and if we make it really slow acceleration we pulled in more and and all that yeah my voice is completely dead anyway I hope you guys enjoyed this tutorial um here’s the outro you just wanted to unfortunate Oriole if you found it helpful please like the video and leave a comment this helps out my channel if you found the challenge helpful you can find more of them at my website www.themanufacturingmentor.com