1
00:00:01,005 --> 00:00:02,006
- Hi.

2
00:00:02,006 --> 00:00:05,009
Welcome to Structuring
the Thomas Was Late Code.

3
00:00:05,009 --> 00:00:07,000
In the previous video,

4
00:00:07,000 --> 00:00:10,005
we looked at Thomas Was Late Game.

5
00:00:10,005 --> 00:00:12,003
In this video, we're going to improve

6
00:00:12,003 --> 00:00:14,007
the manageability of
the code in this project

7
00:00:14,007 --> 00:00:17,008
with the help of Engine class.

8
00:00:17,008 --> 00:00:20,001
One of the problems that
has been quite pronounced

9
00:00:20,001 --> 00:00:21,008
in both projects so far

10
00:00:21,008 --> 00:00:25,003
is how long and unwieldy the code gets.

11
00:00:25,003 --> 00:00:28,001
OOP allows us to break our projects up

12
00:00:28,001 --> 00:00:32,001
into logical and manageable
chunks called classes.

13
00:00:32,001 --> 00:00:33,002
We will make a big improvement

14
00:00:33,002 --> 00:00:35,004
to the manageability of
the code in this project

15
00:00:35,004 --> 00:00:38,000
with the introduction of an engine class.

16
00:00:38,000 --> 00:00:40,002
Among other functions, the engine class

17
00:00:40,002 --> 00:00:42,005
will have three private functions.

18
00:00:42,005 --> 00:00:45,007
They are input, update and draw.

19
00:00:45,007 --> 00:00:48,002
This should sound very familiar.

20
00:00:48,002 --> 00:00:49,004
Each of these functions

21
00:00:49,004 --> 00:00:50,009
will hold a chunk of the code

22
00:00:50,009 --> 00:00:54,000
that was previously all
in the main function.

23
00:00:54,000 --> 00:00:57,001
Each of these functions will
be in a code file of its own.

24
00:00:57,001 --> 00:01:03,005
Input.cpp, Update.cpp and
Draw.cpp respectively.

25
00:01:03,005 --> 00:01:06,007
There will also be one public
function in the Engine class,

26
00:01:06,007 --> 00:01:09,007
which can be called with
an instance of Engine.

27
00:01:09,007 --> 00:01:11,009
This function is run
and will be responsible

28
00:01:11,009 --> 00:01:14,009
for calling Input, Update and Draw

29
00:01:14,009 --> 00:01:17,006
once for each frame of the game.

30
00:01:17,006 --> 00:01:19,006
Furthermore, because we have abstracted

31
00:01:19,006 --> 00:01:21,002
the major parts of the game engine

32
00:01:21,002 --> 00:01:22,007
to the engine class,

33
00:01:22,007 --> 00:01:25,001
we can also move many of
the variables from Main

34
00:01:25,001 --> 00:01:27,008
and make them members of Engine.

35
00:01:27,008 --> 00:01:30,008
All we need to do to get
our game engine fired up

36
00:01:30,008 --> 00:01:32,007
is create an instance of Engine

37
00:01:32,007 --> 00:01:34,008
and call its Run function.

38
00:01:34,008 --> 00:01:38,005
Here's a sneak preview of the
super-simple Main function.

39
00:01:38,005 --> 00:01:40,005
Don't add this code just yet.

40
00:01:40,005 --> 00:01:43,008
To make our code even more
manageable and readable,

41
00:01:43,008 --> 00:01:46,008
we will also abstract
responsibility for big tasks,

42
00:01:46,008 --> 00:01:49,004
such as loading a level
and collision detection

43
00:01:49,004 --> 00:01:52,005
to separate functions
in separate code files.

44
00:01:52,005 --> 00:01:56,004
These two functions are
loadLevel and detectCollisions.

45
00:01:56,004 --> 00:01:58,000
We will also code other functions

46
00:01:58,000 --> 00:01:59,005
to handle some of the new features

47
00:01:59,005 --> 00:02:01,008
of the Thomas Was Late project.

48
00:02:01,008 --> 00:02:04,008
We will cover them in detail
as and when they occur.

49
00:02:04,008 --> 00:02:06,008
To further take advantage of OOP,

50
00:02:06,008 --> 00:02:09,004
we will delegate responsibility
for particular areas

51
00:02:09,004 --> 00:02:11,008
of the game entirely to new classes.

52
00:02:11,008 --> 00:02:14,004
You probably remember that
the sound and HUD code

53
00:02:14,004 --> 00:02:17,000
was quite lengthy in previous projects.

54
00:02:17,000 --> 00:02:19,005
We will build a sound
manager and HUD class

55
00:02:19,005 --> 00:02:22,004
to handle these aspects
in a cleaner manner.

56
00:02:22,004 --> 00:02:24,009
Exactly how they work
will be explored in depth

57
00:02:24,009 --> 00:02:26,006
when we implement them.

58
00:02:26,006 --> 00:02:29,001
The game levels themselves
are much more in-depth

59
00:02:29,001 --> 00:02:30,004
than previous games,

60
00:02:30,004 --> 00:02:33,005
so we'll also code a level manager class.

61
00:02:33,005 --> 00:02:35,007
As you would expect,
the playable characters

62
00:02:35,007 --> 00:02:38,001
will be made with classes as well.

63
00:02:38,001 --> 00:02:39,004
For this project, however,

64
00:02:39,004 --> 00:02:41,009
we will learn some more C++ and implement

65
00:02:41,009 --> 00:02:43,004
a playable character class

66
00:02:43,004 --> 00:02:46,006
with all the common
functionality of Thomas and Bob

67
00:02:46,006 --> 00:02:48,005
and then Thomas and Bob classes,

68
00:02:48,005 --> 00:02:50,007
which will inherit this
common functionality

69
00:02:50,007 --> 00:02:52,009
as well as implement
their own unique functions

70
00:02:52,009 --> 00:02:54,003
and abilities.

71
00:02:54,003 --> 00:02:58,001
This perhaps unsurprisingly
is called inheritance.

72
00:02:58,001 --> 00:02:59,008
I will go into more
detail about inheritance

73
00:02:59,008 --> 00:03:01,006
in the next section.

74
00:03:01,006 --> 00:03:03,009
We will also implement a
number of other classes

75
00:03:03,009 --> 00:03:06,003
to perform specific responsibilities.

76
00:03:06,003 --> 00:03:08,006
For example, we'll make
some neat explosions

77
00:03:08,006 --> 00:03:10,005
using particle systems.

78
00:03:10,005 --> 00:03:12,006
You might also be able
to guess that to do this,

79
00:03:12,006 --> 00:03:16,005
we will code a Particle class
and a ParticleSystem class.

80
00:03:16,005 --> 00:03:18,004
All these classes will have instances

81
00:03:18,004 --> 00:03:20,004
that are members of the Engine class.

82
00:03:20,004 --> 00:03:21,008
Doing things this way

83
00:03:21,008 --> 00:03:23,008
will make all the features
of the game accessible

84
00:03:23,008 --> 00:03:26,004
from the game engine, but
encapsulate the details

85
00:03:26,004 --> 00:03:28,007
into appropriate classes.

86
00:03:28,007 --> 00:03:30,008
The last thing to
mention before we move on

87
00:03:30,008 --> 00:03:33,004
to see the actual code that
will make the Engine class

88
00:03:33,004 --> 00:03:36,005
is that we will reuse without
any changes whatsoever

89
00:03:36,005 --> 00:03:38,009
the texture holder
class, which we discussed

90
00:03:38,009 --> 00:03:42,001
and coded for the Zombie Arena game.

91
00:03:42,001 --> 00:03:43,000
Cool!

92
00:03:43,000 --> 00:03:44,003
In this video, we learned

93
00:03:44,003 --> 00:03:47,000
structuring the Thomas Was Late code.

94
00:03:47,000 --> 00:03:50,002
Next up, we'll see
building the game engine.

