Know we've implemented most of the data we're going to need and kind of thought about it a little bit
at least we're going to start actually implementing the game.
So let's go to our main function right now a world here.
Move this
so.
And first we're going to need to include
text invader's.
Each
because we're going to need all this data.
All of these definitions.
And we're going to need our curses you tale's.
So that's good for now.
And now let's let's really just start with the main loop ok and or the main function in general.
So we know we're going to need our game object that we made in TX in meters.
H.
This.
And let's just start with the player as well and add extra extra variables of different types like the
yelling swarm in the phone and all that later.
OK.
So what would we need to do.
So we'll probably need some function to initialize the games.
And when I say it's called in game and I'm going to give it again.
And most are going to need something to get the player call it player and give it the player.
So this in that game will kind of set up like all the data so that the window size and the level and
the current state of that and and that player will you know set the initial position in missile and
the size and stuff.
OK.
So what's right those functions.
It's not her attorney thing.
So in a game first in a passing game by reference and intimately with the pair going to say layer by
reference
that's ancient you implement them.
Pretty simple for now.
That K..
So for game really you just need to say let's initialize the window size so you get is we actually use
cursus utils So we're actually going to get the screen.
And use the screen with the function and the screen height function screen
like that.
And I was going to set the height as well
and the level is put in one initially in the current state is going to be rocking to make it be the
intro yet we're actually going to make it be placed first.
OK.
And the reason why we're going to do that so you look into here.
I typically try to start with the most kind of common case that the player is going to be in.
Right.
So most of the time is going to be playing games.
Right.
So and really that's the most important part of the game is actually playing.
Right.
So I'm going to start the game currently in the police state.
But this will have to change.
So when you say to do
change shoe Yes intro
you
have to do that later.
But for now it's going to start in the play station kind of mess around.
So the player then should be fairly simple.
Where dots say his position
or actually right to say his lives and he lives from last time.
I didn't actually set them to zero but I said to him to be three but they should be.
Copy this and say x number of lies lies the are going to set the right size to be some size so we don't
have any constants for this.
Let's make it so the right size we said in here would be where is Chubais 5.
So set something here.
Where Spryte
with
is five in the player separate height is two k so it's two rows for the height Zaine five columns with
the width and scope and he's
height.
Is this
and size that.
Sorry that's OK.
And I'm also going to set the position of the where and I'm actually going to make a new function for
this stuff and I'm going to call it teach reset where it's where it's going to take the player in that.
And the reason why I am doing this and also do is do more initialising but every time we kind of change
I say to the next level we want to kind of recenter the player and put him in the initial spot and stuff
like that.
So we might need to call this a bunch of times unlike this nit player which we only will call once per
game.
Right.
So I mean we don't really have to set his width and height every time.
OK so we're going to say a reset player here.
So and reset player will actually set where the player should be initially.
So it's position X is going to be in actually going to.
I'm going to need the game with stuffs because I need to center him properly.
So in fact we have to do our first revision which is send in the games.
So the second change
animals to me to get here is wow I'm just putting the game first.
Just because no reason way.
Copy this
there.
Copy that and put it there.
And then that player.
I'm also going to pass in the game.
So again the reason I need that is because when you do this so with a size Dortch
the went over to minus the player dot the sprite size player that went over to Canute's this puts the
player in center screen.
Horizontal.
And we're also going to put the player position.
Why is what CH It will need to be at the bottom of the screen.
OK but I want him to be one kind of row up from the screen at the bottom.
So it's a game daunts window sized height.
And I remember that it goes from 0 0 at the top left of the screen down.
So you're going to have to take the height of the window minus the player sprite size
dot hige OK so the heights can be two and the window size.
Dr. Height is 30.
So he'll be eight down minus 1.
So that's kind of where he'll start.
And you'll see you'll see what this really do a bit as gain here.
So.
So the other thing you need to do is get the players and the nation states in or at zero initially set
and are also going to need to set the missile position as well.
And we need to somehow say whether or not the missile is currently in play.
So I'm actually going to make a couple of new constants or one new concept really.
And I'm going to name it's not in play in a safe.
Negative One copy this and I'm actually going to make a new function for this as well.
And I'm going to call it void resets missile
and give it player
so.
And what recent missile will do is actually take it out of play.
So we're going to need this for when you hit an alien or hit shield or something like that or goes off
screen.
It's going to need to go out of play.
So risk where Dot missile dot X is not les.
And similarly with the y it's not it's play right because he hasn't shot yet.
So this makes sense and in recent missile.
So we haven't even drawn anything or done anything yet.
We're just just initialize the player.
And again that's it.
OK so now let's actually do the main loop.
So we have we've initialized the player and the game so to say you'll quit and do the same kind of thing
that we did for a while not quit.
What we're going to do is get the in touch or handle the input of the player.
So we're going to need that function for this a handle input
and maybe it'll pass back the input that you gave it.
And I say we're a good game in order to get with the player.
And you'll see why it's an SOS.
Copy this
this second copy it is a little input and turn that character.
It's going to take a game.
It can change the game at all but we might change the player
so
in which copy this piece down here we're not even really going to implement that.
So I was going to do this now in declare clear input that we're going to implement yet.
All really we're going to do from now on is try to get the player to draw in maybe move later.
OK so we're going to have the player on the screen and maybe he'll move.
So that's it for that for now.
And we're going to do
I guess we'll go where we'll do.
Well one thing we haven't done is actually initially curse.
So we should actually do that.
Function is called Schley's versus So we could actually do this right away.
True because we want Nodaway in our gets shut down
curses here.
OK.
So go do that.
It's very import.
So now we will
I guess for now we'll say update game
and we'll pass the game and the player for now and we'll say clear the screen.
And this comes from is used Hill's.
And we'll say draw the game using the game and the player and say refresh the screen also from curses
he tells.
OK.
So let's start implementing these a little bit so update game we're not going to implement really yet
anyway.
So soccer or anything in this I don't think we're going to change it but maybe that's not the case.
We we might change the player and we're also going to need Drog game
and we're definitely not going to change the game again and are not going to change.
Damier
OK so you'd have a lot of functions none of which really have been all implemented yet except for maybe
the initialize ones
so start implementing a little bit of it.
So probably not going to implement a game yet.
Says something to update we just want the player to kind of be on screen.
So we don't have a sprite yet and this semicolon right there.
We don't have a straight for the player.
So let's actually go back and make him.
Let's actually make this right.
So let's call him that's going to accounts char star.
Right.
So Aski so I can call him player Spryte and he's going to be it's going to be an array and each element
will be
kind of see strings sort of and this will be his top it will be firsts.
The top part of him and this will be the bottom that day.
It's an array of character pointers.
So now we have the player Spryte.
So now we should ask into here and we're have to figure out how to draw the player.
So how are we going to
draw the player.
Well in general Burgess going to need some way of drying sprite k.
So I'm actually going to instead of drawing or having like draw sprite method in TX invader's actually
going to put it in curses.
This is kind of the missing function that I was kind of talking about before.
So we're actually going to say void draw Spryte
and redraw it at some positions exposition in y position and or indeed the Spryte self.
Or star Spryte and are going to need the height of this right.
Really this is kind of the length of the array.
And I'm also going to add we're going to add an offset.
Here and this is going to be for later.
And actually going to make it the default parameter.
So are you going there.
Yeah.
These kind of defaulted parameters and then defaulted to zero and you'll see why we need this function
probably
probably we're going to need this function later when we do this parameter later when we do aliens.
But for now I'm going to leave it there to the Dutch CVP file for curses.
Remerge the fault parameters we don't need to have the actual value here.
So that and really what we're going to do for the draw Spryte is pretty simple screens say for each
so inch each being the height height is less than
Spryte height.
Each plus plus.
So it's going to go through each step go back to here.
For each kind of row right height is in the rows we just kind of draw this string.
OK.
That's basically so act here.
Say
and just sit on.
Grass say envied in the branch you
say why position plus the height
and the exposition.
And we're going to say the Spryte of each
Well actually we're going to do S. S. that and this present s actually means a C string.
And this is actually what's called a format format string.
So we actually have to give it the format string in order to draw it properly.
OK.
So just follow follow this.
This just means string.
So put a string in here and this is the string that we're going to put.
OK that's it.
And we'll deal with the offsets later.
OK.
It's not going to bother with yet.
So now that we have something to draw the sprite Let's actually draw the player draw straight
so and take the exposition
in the y position.
And the actual Spryte itself is going to say play or straight.
And B and each so layered that Sprite sized right that
so you truly are in
was right.
Right.
Offset each.
Now where did you draw this.
I
may have put in actual curses you do for some reason.
OK.
So let's make sure make sure I always still kind of like do this and remove all all your your old files
sure that you're putting in the right one.
So I think that's ok now.
OK.
So rest is averted are good.
So now this work.
So let's actually run this and see what happens.
Exist
missing missing that.
So so there should be an array of const char stores.
OK.
So that's all that was.
So now this Yes and look we have our player right.
OK.
So now that we actually have something drawing on the screen which is nice.
Let's actually get to moving him.
Let's close this
and start implementing the handle inputs.
So here now we basically want to do kind of a switch over the input and see what's and see kind of what
was done by the player.
OK.
So I'm going to also say if you hit Q Then you want to quit.
So we will say switch
and we'll switch over the char.
And in fact we'll say actually say it or not we don't want this to be a charge of this to be in this
fact.
This is all.
And the reason again is for the Iraqis.
So we'll say input schools get our char and get charges from the details.
Curses.
So it's details.
But and we'll switch over it.
So if it's.
Q
Then we'll just return
the input like that.
If it's the arrow key so take a look at this.
And in fact I'm going to change this.
AK
for air.
You want to keep consistent naming here.
That flip in the right place.
So if it's the actual arrow key and for now we're going to do left
that will do something at.
Or if it's right is something.
So really it's going to be moved to the right to left.
And that's it.
So
let's actually run this one more time to make sure that cue works.
It doesn't because we haven't hooked up yet.
So yeah in the mainland.
So if
not ch or if input is equal or not equal to Q
and we'll do all this stuff
otherwise.
Quit schoolteacher k.
So let's run this
rescue and it it's good.
So that's good.
We can try the gaming time we want and keep.
And now let's actually be able to move our character or our little player straight.
So let's actually put a function here
or a function to move our player.
So let's actually down here.
Say a void move.
Player
and I'm actually going to pass it the game and you'll see why in a second.
In Pass player in I'm going to pass in some amount to move it by
Put it down here or draw a game
in and if they press left I want to move him in the negative direction and move where it passing the
game player and move him by some amount.
And again going to make a constant for this player Bentz MT CH and I'm going to make two for now.
So it's going to kind of move too over to either direction.
This is going to be negative for left
and it's going to be positive or right.
And so let's actually implement player
so we want to move the player left and right but we don't ever want to go off the screen.
So that's why I'm passing in the game.
This game has the actual screen boundaries.
So I say if player top position X because we can only move left or right really the player can't move
up or down position X plus the player dot size or the sprite size
dot width because how we're going to have our player.
So if you kind of think of the player terms of his Sprite really is he's going to be like kind of this.
This is going to be his top left.
OK.
So this is kind of is the left most part of this right.
So his position is really kind of right here.
Essentially it's position there so if his position plus the width of the Spryte plus the amount he's
moving is greater than the game's gained much window size dot.
Then he would be off the screen.
Right.
So instead we'll say layered position dot X is the game's state but the wind decides that it's with
minus the player's sprite size.
So this is essentially saying
make sure player doesn't go off the screen to the right.
And this is the rightmost position the player can be care.
And then we'll have to do the same for the other side of the player Deitsch position dot X plus X is
less than zero.
So this means
player is off screen to the left.
Then make sure he's not
set easier.
Otherwise we can just put his position plus equals that the actual x and so let's move.
And that.
So there you go.
So move left and right.
So if I go all the way to the left it's hitting it's hitting this case.
So if I keep I keep trying I'm holding the left arrow key right now and I can't move any more to the
left.
And if I do that for the right it's it's the top case here.
OK.
So his his position.
You can think of it is right here that's what the player's position really is and it's this kind of
top left position right here.
So if he sort of.
So if you take that position plus the width of this right which is five plus how much he would be moving
which is two.
In this case.
Ok if that's greater then the window size with the right the whole size of the window right then makes
sure that he's at the window size minus the sprite height.
So right here.
OK.
So that's kind of what it's saying.
So don't go off the right side and don't go off the left side in the next case.
Otherwise you would ever just just move right.
So there you go.
We have our player moving back and forth in our game.
So in the next lecture I want to make sure that he can shoot scores even.