1
00:00:00,270 --> 00:00:03,120
Now we're pretty close to the end of the program.

2
00:00:03,240 --> 00:00:08,130
We've managed to do pretty much everything other than detect when the paddle

3
00:00:08,130 --> 00:00:12,630
actually misses a ball. And if the right paddle misses the ball,

4
00:00:12,780 --> 00:00:15,150
then the left player gets a point.

5
00:00:15,930 --> 00:00:20,340
And this should trigger a restart of the game where the ball goes back to the

6
00:00:20,340 --> 00:00:23,760
center and starts off in the opposite direction.

7
00:00:24,600 --> 00:00:26,010
In order to do this,

8
00:00:26,040 --> 00:00:30,240
to detect when a paddle has actually missed the ball, effectively,

9
00:00:30,240 --> 00:00:35,130
what we're checking is that the ball has gone past a certain point on the

10
00:00:35,130 --> 00:00:37,590
screen. So we know that we're already

11
00:00:37,590 --> 00:00:42,240
checking when the ball goes past this line and it's within 50 pixels of the

12
00:00:42,240 --> 00:00:42,960
paddle,

13
00:00:42,960 --> 00:00:46,740
then it should bounce back because that means the ball was caught by the paddle.

14
00:00:47,130 --> 00:00:51,150
But if it goes further than that, if it goes beyond that on the screen

15
00:00:51,450 --> 00:00:53,820
like over here or over here,

16
00:00:54,090 --> 00:00:57,450
then that means it's a miss and we should reset the ball.

17
00:00:58,200 --> 00:01:01,140
Have a think about how you might create this behavior,

18
00:01:01,650 --> 00:01:05,310
and as a challenge to yourself, see if you can complete the code.

19
00:01:09,920 --> 00:01:12,200
So I'm going to add another comment here

20
00:01:12,230 --> 00:01:17,230
which is going to be detect when right paddle misses.

21
00:01:19,490 --> 00:01:21,920
The right paddle has basically missed the ball

22
00:01:22,040 --> 00:01:27,040
if the ball.xcor is beyond 380.

23
00:01:28,430 --> 00:01:31,550
We know that the width of the screen is 800

24
00:01:31,640 --> 00:01:34,850
and we know that the paddle is at 350.

25
00:01:35,120 --> 00:01:40,040
So the paddle basically goes from 340 to 360,

26
00:01:40,370 --> 00:01:42,470
and if it's already gone past 380,

27
00:01:42,470 --> 00:01:47,120
then the paddle has definitely missed the ball. So in this situation,

28
00:01:47,150 --> 00:01:50,570
we're going to get the ball to reset its position.

29
00:01:51,170 --> 00:01:55,160
And this is going to be a method in the ball class.

30
00:01:55,730 --> 00:01:58,580
So let's create it and I'm just going to paste it in

31
00:01:58,580 --> 00:02:03,580
so I don't make any errors in terms of the naming. Resetting the position of the

32
00:02:04,640 --> 00:02:09,639
ball is going to involve getting the ball to go to the original position.

33
00:02:10,310 --> 00:02:15,230
So we can tell self to go to (0, 0).

34
00:02:16,010 --> 00:02:17,780
Now, if we run our code,

35
00:02:18,020 --> 00:02:22,490
you can see when the ball has gone past a certain point and it's not caught by

36
00:02:22,490 --> 00:02:25,490
the paddle, it goes back into the center.

37
00:02:26,810 --> 00:02:30,380
But we want the ball to go in the opposite direction

38
00:02:30,500 --> 00:02:35,300
once it's been missed by the right-sided player. It's time for the left-sided

39
00:02:35,300 --> 00:02:36,650
player to get a turn.

40
00:02:37,430 --> 00:02:41,420
So in addition to getting the ball to reset its position,

41
00:02:41,750 --> 00:02:45,830
we're going to get the ball to reverse its X-axis.

42
00:02:46,280 --> 00:02:49,610
So we're going to call self.bounce_x.

43
00:02:50,480 --> 00:02:53,630
Now notice how when the ball gets missed,

44
00:02:54,050 --> 00:02:56,420
then its direction gets reversed,

45
00:02:56,510 --> 00:03:00,610
it starts off in the center and it goes off in the opposite direction.

46
00:03:01,360 --> 00:03:05,100
Let's go ahead and define the left-sided paddle miss.

47
00:03:07,530 --> 00:03:12,530
And we can do that by simply saying ball.xcor is less than -380.

48
00:03:15,600 --> 00:03:19,920
And in this case, we're again going to get the ball to reset the position.

49
00:03:20,490 --> 00:03:20,670
Now,

50
00:03:20,670 --> 00:03:24,900
the reason why I've got these in separate if statements is because later on,

51
00:03:24,930 --> 00:03:29,610
we're going to need to detect when the right-sided player or the left-sided

52
00:03:29,610 --> 00:03:33,420
player actually gains a point. So when the right paddle misses,

53
00:03:33,720 --> 00:03:37,650
the left player gets a point, when the left paddle misses the right player

54
00:03:37,650 --> 00:03:38,490
gets a point.

55
00:03:39,660 --> 00:03:44,070
Now when the ball goes past the right edge and it's not caught by the paddle,

56
00:03:44,430 --> 00:03:47,430
then it starts off in the center and it moves to the left.

57
00:03:47,850 --> 00:03:51,480
When it's not caught by the left side of the paddle,

58
00:03:51,660 --> 00:03:54,210
it starts off in the center and it goes to the right.

59
00:03:55,080 --> 00:03:59,190
All that's left to do is to figure out how to do the scoring.

60
00:03:59,550 --> 00:04:02,130
And that is what we're going to do on the next lesson.

