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
challenge.
And that is when we bump on the ground, we no longer have control.
But if we bounce twice, then it plays the sound effect twice and plays the particle effect twice as
well.
So that's something that I want us not to have when you bounce.
Once we have one particle effect, we have one sound effect, but it doesn't trigger for the second
time or the third time or the fifth time, depending upon where you're crashing and how you crash.
So I'm going to give this to you as a challenge to stop the double plays, implement some code so that
the crash, sound effects and particle effect can only be triggered once.
And if you'd like some hints, then hang around.
If you don't need any hints, pause a video and dive into that.
Now see if you can figure it out.
And I encourage you to give it at least a bit of a try before you listen to the hints here.
Give it a go.
But if you do want some hints, here they are, consider using a bull.
We used a bull in the last lecture, so that's fresh in our memory and also consider using the and operator
which is these two ampersand that's the name of this sign these two ampersand together to see if something
and something is true.
So there's a couple of hints for you.
Pause the video, take on that challenge.
See you back here when you're done.
Right.
So I need to be in crash detector.
And within here, I'm going to set myself up a bull.
That will be.
Let's see, something.
As long as I bull has crashed, I think because that will signal that it's the end of what's going on
here has crashed and we're going to initialize that at false because you haven't crashed as a default.
It's only once you crash that you crash.
And then when we bounce into the ground, the first thing I'm going to do is say, well, you have crash,
you now have officially have crash.
So has crashed equals true.
We're going to change our ball.
And now the most important part of this is is to say, don't do all this stuff if you've already crashed.
And the way we can do that is pretty simple.
In our if statement here we've got if we've bumped into the ground, we can add in here and has crashed
is what is equal false.
So I could type it like this equals equals false or we could do it a slightly quicker way, which is
to put an exclamation mark in front of has crashed, which means not has crashed.
So if you have not crashed already then do these things.
The first thing we'll do is change it over to be true.
So yeah, you have now actually crashed, but go ahead and finish what is in this method.
We haven't talked about this much, but all of the code within a block, a code block here will execute
before any of those things is going to change our if statement.
So yes I've got has crashed equals true but it's not then going to change the fact that we are executing
our code block.
It's going to execute this and this and this and that.
And then if we bump into the ground again, it will come back and say, okay, are these conditions
being met?
Yes or no?
So just to be clear on that, that this will all be executing, despite the fact that we've got this
at the top, it doesn't change it and exit out of our method.
Now let's save and see if this works.
If I've got all the steps or if I've missed any of the steps bounce.
And you can see I bounce a couple of times after that, but there was no extra sound effect and no practical
effect.
So that was exactly what I was going for, just to tidy up that little double bounce thing.
So that was a very quick one, quick little exercise there and tidying up our code, nothing more.
In this lecture.
I will see you in the next one.