Work on an example to tie everything we've learned so far.
Essentially what this program will do is we'll be able to control kind of a little ball or be a kid
or something and we'll be able to move it around with our arrow keys.
So first things first say it
screen we don't want any echo
in we don't want to see cursor
falls in it we don't want any delay in our input
and last thing is we want to keep it.
So these functions will probably be using a lot for all the programs right.
Well really just the Ngee that we're going to do in the next section.
I'm going to have a quick.
Just last time
it means say it in a.
Because otherwise it won't be able to understand or our arrow is in for it's yo Actually if you try
with a character in a little warning and it'll say you can't compare each key down and keep it in everything
like that with the input.
So use it here.
So say it while
nocked quit
and you will get the input.
And if the input is not q then we will synch lead jousts clear the screen
and then we'll just sort of check see what he were using and put each.
He down.
And then we'll move our ball down.
If in each is he
ball up it's input such.
Laughs as if it's
he right.
OK.
So what should we do in these cases.
Well we'll need some variables here and we need the inch current exposition and set to be zero.
You don't need current wives as well that G-0 and and in these since
y goes down we'll say current age
iPods plus plus.
Right.
And if it goes up we'll see current each minus minus.
So we're going to move the ball.
One one space every time we type the art is similarly
it's minus here left.
X is
ch it correctly.
Is pas plus.
And then we actually draw the all ch you or Y pause or it's always Y then X
in the ball will just draw.
It's
fresh.
Otherwise we press.
Q So which what caused this.
So take a look at how this worked out.
And it.
Here we see ball.
It's pretty good.
Move it up and down right.
Everything is looking pretty good.
Is that
and also at the end here.
Don't forget that as well.
Some could have some problems later.
There is one more thing that we can do to this.
It's kind of less obvious.
But right now it runs basically acts kind of full speed.
It's running as fast as you can possibly go which possibly could mess up our games in that our games
might run far too fast.
Maybe if the aliens are dropping bombs on us we won't be able to actually get out the way in time.
Right.
We're going to react so to fix this.
I'm going to include
mood seedtime and basically With time when I'm going to do is to limit how fast this loop will go as
initially.
So let's say I want to draw 60 times per second which is kind of the standard refresh rate of Monk.
OK.
And we say that it's 60 frames per second and you can think of one frame as being one time through the
loop for our probes.
So the question becomes how do we make sure that we're only doing 60 frames per second.
And essentially what we're going to do is appear we're going to get the current time and we're going
to use this type called clock clock and the squirty and it's going to give us the current time in clock
ticks and it's playing with a clock tick is it.
Second and to get the current time we need a function.
And it's called clock.
So this will give us
current time
in clock ticks
and now we're going to do is up here are going to get the time again so we're I clock the new time
equal to clock against the clock ticks again and we're going to say clock t delta time t is time between
the new time and the current time
so essentially DTC is how much time has passed from the last time we checked clock essentially.
So this DTC is measured in clock ticks which is an arbitrary unit for measuring internal system time
and it's dependent on your computer.
But clock ticks by themselves don't really help too much.
We need to somehow relate it to second since we want to only go 60 frames per second.
So to get how many ticks per second time actually has a constant called clock ticks per second clocks
per sec clocks her set like this.
And this tells us how many clock ticks happen in a second for your system.
OK so now we have to relate the EDT which is in Tick's two clocks per second.
So to do that we're going to say clocks per second divided by some amount and the amount we're going
to be or it's going to be is Konst in frames per second.
And Ron said it to be 60 in this case and we're going to divide the clocks per second by our frames
per second.
This and essentially is going to be ticks per second divided by frames per second.
And if you know your division you'll know that this kind of translates into ticks per frame.
OK.
So that's essentially what did he really is it's how many ticks per one frame.
And so now we can actually compare this to the delta time.
So we'll see if E.T. is greater than this.
So if.
How much time has passed is greater than our frame rate in ticks per frame.
Then will do all of this.
This is kind of format it's
like that.
They are into this whole thing in this kind of loop or in this case.
Yes.
So are going to check to see how much time is has
as occurred since the last time it's a clock.
And then if it's greater than our frame rate in ticks per frame rate this is what this basically amounts
to is expert frame then we'll do all this.
And the last thing we need to do is update current time to
to the last times and since new time.
OK so current time will be now what it was when we last checked which is equal to Newton.
And so now if we run this
you see that everything kind of looks exactly the same as what we did before.
But like I said now it's going only 60 frames per second.
And again that's going to help us with our game so that we can kind of limit how fast everything goes.
So we might not use 60 frames per second.
You might use it here.
We might use like 20 French second to make it a bit nicer.
OK.
So that's it for this example.
And in the next lecture I want to go over attributes.