Hey everyone welcome to this video.
So in the last audio we have done finding some turtles and in this video we will move a little further.
But one more thing I need to tell you that when you do not have any idea that what you are going to
need and your program while defining a main logic then go for the main logic first.
What I mean here is like if you can creating a calculator unit you are going to require some mathematical
operations like addition subtraction and all this.
Then you will define functions first and then go to mean logic and just call the function that you require.
So same in this program we know that would really put something that will make sure that the caterpillar
will not go out of the window when it go down something that will define give more and then something
that will show.
Final score and this score that we have at that particular point and something that will place the leaves
and a number of more so few function that we are sure about will define him then we will define a main
logic and the additional functions we require will define after the so for functions that you are angry
that we are going to need in this program is first one is we will define something that will make sure
that is a caterpillar inside or outside of the window second function that we do something.
Place the Leafs as they list are not get edited by this will require something that will place the leaves.
After that when we require something that will make sure that the game is over or the game is still
going on.
And after that when we require something that will display our score.
So these are full functions.
I believe every one of you are angry that we are going to require.
So let me define or try to define these functions and whether we are capable of defining these without
the main logic or not so we will go for the similar kind of fun like the outside window and place live
this time and in the next video game over and displaying the score so for the outside window what I
will do I will define these four walls just like the one that we have defined in the video and we have
created a moving total.
If you remember in the total module so we'll just like that one we have left one then we have right
well then they don't fun and in the last we had the bottom one and how we will define them just by simply
calculating the complete land dividing by two or adding or subtracting some factor.
So the left wall will be equal to just simple like that one the DOT window underscored with it because
the sun is actually good and this is the left one.
So minus and only the left part so divided by two because we are first calculating the complete one
and for the right will we had this one in positive and we are not adding some factor this time because
we require of a caterpillar to pets defaults and then we have to spend more tumbles no one is just the
window underscored height parentheses and then divided by two and bottom will be same of the top just
the negative.
So here we have defined all defaults and now I have named the function outside window so actually what
I'm going to do in this function is having not defined that whether my caterpillar is inside of the
window.
I will define the whether it is outside or not.
So whenever it crosses any of these walls it will provide me an alert by providing a Boolean true and
then I will work on that one that my game is over.
So I will take a variable here that is outside and that will check the portion of Caterpillar and the
caterpillar positions will be again like the total positions just X invite and we can clear them simply
just the name not position Neil now we have the x coordinate y coordinate it would all go to the left
and right.
Then if my X is less than the left window or begins a left ball then it means that it is actually out
of this one and if it is greater than right then it means that it is out in right direction.
So we can just add here or X greater than rightful.
So I'm not taking hit inside like greater the next six is.
And so adding left 1 and less than the right one I'm actually taking.
When you get out of D so not the end here or end these things.
And the other two conditions are also added with or because if the caterpillars get out of any of decide
one game will be over.
So y greater than the doleful or i vi less than the note.
So a modern one.
So in that case I will get this one so well this one that might get abilities out now and in that case
I was just redone this outside which is going to be true if any of these conditions satisfy.
Now we have this one so we are done with defining outside window and now we will define placing a leaf.
So that is something very easy because we have no leaf.
We have created a figure so positioning is it's very simple.
Just first of all we will hide the title.
So leave don't hide title.
And that is actually already hidden.
What I mean here is this will first hide the actual leaf that is eaten by the caterpillar right now
so that it will it can place a new one.
So first this one required to hide that one then a new one.
And how do we find new one.
So new leaf can be defined anywhere on this window.
So that is a random one.
That's why I included here random here so we will define it's coded x and y coordinates both randomly
and then whatever we get there will please deliver that particular position.
So we will use set X and set Vikram on.
So leave those set X and leave not set y that will threaten nameless said the coordinates x and y and
to generate a random number just random already because we haven't boarded this on his army note ran
into and provide the limit say minus two hundred to two hundred and same for the VI axis they had this
one and whenever I get any of this position we got the live coordinate x and y and at that point I just
showed the total that we had this.
So it will just find decoding it and showed it total by first hiding the original one.
So that's about these two functions outside window in place.
I hope you get all both of these and they're very easy to understand and create.
Now we will move to these two in the next video.
So thanks for watching.
See you in the next video.