1
00:00:00,150 --> 00:00:01,080
In the last step,

2
00:00:01,110 --> 00:00:06,110
we figured out how to detect when the player turtle hits a car and to stop the

3
00:00:06,150 --> 00:00:08,850
while loop which stops the game at that point.

4
00:00:09,870 --> 00:00:14,220
Now we're going to figure out how we can detect when the turtle reaches the

5
00:00:14,220 --> 00:00:19,220
other side of the screen so that once our turtle makes a successful crossing,

6
00:00:20,790 --> 00:00:25,470
then we can return the turtle to the starting position and speed up all the

7
00:00:25,470 --> 00:00:29,490
cars. So I'm going to do that right here,

8
00:00:29,850 --> 00:00:34,080
and I'm going to detect a successful crossing.

9
00:00:35,040 --> 00:00:39,630
So what is a successful crossing? Well, the player turtle has the reach

10
00:00:39,810 --> 00:00:41,130
the finish line, right?

11
00:00:41,430 --> 00:00:46,430
Which we've defined the Y value for as 280 here in the constant.

12
00:00:47,850 --> 00:00:49,710
Now you could do this in a number of ways.

13
00:00:50,100 --> 00:00:55,100
You could define a method here or simply just get hold of the player's position

14
00:00:55,830 --> 00:01:00,480
and then figure out if it's over 280 inside our main.py.

15
00:01:01,200 --> 00:01:03,870
Now I'm going to create a method here instead

16
00:01:04,500 --> 00:01:09,060
and I'm going to call the method is_at_finish_line.

17
00:01:10,680 --> 00:01:13,050
This method is going to return true

18
00:01:13,380 --> 00:01:17,160
if the turtle is at the finish line and false while it's not.

19
00:01:17,760 --> 00:01:19,980
So how do we detect this? Well,

20
00:01:19,980 --> 00:01:23,400
we can get our self.ycor

21
00:01:23,940 --> 00:01:28,650
and we can see if that is greater than 280,

22
00:01:28,920 --> 00:01:32,010
which is our finished line Y value.

23
00:01:32,370 --> 00:01:36,090
What that means we've pretty much gone over the finish line, right?

24
00:01:36,510 --> 00:01:39,570
So if this is the case, then we're going to return true.

25
00:01:39,930 --> 00:01:43,650
But while that's not the case, any other time when we check this,

26
00:01:43,890 --> 00:01:45,540
we're going to return false.

27
00:01:46,170 --> 00:01:49,200
So now coming back to our main.py,

28
00:01:49,530 --> 00:01:54,240
we can call our player.is_at_finish_line and we can say,

29
00:01:54,270 --> 00:01:57,660
if this is true, well in that case

30
00:01:58,050 --> 00:02:01,260
we're going to get the player to go back to the starting position.

31
00:02:01,920 --> 00:02:06,660
So inside our player class let's create yet another method which I'm going to

32
00:02:06,660 --> 00:02:09,060
call go_to_start.

33
00:02:09,900 --> 00:02:14,900
And this just involves getting our player to go to the starting position

34
00:02:17,430 --> 00:02:20,190
which we've defined here in a constant.

35
00:02:20,820 --> 00:02:23,640
So notice how we've got a little bit of repetition here,

36
00:02:23,640 --> 00:02:28,640
so we can actually delete this line and simply call self.

37
00:02:29,010 --> 00:02:32,460
go_to_start. Back in our main.py

38
00:02:32,520 --> 00:02:37,230
once the player is at the finish line, we're going to get the player to go

39
00:02:37,230 --> 00:02:41,640
to the stat.r And if we go ahead and run our code

40
00:02:41,700 --> 00:02:42,930
as it is right now,

41
00:02:43,200 --> 00:02:47,550
you can see that once the turtle makes it across the road,

42
00:02:47,630 --> 00:02:52,630
[inaudible]

43
00:02:56,930 --> 00:02:59,240
it goes back to the starting position.

44
00:03:00,220 --> 00:03:05,220
Now the very last thing we need to do is to increase the speed of the cars when

45
00:03:06,310 --> 00:03:08,050
the player reaches the other side,

46
00:03:08,260 --> 00:03:11,380
because effectively they've just gone to the next level.

47
00:03:12,130 --> 00:03:17,130
What we can do is when the player reaches the finish line,

48
00:03:17,710 --> 00:03:21,970
we can get the car_manager to increase the speed of the cars.

49
00:03:22,420 --> 00:03:25,660
Let's create a method inside our CarManager class

50
00:03:25,690 --> 00:03:30,160
which we'll call level_up. And in this method,

51
00:03:30,280 --> 00:03:35,280
we're going to get the cars' speed to increase by 10 every time.

52
00:03:35,950 --> 00:03:40,950
So if we have an attribute called car_speed and we initially set it as the

53
00:03:43,510 --> 00:03:45,130
starting move distance,

54
00:03:45,730 --> 00:03:50,730
and then we use this car_speed to determine how far it should move backward

55
00:03:51,250 --> 00:03:53,950
each time. Well then when we level up,

56
00:03:53,980 --> 00:03:58,980
we can say self.car_speed now increases by the increment that we've defined

57
00:03:59,890 --> 00:04:02,560
here, which is the move increment.

58
00:04:03,760 --> 00:04:08,410
So now when our player reaches the other side at the finish line,

59
00:04:08,680 --> 00:04:11,320
then in addition to getting the player to go to the start,

60
00:04:11,590 --> 00:04:16,329
we're going to get the car_manager to level up our cars as well.

61
00:04:16,959 --> 00:04:21,010
So now when my turtle reaches the other side of the screen,

62
00:04:21,339 --> 00:04:24,550
not only does the turtle go back to the original position,

63
00:04:24,790 --> 00:04:27,280
but the cars also increase in speed.

