WEBVTT

00:00.600 --> 00:09.830
This lecture I want to go over making a little library to kind of encapsulate curses.

00:10.150 --> 00:20.520
So in here I'm going to make a new header file in what I call it.

00:20.950 --> 00:24.500
Curses utilities dot h

00:26.890 --> 00:37.210
in that must have going to make a new source file in and call it curses.

00:37.360 --> 00:38.960
It's C.P

00:42.210 --> 00:51.430
in in the H mode to define some functions so first function is going to define it just to initialize

00:51.460 --> 00:52.330
cursors

00:55.420 --> 00:57.850
and going to say

01:00.520 --> 01:11.420
whether or not in this the parameters whether or not I want to delay our input.

01:12.720 --> 01:13.730
Nodaway

01:17.480 --> 01:22.460
that it's in here.

01:23.870 --> 01:31.990
Copy this in mind it's the file.

01:32.520 --> 01:45.220
And you put this in the dot file and then ended up CBP file going to include curses you tildes done

01:45.300 --> 01:48.850
each and I'm going to implement it.

01:49.940 --> 02:00.240
So for the initialization really all it's going to be is to look second

02:02.960 --> 02:06.090
actually up here in P.

02:06.090 --> 02:13.060
I'm also going to include curses says this.

02:13.360 --> 02:23.680
So again this is for Mac here on Windows you should be doing include curses.

02:23.880 --> 02:24.960
It's a

02:29.890 --> 02:30.830
sue.

02:30.850 --> 02:36.170
Now we should write the function to initialize curses.

02:36.180 --> 02:48.460
So don't say it it's in that I don't ever want Echo because he's this for games I don't ever want the

02:49.540 --> 02:50.200
cursor

02:56.100 --> 02:59.590
and I'm going to set the no delay

03:03.170 --> 03:14.370
no this no delay capital-T are naming convention and I'm going to say no delay here because maybe I

03:14.370 --> 03:17.370
want turn based games later.

03:18.410 --> 03:21.950
And I'm always going to keep that

03:26.190 --> 03:30.790
screen any more.

03:32.540 --> 03:42.860
The first function we're going to have for our little utility library next function is going to be shut

03:43.010 --> 03:46.670
down curses.

03:46.800 --> 03:48.600
It's going to take no crammer's

03:51.840 --> 04:00.880
or copy that or put this here and we're in when that.

04:00.900 --> 04:07.610
So that's like that's already two functions to use.

04:07.680 --> 04:10.470
And let's actually start testing this.

04:10.470 --> 04:15.300
So instead of using it including this here

04:17.880 --> 04:29.180
to include our own curses you do this to each answer in that say

04:32.430 --> 04:33.980
initialize

04:36.240 --> 04:40.050
curses in case get false.

04:40.050 --> 04:40.560
For now

04:43.220 --> 04:58.620
and when you say sure or well I guess since I don't wait till later for that we're going to say Shut

04:58.620 --> 05:01.440
down here.

05:01.550 --> 05:05.130
It's that way.

05:05.290 --> 05:09.260
So I come back to this periodically and keep adding things.

05:09.310 --> 05:19.940
And so the next thing I need is the let's do clear screen we're screen

05:24.160 --> 05:25.120
copy this

05:28.130 --> 05:31.130
in here is going to say clear

05:33.930 --> 05:41.980
Dovid or clear screen function and also need our refresh the screen.

05:42.610 --> 05:43.030
Wow

05:48.980 --> 05:50.830
so copy that.

05:53.210 --> 05:57.280
Here is trash.

05:57.320 --> 06:05.170
So the point of doing all this is just going to be so we don't really have to keep every input reimplementing

06:05.270 --> 06:08.700
everything we initialize and shut down everything.

06:08.720 --> 06:18.660
Each time we'll just call functions and it also makes it for you know if you want to kind of portably

06:20.040 --> 06:23.700
use this or maybe that curses invalidation changes shape.

06:23.760 --> 06:25.420
Highly doubt at this point.

06:25.640 --> 06:29.240
But if it did we could just implement everything.

06:29.430 --> 06:37.450
Reimplement everything here instead of changing all of our programs directly.

06:37.620 --> 06:44.710
OK so we have that you only need a couple more things.

06:44.720 --> 06:46.970
Am I going to want

06:49.450 --> 06:57.700
the say the the screen with

07:01.650 --> 07:09.600
and shikse turn integer and are also going to need screen height

07:14.630 --> 07:20.850
copies.

07:20.980 --> 07:22.510
Put them here.

07:27.230 --> 07:29.080
And to get the whip.

07:29.100 --> 07:35.680
The screen is just columns to get height is the line.

07:35.980 --> 07:40.830
Right.

07:41.010 --> 07:44.470
And what else do we need.

07:45.540 --> 07:47.300
Well let's do

07:50.110 --> 08:05.020
character so we're going to see in each and then get Schar and remember it's into because we want so

08:07.320 --> 08:22.620
said here and all it's going to do is turn good character now in our app here say get rich character

08:22.650 --> 08:23.770
like that.

08:24.170 --> 08:24.730
OK.

08:27.870 --> 08:37.080
So the next thing is won't you be able to set a character.

08:37.330 --> 08:38.200
Boyd

08:41.970 --> 08:53.540
or maybe we should call it raw character and we'll give it the inte exposition and the y position and

08:53.540 --> 08:56.230
notice it's X before y now.

08:57.410 --> 09:05.410
And character itself character.

09:05.730 --> 09:09.120
Copy this.

09:09.500 --> 09:11.140
Here is

09:14.690 --> 09:15.200
here.

09:15.220 --> 09:18.500
You say return or not returns.

09:18.520 --> 09:30.040
And the add character and exposition or why position gets first and then exposition and then the character

09:35.210 --> 09:45.520
so this whole thing that we're doing is usually called the wrapper technical term and that's to to hide

09:45.520 --> 09:47.720
implementation details.

09:50.470 --> 09:52.770
What else are you going to need.

09:52.770 --> 09:56.940
We're going to need say

10:01.390 --> 10:11.610
maybe maybe once the move wrap Well we'd move cursor

10:14.230 --> 10:20.360
and say in x x rows.

10:20.580 --> 10:21.410
Why.

10:21.460 --> 10:33.520
Now we can do X X first and then Y.

10:33.820 --> 10:37.940
Move y pause x ball.

10:43.970 --> 10:47.390
There'll be another one that we need.

10:47.410 --> 10:53.590
But I don't want to really want to implement it right now.

10:53.720 --> 10:58.030
I'm going to save that for our game actually.

10:58.100 --> 11:06.640
So for now we're going to say we're still going to include curses up here.

11:06.740 --> 11:08.590
We need it.

11:10.920 --> 11:24.130
At but we're only really need it for this function in we'll say 10 10

11:26.810 --> 11:30.380
a string string.

11:36.630 --> 11:38.520
And run it.

11:42.360 --> 11:43.710
It's still working.

11:43.830 --> 11:47.750
It's good.

11:47.840 --> 11:50.540
And the last thing we're going to do

11:53.340 --> 12:00.500
you're is actually we're going to move this to each

12:03.300 --> 12:12.630
this and we're going to make an and he is going to be arrow keys.

12:14.720 --> 12:16.510
Or actually sorry arrow.

12:18.430 --> 12:19.880
He's this

12:22.460 --> 12:28.590
and I say up is he

12:31.600 --> 12:34.220
down is he down.

12:36.160 --> 12:44.670
In left he left in right.

12:44.720 --> 12:46.860
Is he right.

12:50.430 --> 12:57.630
So we're kind of making our own arrow keys and we're just setting it to be the

13:00.070 --> 13:02.110
curses version.

13:04.390 --> 13:14.140
So that's it for now we may add some things to curses you still a little bit later when we actually

13:14.140 --> 13:17.590
tackle the game itself.

13:18.100 --> 13:25.200
So in the next section we'll finally do our Space Invaders clone called TECS invaders.

13:25.240 --> 13:26.610
So I'll see you then.
