WEBVTT

0
00:00.150 --> 00:01.080
In the last step,

1
00:01.110 --> 00:06.110
we figured out how to detect when the player turtle hits a car and to stop the

2
00:06.150 --> 00:08.850
while loop which stops the game at that point.

3
00:09.870 --> 00:14.220
Now we're going to figure out how we can detect when the turtle reaches the

4
00:14.220 --> 00:19.220
other side of the screen so that once our turtle makes a successful crossing,

5
00:20.790 --> 00:25.470
then we can return the turtle to the starting position and speed up all the

6
00:25.470 --> 00:29.490
cars. So I'm going to do that right here,

7
00:29.850 --> 00:34.080
and I'm going to detect a successful crossing.

8
00:35.040 --> 00:39.630
So what is a successful crossing? Well, the player turtle has the reach

9
00:39.810 --> 00:41.130
the finish line, right?

10
00:41.430 --> 00:46.430
Which we've defined the Y value for as 280 here in the constant.

11
00:47.850 --> 00:49.710
Now you could do this in a number of ways.

12
00:50.100 --> 00:55.100
You could define a method here or simply just get hold of the player's position

13
00:55.830 --> 01:00.480
and then figure out if it's over 280 inside our main.py.

14
01:01.200 --> 01:03.870
Now I'm going to create a method here instead

15
01:04.500 --> 01:09.060
and I'm going to call the method is_at_finish_line.

16
01:10.680 --> 01:13.050
This method is going to return true

17
01:13.380 --> 01:17.160
if the turtle is at the finish line and false while it's not.

18
01:17.760 --> 01:19.980
So how do we detect this? Well,

19
01:19.980 --> 01:23.400
we can get our self.ycor

20
01:23.940 --> 01:28.650
and we can see if that is greater than 280,

21
01:28.920 --> 01:32.010
which is our finished line Y value.

22
01:32.370 --> 01:36.090
What that means we've pretty much gone over the finish line, right?

23
01:36.510 --> 01:39.570
So if this is the case, then we're going to return true.

24
01:39.930 --> 01:43.650
But while that's not the case, any other time when we check this,

25
01:43.890 --> 01:45.540
we're going to return false.

26
01:46.170 --> 01:49.200
So now coming back to our main.py,

27
01:49.530 --> 01:54.240
we can call our player.is_at_finish_line and we can say,

28
01:54.270 --> 01:57.660
if this is true, well in that case

29
01:58.050 --> 02:01.260
we're going to get the player to go back to the starting position.

30
02:01.920 --> 02:06.660
So inside our player class let's create yet another method which I'm going to

31
02:06.660 --> 02:09.060
call go_to_start.

32
02:09.900 --> 02:14.900
And this just involves getting our player to go to the starting position

33
02:17.430 --> 02:20.190
which we've defined here in a constant.

34
02:20.820 --> 02:23.640
So notice how we've got a little bit of repetition here,

35
02:23.640 --> 02:28.640
so we can actually delete this line and simply call self.

36
02:29.010 --> 02:32.460
go_to_start. Back in our main.py

37
02:32.520 --> 02:37.230
once the player is at the finish line, we're going to get the player to go

38
02:37.230 --> 02:41.640
to the stat.r And if we go ahead and run our code

39
02:41.700 --> 02:42.930
as it is right now,

40
02:43.200 --> 02:47.550
you can see that once the turtle makes it across the road,

41
02:47.630 --> 02:52.630
<v 1>[inaudible]</v>

42
02:56.930 --> 02:59.240
it goes back to the starting position.</v>

43
03:00.220 --> 03:05.220
Now the very last thing we need to do is to increase the speed of the cars when

44
03:06.310 --> 03:08.050
the player reaches the other side,

45
03:08.260 --> 03:11.380
because effectively they've just gone to the next level.

46
03:12.130 --> 03:17.130
What we can do is when the player reaches the finish line,

47
03:17.710 --> 03:21.970
we can get the car_manager to increase the speed of the cars.

48
03:22.420 --> 03:25.660
Let's create a method inside our CarManager class

49
03:25.690 --> 03:30.160
which we'll call level_up. And in this method,

50
03:30.280 --> 03:35.280
we're going to get the cars' speed to increase by 10 every time.

51
03:35.950 --> 03:40.950
So if we have an attribute called car_speed and we initially set it as the

52
03:43.510 --> 03:45.130
starting move distance,

53
03:45.730 --> 03:50.730
and then we use this car_speed to determine how far it should move backward

54
03:51.250 --> 03:53.950
each time. Well then when we level up,

55
03:53.980 --> 03:58.980
we can say self.car_speed now increases by the increment that we've defined

56
03:59.890 --> 04:02.560
here, which is the move increment.

57
04:03.760 --> 04:08.410
So now when our player reaches the other side at the finish line,

58
04:08.680 --> 04:11.320
then in addition to getting the player to go to the start,

59
04:11.590 --> 04:16.330
we're going to get the car_manager to level up our cars as well.

60
04:16.960 --> 04:21.010
So now when my turtle reaches the other side of the screen,

61
04:21.340 --> 04:24.550
not only does the turtle go back to the original position,

62
04:24.790 --> 04:27.280
but the cars also increase in speed.