Now we have the aliens moving around.
We should combine them with the shields.
To do that to make a new function
is going to be called destroy a shield.
It's it's going to take in the swarm
and it can take the shield as well
and shoot it down here and call them or call it intially when we move down or move to the left or right.
So it call it great here.
Troy
yields like that unions shields member of shields remember that we passed it in before last time to
call it here as well so we'll destroy all the shields.
They kind of overlap.
OK so now that we call them How is this going to work.
Well they all we're going to do is go through all the shields or all the aliens or the
RO
alien Roux's plus
go.
Call us.
And if the alien at that row and column is alive
then we will essentially kind of collide them with the shield.
So first we'll get the position exposition and one position of this current alien
is for
which separates these
y position.
Colin Roe
Okay.
And I think what we'll do is have a new function.
This one's going to be fairly complicated.
And we call it Clyde shields with you you know passing the shields and the number of shields and the
exposition in the y position and the size of the aliens you just pass in
criticizing this day.
So we don't have this function yet.
But essentially all we're doing is going through all the aliens and then colliding current alien that
ranch with all the shields that it actually collides with.
And so of kind of the major outline of it
is declared here.
Size.
Konst.
Scott's.
That you go back down and.
So this is going to be fairly complicated.
Hopefully we'll be able to follow what I'm doing essentially I'm going to go through all the Shield's
and
and get current shield that are at
that and run to see if the alien actually intersects with the shield.
OK.
So if the alien
if the Let's rename this something nicer when I call it alien position X you know session y.
Notice that I don't need to have the same name as I have.
So in this one it's called X and Y.
This doesn't actually matter.
Ok whatever it's named up there doesn't affect what's named here.
OK what is.
Use these names
so essentially if the alien position
X is less then the shield position X plus shield is right.
And so if it's kind of like less then the dot x.
So if it's less then the
right edge.
So if the alien position X is less than the right edge which is what this is saying the right edge of
the shield
and you know in position X plus the Yulian size dodge of the alien is greater than or equal to the shield
position X can
so
saying if the left edge of the alien alien is less then the right Moat's most edge of the shield and
the rightmost edge of the alien is greater than the leftmost edge shield.
And
the same thing but in the wider action section wants less than you session why US shield.
Right.
And in
wifeless sized ch ch it's greater than equal to shield.
Why.
So really all this is thing things as it intersects with the shield.
It's also saying okay and if you're not understanding this maybe just posin kind of draw it out find
it really helps and see how this is working OK.
So to move on.
So if we're colliding.
So
for colliding then we need to know kind of where we're colliding.
So UI alien Zeeshan.
Why is she you.
Ch
he said we're going to need this later.
Sishen X explain this quite yet.
Basically you want to go through the height of the in
seised right.
Plus
in order to get the y position of the shields at that height.
OK so if shield y position is greater than zero and the shield Y is less than shields.
It's great height.
That then we're going to go through each of the or each part of the width of the alien to see where
we should where we should destroy the shields.
So if the shield x is greater than or equal to zero
and shield less than
teach me
k so
shields right.
Shield why.
So this is the shield Why is really the index into the Spryte shield.
X is also index into the Spryte So this is this indexing to the spray on the rose and this is Zendiks
into the spray into the columns.
So if we find it right.
So essentially we're finding the position of where where we kind of are in the shield essentially.
And then we're kind of looping through the height of the
height of this alien and we're getting the position the actual index position of the sprites of the
shield.
K. and then if we're kind of within the Spryte vertically.
What this is saying then we will go through this.
The aliens bright horizontally and check to see if we're actually within the shields bright horizontally
and if we are we'll set these positions.
Shield wind shield acts to be to be empty.
So kind of like it's the shield.
You know it's
so you know we can only know we can only intersect a shield or one ceiling can only intersect one shield
so if we do actually go through the whole height of the alien error of the of the alien then we know
we're kind of done.
So we can just break off our.
So we don't need to keep going through all the shields in this go if you're the one that we know we
actually collided with.
So know it was a little bit confusing but again try to maybe pause the video really kind of draw everything
out to make sure you understand what's happening.
This is always kind of the hardest part of teaching or showing people's things.
You really have to see see a real kind of picture in your head of what this is really doing.
OK.
But let's run this.
Actually you efforts that stopped is recycled and let's make it go way faster.
So that's going to be here forever.
That is going to make the move in time be fast basically as fast as possible.
So it's going to go really quick.
Check to see if we eat the shields when we go through.
Shields are being eaten.
They go.
So it's working it's pretty good.
So now.
So if you don't remember why you are even doing this.
Said if the aliens said somewhere in here really remember
that somewhere in here that if the aliens kind of overlap the shields then the shields are destroyed.
So that's that's very important.
Yes.
So here says when invaders are low enough to touch the base shelters they erased them as they pass.
Kay.
So that's what we're doing.
This needs to kind of functions here.
And destroy shields and collide.
OK.
So again if you're not quite understanding I know there's like three loops and it's all very confusing.
But really all we're saying is hey are you intersecting with a shield.
If you are find out where you're intersecting.
OK.
And that's what all of this does.
OK.
So find out where you are intersecting and wherever you're intersecting just make it to be empty.
OK.
So that's it for this in the next lecture.
I want to start dropping some bombs on the player.
We'll see you in the next lecture.