Know it's actually have the means to shoot.
So the first thing we're going to do is get this little bit more.
The first thing we're going to do is a function called should should shoot.
So this will actually make the decision about when we should shoot an inds this and since we're going
to be since essentially it's going to be needing some
random numbers going to clewed.
So it's kind of we're going to sort of base should shoot bomb on
kind of random random numbers here.
So we should initialize here or appear as Rand
time
no
K and or should shoot bomb
copy
here.
We're going to say turn
in each Rand 10 percent again.
Just like before with the reset movement time.
Still it's just something I came up with.
It has no real
basis.
It's just kind of thing I thought worked fairly well.
COLMES
explain it in a second.
So we just take a random number and use the modulus of some amount.
So essentially all the saying is the more aliens you have destroyed the more you're going to shoot essentially.
And again you can come up with your own formula if you want or just copy or just copy this one.
So in our update date aliance K is pure
are going to say If so we're only going to shoot if we are not moving.
If not move horizontal.
We will say
we want to basically have the shot come out of the very bottom of the column
that we're shooting.
So I would say that the active columns
active meaning columns that are gone right.
So columns that are still exist
meaning some aliance still alive in that column.
So it's a no
columns.
And then we get checked to see which columns still have
which columns still have aliens in them.
It's use what we have for
and to do it for double for loop.
So arranged in say if the aliens alien and the ends of the row and column if there is still one alive
then this is an active call.
So
I want to add it to our array
increased amounts and then break out of this inner here.
Complaining about ch
that.
Plus all we can do plus plus our
do that
do like this.
OK so we're going to get the amount of active columns in which columns are active.
OK and here we're going to say if we should shoot
that
then check.
See we have active columns laughs
and we kind of choose which.
Well first of all choose the number of shots we're going to take.
And this will be a random number from
1 to 3 right.
Because you can only have three shots on screen at a time plus one minus and no
ch rebounds play so this essentially makes sure that there are only three bombs and
so we pick a number between zero and zero and two here and use at ones it's one in three.
And then remind us how many bombs are still in play.
And then for I think Zero is less than the number of shots.
Plus plus and like a new function.
And most of the pickup pick call as well.
So which column is going to shoot.
And shoot each
choose between zero and the number of active columns that and we'll make a new function called Shoe
bomb take the aliens in the common
that we shoot for
it we don't have this function yet.
And the second thing we need to do is in initialize Elian initialize aliens we need to settle our bombs
and stuff.
So say four inch equals zero.
This then the max number bombs.
Plus
is this
an alien.
Is
and we're going to make them all be out of place.
Currently it's aliens dot bombs.
In their estimation is zero.
Start.
CH way.
So this is just saying there's no bombs yet.
OK so we don't see bombs yet.
So now we need to implement each and Claire bomb
OK.
So you down here
and
seriously we're going to find a slot in our bombs.
OK.
Look here and find a slot in here in the bombs that doesn't exist.
OK.
Or is not in play.
So that's the first thing we're going to do is we're going to find a bomb ready or discussing notch
we currently Andrusco looked through them all
in each.
If the Iranians dumb bombs I
this doesn't matter that much when I use
say or
so we.
So if
if this bomb isn't actually in play at all then we can use it.
OK.
So we found a bomb that
found a bomb slot that is not being used so now we're going to use it.
So for
CH are you know in Rosemont this one is ero.
So now we're going to find the lowest alien in this column.
OK.
And he's the one that's going to shoot.
So we're going to shoot by saying pick we will get the position of this alien
in since it's
Since this is the leftmost part of the alien it's going to add one to it's sort of in the middle.
OK.
Because aliens are four wides so there's no good middle that we can use which can be one to the right
of the leftmost part.
OK.
That's what this is saying.
And then the aliens mission y plus our times you means to us sprits It's
hide.
The.
Adding
aliens sprites is hype.
So bottom you know
quote quote middle middle saying that these are the two positions I'm getting here.
And then all we'll do is just say aliens dot bombs of the bomb that we launch
in the animation to be zero and we don't have the animation yet but make it seem endz drop bombs.
The
Zeeshan X exposition in
the opposition
and now we have one more bomb.
You know of all this
breakout loop here is we're done
number number bombs in play is one more bomb in play.
OK so now that we have this we need to actually update the bomb so it actually would drop on her go
down in the street.
And so we back here and save all actually arrest a bool.
It's cool because what you return to us true if it hit the player.
Aliens game where the shields because it could intersect the shield.
It could hit a player.
She's happy.
Ms.
This
so
we need to make a separate for the
so let's do that first.
Conc char star Yulian bomb Spryte is this.
So it's going to be backslash.
The vertical bar for slash in the dash just had Pierre
sprite for the bomb and it will just cycle through them.
Right.
So now we have that need to know how many
how big it is or how big the animation is.
So say it's no
Straight's it's just this string length that bomb sprite ch.
So be like for this case
and go through
all the
x number of alien bombs
animals.
See if this bomb is in play or
just for good measure.
That's a make sure that the bomb is in play and if it is we will say aliens dot coms I session.
Why.
Well sequels one could have the.
I could make another constant here.
You mean bomb.
So go down one right and then set the animation of the bomb.
So
as
in plus one sent no bomb sprites
but.
And now we should essentially go through each kind of case so grant essentially collide with the player
of the shield and the end of the screen right.
Or the bottom screen.
So for one we already kind of have this position and say Legion point in the shield.
EX So we've done this before with the player or induce again the
the alien bomb is collision things drop bombs tops shin shields.
Number Shield's
in each show you say and the collision point
if shield index do not play.
So if it hit essentially what that is saying then we will take the bomb out of the
in or resolve the shield Glisson.
So can we ever written these functions again otherwise.
Also if the aliens bombs
position why is greater than or equal to games when decides dot height.
An it should also go out of play like mist.
Actually saying
this stuff is
an issue in this should be much less
shouldn't be aliens animations with bombs.
Of course
that OK.
And then
number one is
actually for this case I actually want to check the player as well.
So if we don't have something to check later collision so let's write another function and call it.
I was going to use it here but I'm going to make it right after we call it again.
And it's going to take the position of a projectile essentially in the position of a something like
this this can position of essentially a sprite
and the size of the sprite.
And it'll check to see if we hit something.
Copy this.
So in this case if it did hit something and we just do all this and then turn true that we hit the player
OK.
So otherwise in
we didn't hit the player.
So the game can continue as it were.
KING So it's copy is
and are going to clear it up here.
Will
and this will just be a position
in.
This will also be an
Spryte
in this or just.
It's
this.
And there you and I were kind of doing it this way is cuz then we could use this for other things as
well.
So it's down here.
An essentially it's going to be the same
check and doing so is a projectile you know within the Spryte sizes actually.
So is it within the kind of horizontal of the sprites.
And the within the
vertical is right it is then we know that each
it so hurts colliding
So there's that.
Now we need to actually call this up.
So in our
update function for aliens appear we're going to actually check see Treacher going to call up the bombs
game.
It means player shields
number of shields.
And if this happens
then I'm actually going to make this function update aliance a boolean now.
OK.
And I'm going to return true that the player was hit and here I'm going to just return false.
He's fine.
Julie and I need to change it.
CH here is while you alians trains bhool now.
So now that we have that we're going to have to use the.
So if the player gets hit I want him to essentially explode.
Right.
So in our raw
game
here it is we're going to have to start using the status of the game.
So going to say if the game state
is play or game state is explode
we sure have.
That's the.
I don't.
So and actually it's called player
so if he's dead or playing or waiting so the wait will be like
the
class.
So if the player gets hit in all this Ernst.
So basically if the player hits and he's exploding I want to be able to press like the spacebar or something
and then it'll wait a second until.
Or wait a few seconds until it actually restarts the games.
The player has time to recover.
So I'm actually going to put all this stuff here in here.
And for the player
I'm going to check if the game's current state is G-S play or if it's game states
G-S wait
then I'll draw the regular player sprite SG.
Otherwise I'm going to show the exploding sprite.
I don't think we've put that in here yet.
It's that
so it's char.
It's our air.
Right.
This
is kind of a strange one so you can use whatever you want here.
This.
Came up with
the first part of that
first right in this second straight.
That
so
we're going to draw
layer in that spread.
OK.
Now that I'm drawing that in the game can do some things more in and say if the game duck current state
which is in place state.
You all of this stuff done
that K
otherwise
if the state is yes you're dead.
As if it's her state.
They don't want changes animation.
Here
and
else if we're waiting
we all actually have a timer
so
we're going to set the timer.
We're going to set the game timer above
go with me on this.
Amed Rhymer 0
and we don't have a great time yet.
I think we'll need one so gained state current state
is play so we need to add a timer and game
timer.
This is put in the game struct that says just an int.
So this is working now.
And in our handle input such.
So here this is going to get quite a bit more tricky.
Say if game current stays just play then we could do this stuff
only if we're in this game state.
We haven't been using the States yet.
We're going to need to kind of see why.
So for a player shoot if the game is in the current state of the current state that the game is play
then you can.
It's fine.
Else if
game
is
else if the game's state is players dead say flared lives minus minus and the player animation set to
be zero.
And if the player dot was equal to zero then the game state will be over
it and otherwise
we'll set the stage to be.
Just wait.
And we'll wait.
Taimur to be some
and the last thing we need to do is actually draw the bomb.
It's OK.
So
our Tirah aliens down here you have to draw the BOP's number is zero.
So for all the bombs that we have
Dutch bombs way
that
say if if the bombs in play we should dropped
so set or draw character
and get structure for x x y
character so we can stop bombs
by in the position
and you can bomb right of
unions dot bombs.
I doubt anybody use wherever current animation is.
Or the current Spryte.
So we
think that's it.
CH It's all we need.
Quite a bit.
Of course.
But let's kind of run this and see how close air
in handle input we actually need to make the game not pass by constant reference because we're changing
it now.
When we also
to air this was
2:16
also an update in
move that
so you see that the aliens shot the bombs and they even hit shields.
See if I can try to get hit by one of these guys.
Shoot me up.
I didn't get hit so it's still a problem.
So I'm still not getting hit properly.
Let's take a look at the bombs.
Fine.
You see it.
And I think it's because
where I'm using update aliens I'm not actually
I'm not
setting the the player to me or the game in fact to be in play or dead.
The ch
that so and so we're checking to see if we hit the player and if we did then the player should be dead
for now.
OK.
So it's run this more time and see hopefully it can get hits.
But it's tricky.
Aereo but I'm not animating either although if I do press space it does resume.
It's got nice.
So I'm not animating yet.
But we pray we can fix that.
Too much problem.
And in fact in the draw
drug game.
Her shop where I actually
in the draw player we're not passing the offset
here Ross should be saying layered animation times the player sprites.
Right.
Need that one more time.
Yeah yeah.
So I get it.
Now I'm kind of animating back and forth and I'm dead.
OK.
If you press space it goes back and it continues on.
So this is a bit of a longer one.
But this was very important lecture because now we have essentially most of the game working.
There's a few other things that you still need to make work.
For example more of the states the intro screen over screen squirty and all that stuff but we will tackle
the kind of more of the game states and maybe I'll go over it a little bit more thoroughly than I did
in this lecture series.
There's so much to do in this lecture so I'll see you in the next lecture.