WEBVTT

0
00:00.510 --> 00:04.010
Hey guys, welcome to Day 20 of 100

1
00:04.010 --> 00:05.560
<v 1>Days of Code. Today</v>

2
00:05.680 --> 00:09.200
<v 0>is really exciting because we're going to be using the knowledge that we've</v>

3
00:09.200 --> 00:11.630
gained about Object Oriented Programming

4
00:11.990 --> 00:16.370
as well as what we learned about how to use the turtle module to build the

5
00:16.370 --> 00:18.830
famous snake game. Now,

6
00:18.830 --> 00:22.430
this is probably one of the most famous mobile games that ever was,

7
00:22.490 --> 00:27.490
and it's definitely one of my favorite. And my history with it goes back all the

8
00:28.760 --> 00:32.390
way to my very first mobile phone,

9
00:32.420 --> 00:37.280
the Nokia 3310. It might be showing my age a little bit here,

10
00:37.340 --> 00:40.580
but this was my first ever mobile phone.

11
00:40.890 --> 00:45.830
I remember loving it so much that I actually had it next to my pillow when I

12
00:45.830 --> 00:50.180
went to sleep. And this was probably one of the first affordable mobile phones.

13
00:50.270 --> 00:55.270
And it was endlessly customizable with different cases and different keys.

14
00:56.360 --> 00:58.640
But the most exciting thing about it

15
00:58.880 --> 01:01.090
was the snake game. I would compare

16
01:01.190 --> 01:04.490
with my friends and see who got the highest score in snake

17
01:04.730 --> 01:09.590
and we would spend days and days playing this game. And compared to the iPhone

18
01:09.590 --> 01:14.060
games of today, of course, this was very, very simple, but nonetheless,

19
01:14.060 --> 01:17.990
it is still super addictive. Over the next two days

20
01:18.110 --> 01:22.700
this is the game that we're going to build. A snake game that has,

21
01:22.760 --> 01:26.180
um, a moving snake, which you control using your keyboard,

22
01:26.630 --> 01:29.030
and you can go and get food,

23
01:29.300 --> 01:31.910
and then it grows in length as it eats more food.

24
01:32.240 --> 01:35.480
And you have to make sure that you don't end up getting tangled or hitting the

25
01:35.480 --> 01:36.170
wall.

26
01:36.170 --> 01:40.940
And the goal is to eat as much food as you can while staying alive.

27
01:41.600 --> 01:45.350
There are some people who are truly masters at this game, um,

28
01:45.410 --> 01:47.420
which I personally am not,

29
01:47.780 --> 01:52.430
but they managed to get their snakes to crazy lengths and start having these

30
01:52.430 --> 01:57.430
strategies for how you can avoid hitting your tail and how you can keep going.

31
01:58.100 --> 02:01.400
So once you've built your snake game, you'll be able to play with it,

32
02:01.550 --> 02:04.700
and you'll be able to show off your high scores to the rest of us,

33
02:04.910 --> 02:07.310
but I'm sure you're going to do a lot better than me.

34
02:07.700 --> 02:10.850
It's not that hard to beat me at snake. As always,

35
02:10.850 --> 02:13.040
when we're thinking about a complex problem

36
02:13.070 --> 02:16.340
the first step is to break down the problem.

37
02:16.940 --> 02:21.940
And I'm going to break down this problem of building the snake game into seven

38
02:22.040 --> 02:23.150
separate steps.

39
02:23.420 --> 02:26.660
And the way we're going to do it is we're going to tackle the first three steps

40
02:26.660 --> 02:30.470
on Day 1 and the last four steps on Day 2.

41
02:30.950 --> 02:34.730
So we're going to split up this game into two parts and we're going to tackle it

42
02:34.760 --> 02:39.680
over two days. The first step is to create a snake body,

43
02:40.070 --> 02:43.880
and we're going to do that by creating three squares on the screen,

44
02:44.270 --> 02:45.950
all lined up next to each other.

45
02:46.760 --> 02:51.290
And then we're going to figure out how to move the snake so that it continuously

46
02:51.290 --> 02:52.250
moves forward

47
02:52.460 --> 02:57.170
and all we have to do is tell it to change direction. Afterwards,

48
02:57.230 --> 03:01.300
we're going to figure out how to control the snake using keyboard controls.

49
03:01.570 --> 03:06.570
So we're going to be using the up, left, down, and right arrow keys to move our

50
03:07.240 --> 03:08.680
snake across the screen.

51
03:09.070 --> 03:12.520
And that is what we're aiming for by the end of today,

52
03:12.520 --> 03:14.920
Day 20. On Day 21,

53
03:15.070 --> 03:18.340
we're going to continue and we're going to build out the last four steps of the

54
03:18.340 --> 03:19.173
snake game.

55
03:19.630 --> 03:24.100
Then we'll need to start putting some food onto the screen and started to detect

56
03:24.100 --> 03:28.210
the collision with the food so that once the snake hits the food,

57
03:28.450 --> 03:33.400
then a new piece of food gets created randomly on the screen at some sort of

58
03:33.520 --> 03:34.570
random location.

59
03:35.410 --> 03:40.240
And then it's a matter of keeping track of the score and creating a scoreboard.

60
03:40.510 --> 03:45.430
So we're going to learn how to write text in our program so that once the snake

61
03:45.430 --> 03:48.970
hits a piece of food, the score automatically updates.

62
03:49.480 --> 03:52.870
And then next we're going to figure out when the game should end.

63
03:53.020 --> 03:58.020
So one of the cases when the game should end is when the snake has collided with

64
03:58.480 --> 04:02.470
the wall. And at this point we should see game over,

65
04:02.470 --> 04:06.430
show up on screen and the snake should no longer move.

66
04:06.910 --> 04:08.140
And then finally,

67
04:08.200 --> 04:12.880
the other reason why our game could end is when the snake has collided with its

68
04:12.880 --> 04:17.470
own tail. So the snake basically can't chase his own tail.

69
04:17.740 --> 04:21.610
And as the snake gets longer, this problem is more likely to occur.

70
04:22.060 --> 04:26.500
And when their head hits any part of the body of the snake, then it's again,

71
04:26.560 --> 04:29.860
game over. So these are the seven steps

72
04:29.890 --> 04:32.040
that it takes to create the snake game.

73
04:32.670 --> 04:37.440
<v 0>And once you're ready, we're gonna get started with step one on the next lesson.</v>

74
04:37.650 --> 04:38.340
So I'll see you there.