Hey, this lesson, more tweaks and adjustments, so we did want to add in this Storper option where
the ball will actually sit on top of the paddle and it's actually not going to be moving or it's not
going to be in play until the player wants to place it into play.
So creating another object within the player in play by default, we're going to set this to false and
then apply this condition where we need to.
And this is also going to be sitting on top of the stopper.
And we're also going to update this inplay value when we do the key presses.
So when the key press is whenever the key is pressed and player in play is not true, that we're going
to set it to true.
We're going to check to see if key 38 is being pressed.
And that's the up arrow.
So you can apply a few different keys if you wanted to, to this function as well.
And we're checking to see if player in play is not true.
And if that's the case, then we're going to take player in play and we're going to set that one to
true so that our way to toggle that and that will give the player the ability to launch the ball whenever
they're ready to launch it.
So we need to add in a few more things where we don't want the ball actually to be moving or we want
to adjust the ball movement to be in line with what's happening with the paddle because we're sitting
on top of the paddle, has to move along side with that.
So going down to where we have the ball move and update the so we can have a condition that will check
to see if the ball is on the paddle.
So take move ball.
And we're going to move that just to just under here where we've updated the paddle position because
we want to use that to also update the ball position.
And we're going to apply our condition here to check to see if player inplay.
Is not true.
So if it's false.
Then that means that it's waiting on the paddle, otherwise we know we can move the ball naturally.
However, the ball needs to move so we can apply the move ball function there.
And if it's waiting on the paddle, we're going to create another function that will be or we actually
probably don't even need a function for that where we can update the ball position directly here.
We're updating the ball style and updating the ball style.
Top position will be equal to whatever the paddle.
Offset and we use these offset values again, so that offset top and then subtracting roughly around
20 and we'll have to check that just to make sure that we did get that properly.
And then the ball style left position is going to be equal to whatever the current position left is.
And as well, we need to add to that so we can take that current position.
So this is going to be the same as the left and add 50 to the current position.
So see what happens.
So now we've got the ball sitting on top of the paddle and we move it along and then when I press the
upkeep, you're going to see that it actually moves alongside.
So this situation where the ball has moved, now we have a function that we can set.
We can set this in play, and that means that's going to be sitting on top of the paddle.
So when it goes, whatever it falls off, we can apply that where we're sitting the ball on top of the
paddle.
And that will give us the ability to set it and move it along side.
So whenever it falls off the edge, the starting position is going to be wherever the stopper is setting
it to.
So taking that stopper position stopper function that we created earlier, now we can use that game
player in play value and set that to force and then also take the player ball direction.
We need to make an adjustment for that because we saw that as well, that we need to always set it to
the negative so that it will always start out decreasing in value.
So moving up and also the ball direction by default, we're going to set it to zero.
And actually I'm going to break this off.
And the reason I'm going to do this is breaking it off of the current position is so that we do have
a function where we can reset the position.
So let's do a quick adjustment here and we'll call it waiting on paddle.
And what this function is going to do is this is going to take care of the ball position so that we
can call to this function over here and we're going to reuse that same function where we're going to
position the ball position.
So instead of the current position, we're going to take the current offset left position and we're
going to add 50 to it in order to position it on the paddle.
So now, whenever we need to position it and we within Storper, we can call to that function and that
will reposition where the ball is sitting and place it on top of the paddle.
And then when we're moving the paddle, then we can see where the ball is going to be sitting.
And there's one more that we wanted to add in as well, and that is to stop the animation.
So we've have an option where we can give the animation frame a name.
And when we start the animation, if we call it a name, that we can access it.
We can also use that to stop the animation.
So you can just call it player any.
And then within itself, as we are calling itself, we're going to also give it that same name so that
we can always refer to it.
And then within Storper, we have an option here to cancel the animation subframe so we can go window,
cancel animation frame, and then we need to specify the name of the animation frame that we want to
stop and cancel.
So I think we're ready to try that and we can move the ball and sitting on top of it went off and we
can adjust the lives so that we have a little bit longer gameplay.
And sometimes it does take a few times where you have to play through the game just to make sure you've
got all of the functionality that you were looking for.
So see where decreasing in lives and whenever it's running off, then the ball is sitting on top of
the paddle and when we move the paddle, the ball moves along side.
Well, also, I just noticed that it's not directly centered.
So maybe we'll want to make an adjustment to where we've got the offset, whatever the ball is sitting
on top of the paddle.
So we still have that within that one option here.
So we can maybe even move it down a little bit and move it over to the left hand side because the ball
hits.
The paddle was one hundred, the ball was 20.
So taking half of that should give us a good starting point for the ball.
And we can also move that down a little bit more as well.
So it looks more like it's sitting on top of the paddle and you can adjust and tweak it as needed.
So I think that was a little bit too much.
And sometimes we do need to make a few little minor adjustments to get at work in the way that we need
it.
Coming up next, we're going to do a final run-Through of the game, make sure that we've got all of
the functionality that we set out to produce and also do a quick code review.
And I just noticed one of the thing that we do need to adjust and we still have the ability to run the
paddle off the screen.
So we want to create those boundaries.
So that's coming up next.
One more tweak, an adjustment lesson and then a code review.
So that's still all yet to come.