1
00:00:03,060 --> 00:00:07,500
There's a quick piece of tidy up that I want to do, and I'm going to set this to you as a nice, meaty

2
00:00:07,500 --> 00:00:07,950
challenge.

3
00:00:07,950 --> 00:00:10,560
And that is when we bump on the ground, we no longer have control.

4
00:00:10,560 --> 00:00:15,720
But if we bounce twice, then it plays the sound effect twice and plays the particle effect twice as

5
00:00:15,720 --> 00:00:16,140
well.

6
00:00:16,140 --> 00:00:19,050
So that's something that I want us not to have when you bounce.

7
00:00:19,050 --> 00:00:23,550
Once we have one particle effect, we have one sound effect, but it doesn't trigger for the second

8
00:00:23,550 --> 00:00:27,930
time or the third time or the fifth time, depending upon where you're crashing and how you crash.

9
00:00:27,930 --> 00:00:32,460
So I'm going to give this to you as a challenge to stop the double plays, implement some code so that

10
00:00:32,460 --> 00:00:36,270
the crash, sound effects and particle effect can only be triggered once.

11
00:00:36,270 --> 00:00:38,490
And if you'd like some hints, then hang around.

12
00:00:38,490 --> 00:00:41,940
If you don't need any hints, pause a video and dive into that.

13
00:00:41,940 --> 00:00:43,140
Now see if you can figure it out.

14
00:00:43,140 --> 00:00:47,730
And I encourage you to give it at least a bit of a try before you listen to the hints here.

15
00:00:47,760 --> 00:00:48,450
Give it a go.

16
00:00:48,450 --> 00:00:51,750
But if you do want some hints, here they are, consider using a bull.

17
00:00:51,750 --> 00:00:57,510
We used a bull in the last lecture, so that's fresh in our memory and also consider using the and operator

18
00:00:57,510 --> 00:01:02,760
which is these two ampersand that's the name of this sign these two ampersand together to see if something

19
00:01:02,760 --> 00:01:04,410
and something is true.

20
00:01:04,410 --> 00:01:05,790
So there's a couple of hints for you.

21
00:01:05,820 --> 00:01:07,380
Pause the video, take on that challenge.

22
00:01:07,380 --> 00:01:08,580
See you back here when you're done.

23
00:01:11,950 --> 00:01:12,340
Right.

24
00:01:12,340 --> 00:01:14,530
So I need to be in crash detector.

25
00:01:14,980 --> 00:01:18,640
And within here, I'm going to set myself up a bull.

26
00:01:18,640 --> 00:01:20,020
That will be.

27
00:01:20,020 --> 00:01:20,770
Let's see, something.

28
00:01:20,770 --> 00:01:27,580
As long as I bull has crashed, I think because that will signal that it's the end of what's going on

29
00:01:27,580 --> 00:01:33,790
here has crashed and we're going to initialize that at false because you haven't crashed as a default.

30
00:01:33,790 --> 00:01:35,500
It's only once you crash that you crash.

31
00:01:35,500 --> 00:01:40,300
And then when we bounce into the ground, the first thing I'm going to do is say, well, you have crash,

32
00:01:40,300 --> 00:01:42,340
you now have officially have crash.

33
00:01:42,340 --> 00:01:45,040
So has crashed equals true.

34
00:01:45,040 --> 00:01:46,570
We're going to change our ball.

35
00:01:46,570 --> 00:01:53,050
And now the most important part of this is is to say, don't do all this stuff if you've already crashed.

36
00:01:53,050 --> 00:01:54,850
And the way we can do that is pretty simple.

37
00:01:54,850 --> 00:02:02,800
In our if statement here we've got if we've bumped into the ground, we can add in here and has crashed

38
00:02:02,830 --> 00:02:04,180
is what is equal false.

39
00:02:04,180 --> 00:02:09,520
So I could type it like this equals equals false or we could do it a slightly quicker way, which is

40
00:02:09,520 --> 00:02:13,750
to put an exclamation mark in front of has crashed, which means not has crashed.

41
00:02:13,750 --> 00:02:17,350
So if you have not crashed already then do these things.

42
00:02:17,350 --> 00:02:19,450
The first thing we'll do is change it over to be true.

43
00:02:19,450 --> 00:02:24,070
So yeah, you have now actually crashed, but go ahead and finish what is in this method.

44
00:02:24,070 --> 00:02:29,740
We haven't talked about this much, but all of the code within a block, a code block here will execute

45
00:02:29,740 --> 00:02:33,460
before any of those things is going to change our if statement.

46
00:02:33,460 --> 00:02:40,900
So yes I've got has crashed equals true but it's not then going to change the fact that we are executing

47
00:02:40,900 --> 00:02:42,340
our code block.

48
00:02:42,340 --> 00:02:45,490
It's going to execute this and this and this and that.

49
00:02:45,490 --> 00:02:49,990
And then if we bump into the ground again, it will come back and say, okay, are these conditions

50
00:02:49,990 --> 00:02:50,500
being met?

51
00:02:50,500 --> 00:02:51,430
Yes or no?

52
00:02:51,430 --> 00:02:56,020
So just to be clear on that, that this will all be executing, despite the fact that we've got this

53
00:02:56,020 --> 00:02:59,200
at the top, it doesn't change it and exit out of our method.

54
00:02:59,200 --> 00:03:01,660
Now let's save and see if this works.

55
00:03:01,660 --> 00:03:05,590
If I've got all the steps or if I've missed any of the steps bounce.

56
00:03:05,590 --> 00:03:10,840
And you can see I bounce a couple of times after that, but there was no extra sound effect and no practical

57
00:03:10,840 --> 00:03:11,110
effect.

58
00:03:11,110 --> 00:03:15,010
So that was exactly what I was going for, just to tidy up that little double bounce thing.

59
00:03:15,010 --> 00:03:19,570
So that was a very quick one, quick little exercise there and tidying up our code, nothing more.

60
00:03:19,570 --> 00:03:20,170
In this lecture.

61
00:03:20,170 --> 00:03:21,400
I will see you in the next one.

