Know that we have our aliens drawing and we can actually shoot them I want to of finish up the explosion
of it and to do that we'll need a new function and call it update.
Aliance
and take the game
and take alians
and take the player
in.
I'm also going to pass in the shields for him but not going to use this lecture but will need them for
later.
That so the aliens are going to do is it's going to come down the explosion every time it updates and
then any any aliens that are exploding
should then kind of be cleared.
OK so to say if it's aliens dot explosion Taimur is greater than zero.
Returned equals zero then or say aliens dot an explosion
Ramer minus minus k so even if even if it's 0 then it will get minus minus that will equal to not in
place.
So if explosion remember is zero then explosion
timer will be set to not in play effectively.
So then we're going to go through all the aliens
that and to check to see if they're exploding ants row column and if they're exploding
and the timer explosion timer
is equal to not in play.
Playing like this.
Then we're going to set the aliens to be dead.
OK.
So essentially we're just kind of clearing all the aliens that have been exploding up until this point
and we're just setting them to be gone now.
So if we actually call this in it's a game and say date aliens in repasts game player whether the player
or aliens
and the player the shields and the number of shields like so OK.
So if you run this
then you see how it explodes for a second and then it disappears.
They just kind of what you want.
So that looks pretty good so far.
Now we want to have our aliens kind of move.
OK.
And to do that we'll be still working in the aliens function and we're going to have
centrally we're going to count down the amount of time that the alien.
So essentially every few every amount of a certain amount of time we're going to move the alien to the
right or left.
So to do that we're going to we're going to make a new function first.
And we're going to call it a reset movement time and make a new function here.
BOYD It's called Reset movement time like this in we're going to pass it in the alien swarm
and this is really it's kind of up to you how you want to implement it.
Actually there's no right way.
I don't think to do it.
But here's kind of what I found to be kind of nice in a movement.
Time is the movie Time and we're going to set it to some amount and it's going to be based on the current
line that the aliens are on times two plus two times or five or five times
the amount of aliens that are left.
So it means that none of you are left over.
Of the number total aliens
OK.
So this is kind of just something I came up with.
So essentially though the lower the amount of aliens the lower this movement time will be essentially
trying.
So meaning that after we every time this in time hits zero will move the alien K and it it goes faster
depending on depending on how many aliens are left.
So this is just something I sort of came up with.
It doesn't really matter you can come up with your own kind of formula or use mine.
It doesn't matter that much.
OK so I'm actually going to call it in initialize aliens.
I'm going to say here.
So notice we never set movement time ever.
So we're going to reset time.
Really it's like so and now every so often when the movement time is zero we will essentially move the
aliens.
So aliens Dot meant time is minus and then we're going to need some which you need some
boolean values and stuff that's cool and I say move horizontal
and can move horizontal.
If it's if 0 is greater than or equal to the aliens movement time.
So basically if if the moving time is zero we're going.
OK.
And
going to also need so if I just kind of run this for now.
Not going to move yet but see how you say I kind of kill this row of aliance
if they should move to the right day initially and if these aliens hit the edge of the screen then it'll
move down and then go back.
OK.
So we need some way of getting
like all the empty columns and rows that exist to the left and right of the alien swarm.
And so if I kill that it's killed three columns of the alien swarm so now they would they would only
move down if these guys.
These aliens are here hit the right edge.
KAYE So we're going to kind of have to factor that in somehow.
And we're going to do that by having some say empty columns to the left in just how many empty columns
to the right
and also we don't have empty columns to the bottom.
Well are empty roads.
Yes.
OK.
And I'm going to.
Not yet but I'm going to write the function called find empty rows and columns.
And I'm going to pass the aliens and the empty homes if it's
de columns.
Right.
D Rose bottom.
OK.
And these largely find all the empty row empty columns and and bottom rows that we have in the elite.
It's OK.
And again we're going to need that so when they actually move to the right or left in the then we know
which.
Which columns should hit the the edge before it actually moves down.
And then back.
OK.
So we're going to need that at some point or we're not going to implement that just yet.
And in a minute and or in say a number of columns is the number is
is the number of
union columns minus empty
columns left minus the in the columns right.
That's just how many are actually left and we're going to get the Left position
of the aliens
and or in-seat aliens dot Sion X plus
and B are empty columns.
And d Combs left Heinz
unions don't great sized weight loss.
You know it's expanding
and we're also going to need the right position
or should be left in the ocean.
What's the number columns that we have times in
sed rate.
So it's
just the number of columns it's one times you know millions
patting things are just getting the left and right side of the aliens warm day.
It's already here.
So if
you're right alien position is greater then the game not the size.
Wit and we're going in the right direction.
It's greater than zero.
Or
the left alien position.
Is less than or equal to zero.
And aliens dot direction is less than zero.
And
we have to move horizontal or the next move is the horse is a horizontal move and we're not done game.
So we're not at the end of the actual thing here.
So lines really just means like level or at or like not level but like what current row we're at.
So if the row is 11 then we have to invade now essentially then we will move I say move horizontal is
false because we're actually going to move down here.
This is the move down because we've hidden edge K and or Asay aliens dot position dot y plus plus the
next line.
Aliens dot line minus minus.
We're going to switch the direction
this means.
Action and you're also going to reset the movement time
the aliens say because we need to do this all over again the next time right.
And we're going to say If move.
Horizontal
then the aliens position X plus ghouls aliens direction.
We're going to reset the movement time again.
Because we just went whatever direction that we're going in.
So you have to wait some amount of time again to do it and say aliens dot animation
and animation.
So if it was 0 then it should be 1.
Otherwise it's
so this was kind of a lot of stuff and we're still not done.
But kind of to recap essentially again if I run this
this for now.
So if I run this up see how they're moving already.
They're not animating yet.
So once they hit the right edge here they should go back
see it drop down and then now they're going backwards.
OK.
So that's kind of nice but kind of recap this or actually this is actually a good example.
So
the reason why we did this kind of left alien position right aliens mission is to see where the left
most are.
In this case the most alien position is which is right here.
So say I only had I had like this.
This is still the rate most alien position because I have an alien on the right.
OK.
So this whole column hasn't been cleared yet.
So if this hit the right edge then we should drop down and then go to the left again.
So that's really what all of this is saying saying find me the left edge of the aliens find me the right
edge if the right edge of the aliens is greater than the window size.
So if it's at the if it's at the actual and or the rightmost edge of the window and we're going in the
right direction or if we're at or if the left edge of the aliens is at the left edge of the screen and
we're going left and we have it and we can move right then go down OK so move down and then switch or
directions.
And Doree this line stuff for now we're going to get to that of later so move down and then don't move
horizontal.
OK.
And then otherwise if we didn't move down just keep moving in the direction you're going and then reset
your movement time and then switch your animation.
So now let's deal with the animations.
It kind of looks kind of good.
So don't worry about this stuff yet.
OK.
We'll do this after.
So in our
utils
what I want to do is I want to have the offset here.
And this offset will actually be animation.
And so if you look at Texana baiters that H.
So it goes 0 1 2 3 for our sprites and the height of the sprite is 2.
So we have to go by twos for animations so 0 is the first animation and then it's starting at 2 0 1
2 is the next Sprite to draw.
Ok so this offset here really will be the animation that we're at.
OK.
So now that we have that in our raw
in our draw we need to also pass the animation that we're on aliens
animation times the aliens dot straight sized dot height.
Are going to pass this.
So this will kind of skip.
So if the animation is 0 then it'll only draw the first two and if the animation is one it'll skip the
first two and then only draw the second two.
OK so are shouldn't be here it should be.
No no animation for the explosion should be in the actual when it's alive.
And just copy and paste that for each one
OK.
So now if we run this
see them move or see them animate as they move.
So you know that's working.
And it should drop down and keep animating and going to laugh.
Hey so that's pretty cool.
But they don't teach us this too but they don't actually hit the proper edge yet we still haven't done
that because we can commented out this function and what this function will do.
Is it will actually find which rows and columns are actually got this point.
So what's actually infinite this.
This one's going to be actually fairly long.
Fortunately
But it's important to us.
So Boyd
an we're not going to change the aliens at all.
Passed in these by reference because these are going to be kind of the output function
so start implementing this.
So I hope the animation portion of it made sense of what's what's happening.
OK.
I hope hope that makes sense.
So really we're just kind of indexing further into the array for the sprites.
Jay that's that's really what this is this is doing.
So for the find empty rows and columns
save you found false
in we're going to go by columns this time and not rows
and this will be kind of the left.
We're going to check all the left columns.
It's
from
column
that and then we'll go through rows of that column
and this found will essentially once we find someone in that column then we're done.
So if aliens dot millions of row and column.
So as long as it's dead we'll keep going.
We're exploring the as dead.
Or maybe we shouldn't have it actually.
So maybe if it's exploding it shouldn't because there might be some weird problem with that actually.
So if the row alien is one
so if we're at like the end of the rose.
So this is the last row
then we know there's no
there's no column there.
They're all that
should be.
Otherwise we found one.
So we should kind of exit out of this and we're done and we're done.
And that's essentially what we're going to do for the other side.
So I reset this false accuracy for it.
See
Ilion.
COLMES So now we're starting at the right
sees zero found.
It's minus.
So start from the right and work your way back.
Back in the couples column C
is in row 0 row is less than number of alien rows.
And again we haven't found anything
ropes plus.
So basically the same thing if aliens dot row column is dead.
Right.
And if the rover at the last row
then this is an empty column
go straight.
Going otherwise we found something
exit out of this entire.
And raising this found by the way to the exit of two loops.
OK.
So both loops are exiting out of that's where we're now using break here just for information.
And we're also going to loop over the
loop over the bottom
falls or in touch bottom rows they.
So if gange these same thing and dot row home
it's all dead.
Then read the last column
and we know we have an empty row in the bottom
K else.
So I don't run this without calling this function and I'm going to run this with calling this function.
So I'm going to not call this function you know run it and when do is I'm going to attempt to you destroy
them all.
For they get to and this
so yeah see how they drop down even though they weren't at the edge.
So which is I'm going to do this again.
But have this find empty rows and columns
to do the same thing.
Kill three or one or three columns.
Why not.
Now see how they're not dropping down.
They should have been dropping down by now if we had the find empty rows and columns called or not called.
So see how they dropped down now.
And at the end of this day.
So that's why we need that function to actually
to actually hit the edge properly.
They just get the idea it's going to take too long to get.
So you get the idea.
So now that we have all that done
in the next lecture
we're going to work on having the aliens kind of destroying the shields.
So see you then.