Yeah.
So in this video with the a main logical flip program that will make the program track.
So say this one stock gain
maybe go.
Now one thing most of you are already thinking about that how our keys would make the program work how
we will intractable keyboard the this program.
So for that fund we have a very simple matter.
We use to denoting total load own key metal that is own pressing that particular key.
What will happen and pass panties in these you required to pass two parameters.
First one is the main function and if we do generally then first is the key that you are pressing like
I'm going to press space.
When my game begins I go in pressing this space you'll start the game so space
and then what will happen on pressing Dedmon.
So that will be going to be any commander any C function.
So I'm going to call the function start game.
So on pressing the space game we'll start.
So this is how you can make your keyboard and your program to combine with each of them.
And then just add data or policeman so that keyboard commands can be routed and in the last main loop.
That is what we need to add part of a program.
Now this is about space only rest commands.
We will learn in the next video.
Now let me move towards docking.
So first of all in this tight game I'm taking a global variable that is say game started and the game
is starting to space based few things happen.
The first thing.
If the game is already started and I'm pressing space right now.
So that is something can also happen.
So when the game is already started never done nothing.
And after that one game started equal to draw.
What's actually happening here is like when I just pressed this space first then I came to this when
I have a variable game started and if it doesn't have anything then it will not go inside of this function.
And if there is anything in that when like when it is already started and then it will return nothing
it means that whenever I press space even after my program is running then there will be nothing happen
with that space.
Otherwise game will start again.
And how game already started means is like if my game started is already drew then it will go inside
that well then it may provide some adversarial programs to work in restarts.
So this is a little come on that will only happen when the game is stagnant.
In that case also it will return nothing.
And after that this thing happen.
Then game started equal to Drew.
So from here of a game will start to work.
This is for just checking that one.
Now first of all when the game started begin Drew we will begin with this goal that is going to be 0
initially so scored is initially zero and extra in the score.
Total player.
So what test on the desktop that is press space to start will begin.
Zero and after that one we will work with the Caterpillar.
So as soon as the program starts we a caterpillar.
So Caterpillar underscores speed will do too.
And Caterpillar land equal to say 3.
We are digging if only three men here we will define Caterpillar not shape size.
That is something that will make a look at the below a rectangle.
And what we will do here.
1 and then the caterpillar equation will enter that point and 1 in the end maybe love a deadline so
we'll get to the mainland and one before and after.
So although Caterpillar have three squares at that point after that one we need to show a caterpillar
because it is hidden at this point.
So short total if you remember we have hidden these turtles initially so we will show a turtle and then
display scored with the current score which is actually zero right now.
So this one will display zero.
So here.
Also past the current score.
The barometer we are using here because now we have declared that none displayed this called Zero.
And last thing placed the leaf.
So this is the initial condition when you're trying to run this one we are getting an arrow a line equal
to send 50 to line that we check that what that is so here we are missing a comma so save that one and
run it again.
There you go.
We are getting this one press phase to start when I started this one I had my initial score to zero.
The Caterpillar the this length the main landing beginning and then we have one end up and the Leaf
randomly here.
And when you start this one again then you have a leaf a different position that we have.
But this thing but it will be a different collision.
Now after that one.
This is about the initial conditions that will begin with that one.
Now while Drew while our game is started so until it remains draw my below will moving forward not action
with its Caterpillar spin.
So whatever this period has it will moving forward direction.
And after that one we have two conditions.
If this is hitting the leaf or not hitting the leaf then moving.
And third one also manage to get hit in by vole.
So first when the caterpillar say we are taking distance of the collision of these two.
So distance with the leaf.
So this is how you can compare the distance of two turtles.
Main turtle it is the distance with the another one and then when this one is less than say 20 so 20
is very small gap.
What will happen in that case will first place live because as soon as they touch each other we must
make sure that the original is disappear and a new one place at a different location.
And after that one many in the Caterpillar eat that one Caterpillar land will increase by 1.
So Caterpillar underscored land and that will be equal to Caterpillar land plus one and also the caterpillar
speed.
This one also increased by 1
plus 1.
And also when they land is increased now you again need to define the shape size of the caterpillar
so that it will get updated with that one.
They will have the same line here.
After that one few more things you need to operate school maintain.
So school will be school plus and and then this quality function display school with this new school
that is going to be our current school and day we had this one.
Now we do not require to operate anything else.
And if
outside the window.
So if it this one hits the outside window or when this thing provides Drew.
So what will happen in that case.
Just call game over and provide a break clavicle.
So this is very easy.
If you focus a little on this one we have just checked first with a global variable like if the goal
or this one is already started to do nothing then provide this one a you grew then we have initial conditions
like school zero.
We have cleared everything this text there like best best.
Then we have the initial values speed and land of the caterpillar and the initial score and the leave
after that one until this one remains true.
Our Caterpillar remain moving oh keep moving.
Then if their distance with the leaf is less than quality it means it has soil in the leaf then place
Senator live and increase its length and speed.
Also update this code and if it hits DiVall then the game is over.
So this is about all the functions and main objects but there's one thing left here.
Now if you run your code you will get your game there hit return.
So this space you will get this one moving but you cannot control Dettmer and your score it is essentially
here.
So how to do that one.
So that's something we are going to learn in the next video.
So thanks for watching.
Soon the next video.