WEBVTT

00:00.770 --> 00:02.900
That we have the Shield's drawing.

00:02.900 --> 00:09.070
I'd like to be able to collide them missiles that the player shoots.

00:09.260 --> 00:27.350
So up here and then to make a new function call it it is collision and it can take a position for a

00:27.350 --> 00:28.490
projectile

00:31.350 --> 00:34.330
and then take all the shields

00:38.330 --> 00:40.730
in a number of shields.

00:46.800 --> 00:54.510
And I'm also going to have in out only parameter called

00:56.830 --> 01:02.400
Shields collision point.

01:02.410 --> 01:15.370
So essentially this will return me the search turns the shield index into our shield array of which

01:15.370 --> 01:24.390
one got hit which Shield got hit.

01:25.430 --> 01:27.950
And it will return.

01:28.680 --> 01:30.490
Not in play I guess.

01:32.110 --> 01:37.440
If nothing was hit.

01:39.320 --> 01:45.530
And also I'm going to return out a shield collision point.

01:45.590 --> 02:00.210
So also turns the shield collision point of of like whatever point of the Shield got hit.

02:00.240 --> 02:02.030
So I look here.

02:02.030 --> 02:16.010
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.

02:16.490 --> 02:22.310
So you'll actually tell me where in the shield you got hit.

02:22.410 --> 02:26.370
It does kind of two two things.

02:26.370 --> 02:34.310
So let's start implementing this in this once again.

02:34.310 --> 02:36.420
This one's a little bit trickier function.

02:38.500 --> 02:46.190
It's not too tricky but it's tricky to know that this is the signature that you really want.

02:46.270 --> 02:47.820
OK.

02:48.990 --> 03:00.060
So she'll collision point docked X is going to put it to be not play initially or.

03:00.100 --> 03:07.030
So whatever they pass in we're not going to have it in play.

03:07.120 --> 03:07.340
Now

03:10.490 --> 03:13.850
we're all shoes too.

03:13.880 --> 03:14.740
Ellen Glasheen

03:21.800 --> 03:24.200
conclusion that.

03:25.070 --> 03:33.440
So initially if we didn't hit anything then this won't be set to anything.

03:34.310 --> 03:45.860
So now we will say if we have an actual projectile if the projectile is not equal to not play.

03:45.890 --> 03:54.070
So if it isn't way.

03:57.070 --> 04:00.330
Then we're going to loop through all the shields

04:09.930 --> 04:18.230
like that and are going at the current shield and we're not going to change the shield in any way says

04:18.480 --> 04:19.200
Konst

04:26.780 --> 04:27.840
that.

04:28.850 --> 04:34.370
And now we have to check to see where it collided.

04:34.880 --> 04:38.990
So say if the projectile

04:41.680 --> 04:58.910
x is greater than the shield not position X and the projectile X is less than the shield position dot

04:59.120 --> 05:03.720
x y a shield.

05:03.830 --> 05:04.810
Right.

05:07.000 --> 05:09.920
With.

05:10.610 --> 05:22.960
So this is saying is it is correct that this is saying is it on the same.

05:23.240 --> 05:24.890
Or is it in line horizontal

05:35.220 --> 05:36.210
project or on

05:39.240 --> 05:47.880
like so is that so is it actually.

05:47.890 --> 05:59.590
So is the project tells x x component within the width of this current shield is what this is saying.

05:59.590 --> 06:09.580
So if it's greater than the greater than or equal to than the shields position rain and again the shields

06:09.580 --> 06:18.380
position is kind of the top guess is the top left yes of the shields right.

06:18.430 --> 06:29.770
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

06:29.770 --> 06:39.720
rightmost portion of the shield which is this right then it's then it's in line horizontally.

06:40.240 --> 06:46.550
But we also have to say and is it in line vertically

06:49.760 --> 06:57.280
is it in mind vertically some shield or is it projectile

07:01.810 --> 07:10.170
Why is greater than or equal to shield position Y and

07:14.880 --> 07:32.100
you dial Y is less than shield position Y plus shield separate CH Right.

07:52.570 --> 07:53.720
You know on your

08:02.660 --> 08:02.980
it's

08:14.870 --> 08:15.440
this

08:34.310 --> 08:36.390
see this.

08:36.590 --> 08:41.530
So is it inline vertically as well.

08:41.530 --> 08:42.100
All right.

08:43.580 --> 08:46.270
I think that's right.

08:46.840 --> 08:51.130
So is it in line vertically as well.

08:51.470 --> 08:54.670
That's that's kind of what this is saying.

08:55.690 --> 09:01.330
So is the projectile within the show you

09:04.440 --> 09:09.300
show you in here so say the projectile was here.

09:10.180 --> 09:19.180
This so it's within the boundary of the width of the shield and it's also in boundary of the height

09:19.960 --> 09:21.030
of the shield.

09:21.200 --> 09:21.630
OK.

09:21.670 --> 09:30.820
So that's that's where those two two vines are saying as far as a new another one.

09:31.150 --> 09:40.700
And the shield sprites and then projectile

09:42.920 --> 09:45.010
wind minus shield

09:47.360 --> 09:50.370
and why.

09:52.890 --> 10:06.370
Project X minus shield position and x is not equal to an empty space.

10:06.370 --> 10:07.630
Right.

10:07.780 --> 10:10.690
So in within the action.

10:10.690 --> 10:13.230
So as long as these two are true.

10:13.370 --> 10:13.720
OK.

10:13.750 --> 10:17.490
So then it's within the actual shields right.

10:17.860 --> 10:29.170
And if the projectiles position in the shields upright is not a space right then then this must be a

10:29.170 --> 10:29.860
collision.

10:30.020 --> 10:35.980
And so we collide.

10:36.730 --> 10:41.390
If you're not truly understanding this quite yet.

10:41.410 --> 10:46.100
Just pause the video and really kind of look at what it's saying.

10:46.110 --> 10:56.350
So it's really just saying in line horizontally the first line is it in line vertically.

10:56.490 --> 10:56.800
Right.

10:56.820 --> 10:58.360
That's the second line.

10:58.510 --> 11:03.210
And the third line is racing does it

11:06.130 --> 11:11.800
collide with part of the shield.

11:15.150 --> 11:20.910
Or alternatively saying does it not collide with an empty space OK.

11:24.530 --> 11:25.250
Right.

11:25.460 --> 11:29.870
So if all of these are true then we collided.

11:29.870 --> 11:41.290
So the shield point will be this shield collision point X will be exactly this projectile

11:45.150 --> 11:54.600
is checked dial X minus the shield position X

12:01.400 --> 12:08.730
which point is and the shield collision point which

12:11.640 --> 12:16.090
y seem trip down.

12:16.130 --> 12:21.050
Why is this shield position.

12:21.150 --> 12:23.410
Why is that.

12:23.530 --> 12:26.530
OK so we're going to be returning this by the way.

12:26.550 --> 12:35.810
And also we return the actual shield effects so we all sort of turn k.

12:36.180 --> 12:41.680
So otherwise we didn't find it and quite an

12:48.150 --> 12:49.440
AM I IN LINE.

12:49.570 --> 12:51.990
Horizontally and vertically.

12:52.090 --> 12:56.810
Does it collide with an actual physical part of the shield.

12:57.250 --> 13:00.000
It's not it hasn't collided there before.

13:00.010 --> 13:00.540
Right.

13:00.820 --> 13:07.480
If so then we take the position that it collided in relative to the shield.

13:07.540 --> 13:07.870
Right.

13:07.900 --> 13:08.490
Right.

13:08.860 --> 13:11.120
And we returned it.

13:11.800 --> 13:18.760
So hopefully this makes sense again posit really kind of look at it and really try to understand what's

13:18.760 --> 13:20.250
happening here.

13:20.310 --> 13:22.740
This is pretty important.

13:23.500 --> 13:28.010
Collision detection is always kind of kind of hard to understand at first.

13:28.060 --> 13:33.100
So really tried to try to grasp it as best you can.

13:33.730 --> 13:37.770
So if it collided then it will also need some kind of.

13:37.810 --> 13:40.760
So this just checks to see if it collided or not.

13:40.780 --> 13:46.160
We still need to resolve the collision.

13:46.350 --> 14:03.030
So resolve shield collision and this will be much easier as shield shields and shield index in the position.

14:05.370 --> 14:13.450
It's designed to change shield collision point.

14:15.340 --> 14:21.550
And this one's pretty easy to say shields of shield index

14:24.720 --> 14:31.220
Sprite and then say shield

14:33.510 --> 14:37.280
collision point.

14:37.520 --> 14:47.120
Why and shield collision point dot x is empty

14:53.900 --> 14:56.560
groan is complaining to me.

14:57.440 --> 15:00.800
OK so just set the actual.

15:00.980 --> 15:07.410
So for whatever SHIELL index it was set wherever it collided to be.

15:09.060 --> 15:12.970
So all the heavy lifting is in the actual collision.

15:12.970 --> 15:14.940
Check.

15:14.950 --> 15:20.580
So now we need to actually call these.

15:20.590 --> 15:23.890
And also probably cleared him already.

15:27.480 --> 15:31.350
He declared the collision.

15:32.460 --> 15:50.830
So now in the game we'll say the positions of position the shield region point and pass it in.

15:51.170 --> 15:53.780
Actually before this if were in say

15:56.390 --> 15:58.550
we're going to make a shield

16:01.160 --> 16:08.170
index in we're going to call is collision

16:12.540 --> 16:20.020
take it takes the projectile the shield say and the number of shields and shoot collision.

16:20.360 --> 16:22.530
It's so

16:25.560 --> 16:29.090
you project is a player.

16:30.320 --> 16:30.830
So

16:33.290 --> 16:39.870
the shields have a shield to pass in.

16:40.280 --> 16:41.990
You see

16:46.090 --> 16:50.590
there is so as you

16:55.510 --> 16:57.040
number Shield's

17:02.710 --> 17:05.620
copy is a copy

17:08.330 --> 17:09.150
these

17:13.580 --> 17:20.270
can that see shields and the number.

17:20.490 --> 17:20.850
It's

17:24.060 --> 17:28.550
an impasse in the shield collision point

17:34.340 --> 17:35.030
right.

17:36.870 --> 17:55.970
And basically were to check to see if the shield index is not equal to not play.

17:56.030 --> 18:03.130
So if if this is true then we know it hit right.

18:03.380 --> 18:08.260
Because if it's if it's if it does return not in play.

18:08.280 --> 18:09.880
I mean no it didn't hit at all.

18:10.070 --> 18:10.780
OK.

18:11.030 --> 18:15.150
So we're going to say reset the missile because it hit

18:18.160 --> 18:29.350
that and we're going to say resolve shield collision shields shield

18:31.750 --> 18:33.730
index and the

18:36.250 --> 18:38.020
shield collision which

18:40.660 --> 18:41.100
that

18:43.970 --> 18:57.310
and now in the game we also have to pass in the shields in the shields that.

18:57.440 --> 19:00.530
So now we run this

19:05.130 --> 19:12.980
you should see that the shields get broken any time the time you hit they

19:15.760 --> 19:16.170
that

19:21.520 --> 19:21.880
day.

19:21.920 --> 19:25.290
So it's working just great.

19:28.710 --> 19:40.850
So in the next lecture I want to start doing are getting the the aliens to start drawing on the screen.

19:40.850 --> 19:41.680
OK.

19:41.770 --> 19:43.880
I'll see you in the next lecture.
