That we have the Shield's drawing.
I'd like to be able to collide them missiles that the player shoots.
So up here and then to make a new function call it it is collision and it can take a position for a
projectile
and then take all the shields
in a number of shields.
And I'm also going to have in out only parameter called
Shields collision point.
So essentially this will return me the search turns the shield index into our shield array of which
one got hit which Shield got hit.
And it will return.
Not in play I guess.
If nothing was hit.
And also I'm going to return out a shield collision point.
So also turns the shield collision point of of like whatever point of the Shield got hit.
So I look here.
So if say this one got hit then I'll return you know 0 1 to the first of the first part of the Great.
So you'll actually tell me where in the shield you got hit.
It does kind of two two things.
So let's start implementing this in this once again.
This one's a little bit trickier function.
It's not too tricky but it's tricky to know that this is the signature that you really want.
OK.
So she'll collision point docked X is going to put it to be not play initially or.
So whatever they pass in we're not going to have it in play.
Now
we're all shoes too.
Ellen Glasheen
conclusion that.
So initially if we didn't hit anything then this won't be set to anything.
So now we will say if we have an actual projectile if the projectile is not equal to not play.
So if it isn't way.
Then we're going to loop through all the shields
like that and are going at the current shield and we're not going to change the shield in any way says
Konst
that.
And now we have to check to see where it collided.
So say if the projectile
x is greater than the shield not position X and the projectile X is less than the shield position dot
x y a shield.
Right.
With.
So this is saying is it is correct that this is saying is it on the same.
Or is it in line horizontal
project or on
like so is that so is it actually.
So is the project tells x x component within the width of this current shield is what this is saying.
So if it's greater than the greater than or equal to than the shields position rain and again the shields
position is kind of the top guess is the top left yes of the shields right.
So if it's if it's greater than or equal to the left most portion of the shield and it's less than the
rightmost portion of the shield which is this right then it's then it's in line horizontally.
But we also have to say and is it in line vertically
is it in mind vertically some shield or is it projectile
Why is greater than or equal to shield position Y and
you dial Y is less than shield position Y plus shield separate CH Right.
You know on your
it's
this
see this.
So is it inline vertically as well.
All right.
I think that's right.
So is it in line vertically as well.
That's that's kind of what this is saying.
So is the projectile within the show you
show you in here so say the projectile was here.
This so it's within the boundary of the width of the shield and it's also in boundary of the height
of the shield.
OK.
So that's that's where those two two vines are saying as far as a new another one.
And the shield sprites and then projectile
wind minus shield
and why.
Project X minus shield position and x is not equal to an empty space.
Right.
So in within the action.
So as long as these two are true.
OK.
So then it's within the actual shields right.
And if the projectiles position in the shields upright is not a space right then then this must be a
collision.
And so we collide.
If you're not truly understanding this quite yet.
Just pause the video and really kind of look at what it's saying.
So it's really just saying in line horizontally the first line is it in line vertically.
Right.
That's the second line.
And the third line is racing does it
collide with part of the shield.
Or alternatively saying does it not collide with an empty space OK.
Right.
So if all of these are true then we collided.
So the shield point will be this shield collision point X will be exactly this projectile
is checked dial X minus the shield position X
which point is and the shield collision point which
y seem trip down.
Why is this shield position.
Why is that.
OK so we're going to be returning this by the way.
And also we return the actual shield effects so we all sort of turn k.
So otherwise we didn't find it and quite an
AM I IN LINE.
Horizontally and vertically.
Does it collide with an actual physical part of the shield.
It's not it hasn't collided there before.
Right.
If so then we take the position that it collided in relative to the shield.
Right.
And we returned it.
So hopefully this makes sense again posit really kind of look at it and really try to understand what's
happening here.
This is pretty important.
Collision detection is always kind of kind of hard to understand at first.
So really tried to try to grasp it as best you can.
So if it collided then it will also need some kind of.
So this just checks to see if it collided or not.
We still need to resolve the collision.
So resolve shield collision and this will be much easier as shield shields and shield index in the position.
It's designed to change shield collision point.
And this one's pretty easy to say shields of shield index
Sprite and then say shield
collision point.
Why and shield collision point dot x is empty
groan is complaining to me.
OK so just set the actual.
So for whatever SHIELL index it was set wherever it collided to be.
So all the heavy lifting is in the actual collision.
Check.
So now we need to actually call these.
And also probably cleared him already.
He declared the collision.
So now in the game we'll say the positions of position the shield region point and pass it in.
Actually before this if were in say
we're going to make a shield
index in we're going to call is collision
take it takes the projectile the shield say and the number of shields and shoot collision.
It's so
you project is a player.
So
the shields have a shield to pass in.
You see
there is so as you
number Shield's
copy is a copy
these
can that see shields and the number.
It's
an impasse in the shield collision point
right.
And basically were to check to see if the shield index is not equal to not play.
So if if this is true then we know it hit right.
Because if it's if it's if it does return not in play.
I mean no it didn't hit at all.
OK.
So we're going to say reset the missile because it hit
that and we're going to say resolve shield collision shields shield
index and the
shield collision which
that
and now in the game we also have to pass in the shields in the shields that.
So now we run this
you should see that the shields get broken any time the time you hit they
that
day.
So it's working just great.
So in the next lecture I want to start doing are getting the the aliens to start drawing on the screen.
OK.
I'll see you in the next lecture.