1
00:00:00,170 --> 00:00:03,950
Welcome back, my fellow game developers.

2
00:00:03,945 --> 00:00:08,535
In this video, we are making the game so much cooler.

3
00:00:08,535 --> 00:00:12,335
So finally, this video makes everything look amazing.

4
00:00:12,330 --> 00:00:13,860
So we start off the game.

5
00:00:13,860 --> 00:00:15,020
We start running around,

6
00:00:15,015 --> 00:00:16,125
oh no, there is a door.

7
00:00:16,125 --> 00:00:16,985
It's closed.

8
00:00:16,980 --> 00:00:18,770
Oh, no. Let's go to the next door.

9
00:00:18,765 --> 00:00:20,505
Oh, no, it's close though.

10
00:00:20,505 --> 00:00:22,275
There are three enemies in here.

11
00:00:22,275 --> 00:00:24,735
Oh, they tried to shoot as they try to follow as nope,

12
00:00:24,735 --> 00:00:26,165
we kill the first one.

13
00:00:26,160 --> 00:00:30,230
Maybe he takes a lot of it's the second one. How many does it take?

14
00:00:30,230 --> 00:00:33,040
One hit his dies and his pleasure, blood.

15
00:00:33,035 --> 00:00:35,155
We call this one. We tried to kill the last one.

16
00:00:35,150 --> 00:00:37,160
We are shooting him as he shooting back.

17
00:00:37,160 --> 00:00:40,100
Nope, he's not. Wait, but Tim shu Okay, It's not shooting.

18
00:00:40,100 --> 00:00:43,280
So we should have, there are things flying in our direction.

19
00:00:43,280 --> 00:00:45,760
We should around him and he dies.

20
00:00:45,755 --> 00:00:46,405
Amazing.

21
00:00:46,400 --> 00:00:48,190
So there you go. The doors are open.

22
00:00:48,185 --> 00:00:52,195
We walked through and now we can go to the next level or we could

23
00:00:52,190 --> 00:00:56,650
use the other door because it also opens when we kill all of our enemies.

24
00:00:56,645 --> 00:00:58,825
So let's not waste any more time.

25
00:00:58,820 --> 00:01:00,730
We will fix this thing right here,

26
00:01:00,725 --> 00:01:03,005
seeing the blue things around us,

27
00:01:03,005 --> 00:01:05,635
and let's get started.

28
00:01:05,630 --> 00:01:07,550
Oh, case.

29
00:01:07,550 --> 00:01:13,100
So now it's time to open up the doors whenever the enemies are killed,

30
00:01:13,100 --> 00:01:16,070
let's go into the enemies right here or the room.

31
00:01:16,070 --> 00:01:17,900
Actually run the game.

32
00:01:17,900 --> 00:01:21,920
And I'm going to try to kill a couple of enemies that's opened up.

33
00:01:21,920 --> 00:01:22,760
There you go.

34
00:01:22,760 --> 00:01:24,740
Let's shoot the enemy right here.

35
00:01:24,740 --> 00:01:27,080
Three bullets should be enough, and he's dead.

36
00:01:27,080 --> 00:01:30,620
And you can see right here that he is now a missing.

37
00:01:30,620 --> 00:01:32,300
Very good. He is missing.

38
00:01:32,300 --> 00:01:33,880
The second one is missing.

39
00:01:33,875 --> 00:01:36,115
The third one is also missing,

40
00:01:36,110 --> 00:01:38,000
so we no longer have any enemies.

41
00:01:38,000 --> 00:01:40,010
The door should open.

42
00:01:40,010 --> 00:01:44,360
The only problem is that we still have these elements in here.

43
00:01:44,360 --> 00:01:46,940
But thankfully, when we're working with lists,

44
00:01:46,940 --> 00:01:51,290
we can actually remove the item very easily.

45
00:01:51,290 --> 00:01:53,200
So the way we do that,

46
00:01:53,195 --> 00:01:58,315
as we go into our updating here in the rooms manager update.

47
00:01:58,310 --> 00:02:01,790
And we are going to create another loop.

48
00:02:01,790 --> 00:02:05,390
And this time this loop is going to be a for loop.

49
00:02:05,390 --> 00:02:07,300
So what is a for loop?

50
00:02:07,295 --> 00:02:08,365
Let me explain.

51
00:02:08,360 --> 00:02:11,360
So what is a for loop?

52
00:02:11,360 --> 00:02:15,200
Loops can execute a block of code number.

53
00:02:15,200 --> 00:02:18,470
Times. Loops are handy if you want to run

54
00:02:18,470 --> 00:02:23,260
the same code over and over again each time with a different value.

55
00:02:23,255 --> 00:02:27,205
Now, I'm delving a bit deeper into loops than we did with the for each,

56
00:02:27,200 --> 00:02:32,060
but not worry for loops are similar to for-each loops.

57
00:02:32,060 --> 00:02:34,730
But this time instead of using the items,

58
00:02:34,730 --> 00:02:41,300
we use the indexes and side of the list or the array.

59
00:02:41,300 --> 00:02:44,800
So you can see that this continues to execute

60
00:02:44,795 --> 00:02:48,395
code inside until I reaches a certain limit.

61
00:02:48,395 --> 00:02:50,315
What does that mean?

62
00:02:50,315 --> 00:02:54,185
Let's look through this syntax right here and understand it better.

63
00:02:54,185 --> 00:02:57,265
We start off by writing for, That's good.

64
00:02:57,260 --> 00:03:00,830
We instantiate a variable which is an integer,

65
00:03:00,830 --> 00:03:03,940
most probably which is an I equals 0.

66
00:03:03,935 --> 00:03:06,245
We then add this semicolon.

67
00:03:06,245 --> 00:03:12,005
We then tell it what is the limit that the I will keep working towards.

68
00:03:12,005 --> 00:03:16,135
And then we stop and each time we add one to the eye.

69
00:03:16,130 --> 00:03:18,050
So you can see right here, this plus,

70
00:03:18,050 --> 00:03:20,770
plus means that it's I plus one.

71
00:03:20,765 --> 00:03:22,315
So we start off at 0,

72
00:03:22,310 --> 00:03:25,160
let's say the certain limit is three.

73
00:03:25,160 --> 00:03:31,630
We will continue looping through until I is no longer less than three.

74
00:03:31,625 --> 00:03:33,155
So we start off at 0,

75
00:03:33,155 --> 00:03:36,295
we do some stuff, we execute the code I plus, plus.

76
00:03:36,290 --> 00:03:38,230
That means I becomes one.

77
00:03:38,225 --> 00:03:40,055
It's still less than three.

78
00:03:40,055 --> 00:03:42,025
Great, we continue on.

79
00:03:42,020 --> 00:03:43,880
We have I plus two,

80
00:03:43,880 --> 00:03:45,370
as it's still less than three.

81
00:03:45,365 --> 00:03:46,885
It is, we continue.

82
00:03:46,880 --> 00:03:49,190
I equals three is it's still less than three.

83
00:03:49,190 --> 00:03:54,580
No, it's not because we need to be less than 3 or less than the certain limit.

84
00:03:54,575 --> 00:03:59,935
And we are going to be using that to see we are going to count through all the enemies.

85
00:03:59,930 --> 00:04:02,810
And when we are at the last enemy,

86
00:04:02,810 --> 00:04:06,710
we are going to go ahead and stop the loop.

87
00:04:06,710 --> 00:04:11,260
And at each level we are going to check if that enemy is an empty game object,

88
00:04:11,255 --> 00:04:14,435
then we are going to remove the entire item from the list.

89
00:04:14,435 --> 00:04:16,255
So let's get started.

90
00:04:16,250 --> 00:04:18,110
This will be a bit complicated,

91
00:04:18,110 --> 00:04:19,720
but bear with me.

92
00:04:19,715 --> 00:04:23,395
So I'm going to go ahead and create a for loop.

93
00:04:23,390 --> 00:04:27,350
And instead of going from the first element to the last element,

94
00:04:27,350 --> 00:04:29,300
I'm going to start at the back.

95
00:04:29,300 --> 00:04:37,970
So I'm going to have an int I equals enemies dot count minus1.

96
00:04:37,970 --> 00:04:39,650
First of all, what is the count?

97
00:04:39,650 --> 00:04:44,020
Enemies dot count is the number of items that we have in the list.

98
00:04:44,015 --> 00:04:47,155
And our case, this will be the three skeletons.

99
00:04:47,150 --> 00:04:49,100
Why am I adding minus one?

100
00:04:49,100 --> 00:04:53,600
Because lists work just as arrays do where we start,

101
00:04:53,600 --> 00:04:56,660
the counting of the indexed from 0.

102
00:04:56,660 --> 00:05:00,170
The last element of the three skeletons will be two.

103
00:05:00,170 --> 00:05:01,670
We have the skeleton zeros,

104
00:05:01,670 --> 00:05:03,520
skeleton one skeleton too.

105
00:05:03,515 --> 00:05:07,545
So count is equal to three because we have three skeletons.

106
00:05:07,549 --> 00:05:11,979
So the first element should be the count minus one.

107
00:05:11,975 --> 00:05:14,025
I hope that is understood.

108
00:05:14,029 --> 00:05:16,369
Now because we are starting from the back,

109
00:05:16,370 --> 00:05:17,720
what is our goal?

110
00:05:17,720 --> 00:05:19,730
We will keep looping through.

111
00:05:19,730 --> 00:05:24,530
While i is greater than minus one.

112
00:05:24,530 --> 00:05:27,010
Why is this minus1?

113
00:05:27,005 --> 00:05:29,485
Well, because when we get to 0,

114
00:05:29,480 --> 00:05:32,710
we still want to loop through the list.

115
00:05:32,705 --> 00:05:36,785
And one we get two minus one because let me just finish this off.

116
00:05:36,785 --> 00:05:37,375
There you go.

117
00:05:37,370 --> 00:05:38,800
Because we are going.

118
00:05:38,795 --> 00:05:40,195
Minus minus.

119
00:05:40,190 --> 00:05:41,810
So just like Plus,

120
00:05:41,810 --> 00:05:43,280
Plus adds a one,

121
00:05:43,280 --> 00:05:45,730
minus, minus removes a one.

122
00:05:45,725 --> 00:05:48,125
So again, what's happening?

123
00:05:48,125 --> 00:05:50,935
We are starting from the back of the list.

124
00:05:50,930 --> 00:05:56,210
We are making sure that we always are greater than minus one,

125
00:05:56,210 --> 00:06:00,670
which means we don't want to have 0 as the last element that we go through.

126
00:06:00,665 --> 00:06:04,765
And finally, we are adding I minus minus.

127
00:06:04,760 --> 00:06:06,820
So let's continue one.

128
00:06:06,815 --> 00:06:08,995
What are we going to do in here?

129
00:06:08,990 --> 00:06:13,430
Well, we are going to check if the enemies

130
00:06:13,429 --> 00:06:20,319
or the enemy at the position I is equal to null.

131
00:06:20,315 --> 00:06:23,005
So null means that he is missing.

132
00:06:23,000 --> 00:06:26,720
We saw previously in a previous video when we kill the skeletons,

133
00:06:26,719 --> 00:06:28,989
the element in there became missing.

134
00:06:28,985 --> 00:06:30,485
That means it's not.

135
00:06:30,485 --> 00:06:35,375
So if the enemy or the collider 2D is missing on this enemy,

136
00:06:35,375 --> 00:06:38,755
than what we're going to do is we're going to access the enemies.

137
00:06:38,750 --> 00:06:44,900
Dot remove at, and we're going to remove it at the position I.

138
00:06:44,900 --> 00:06:50,080
So again, let's just look at it one more time and understand what's happening.

139
00:06:50,075 --> 00:06:56,225
We are starting at the back of the line because we want to remove things from down to,

140
00:06:56,225 --> 00:06:58,165
up until we get to the first one.

141
00:06:58,160 --> 00:07:00,320
So we are starting from the back.

142
00:07:00,320 --> 00:07:05,740
We are using count minus one because count is the number of elements,

143
00:07:05,735 --> 00:07:09,175
but the elements inside are indexed from 0.

144
00:07:09,170 --> 00:07:11,380
So we start at 0, 1, 2,

145
00:07:11,375 --> 00:07:13,015
but the count is three,

146
00:07:13,010 --> 00:07:14,470
so we remove one.

147
00:07:14,465 --> 00:07:19,895
We keep removing one by using AI minus-minus until we

148
00:07:19,895 --> 00:07:25,145
are no longer greater than minus one y. I mean,

149
00:07:25,145 --> 00:07:27,655
when we are less than minus one, why?

150
00:07:27,650 --> 00:07:31,430
Because the last one is going to be 0, so minus1,

151
00:07:31,430 --> 00:07:32,870
when we become minus1,

152
00:07:32,870 --> 00:07:36,700
that means we've ended and we no longer want to continue on with the loop.

153
00:07:36,695 --> 00:07:42,185
And each time we find that the enemies is missing or is null,

154
00:07:42,185 --> 00:07:45,365
we are going to remove them from the list.

155
00:07:45,365 --> 00:07:47,905
Great, Let's save that.

156
00:07:47,900 --> 00:07:56,100
Let's go back into our game and let's go ahead and print out in here the enemies.

157
00:08:02,440 --> 00:08:06,600
Okay, So enemies.gov.

158
00:08:06,610 --> 00:08:09,160
And let's just see what happens.

159
00:08:09,155 --> 00:08:11,365
So back in our game,

160
00:08:11,360 --> 00:08:14,140
I'm going to run the gain.

161
00:08:14,135 --> 00:08:16,495
I have the list of enemies,

162
00:08:16,490 --> 00:08:18,250
I'm going to shoot first 1,

163
00:08:18,245 --> 00:08:20,135
second 1, and the third one.

164
00:08:20,135 --> 00:08:22,925
So let's wait for the books to appear.

165
00:08:22,925 --> 00:08:25,655
There you go. You can see a pop-up. Oh, okay.

166
00:08:25,655 --> 00:08:28,045
So now you can see that the list is empty.

167
00:08:28,040 --> 00:08:30,320
There's something I forgot to say.

168
00:08:30,320 --> 00:08:36,310
So we can see we have these and we didn't look at the Council even that may appear.

169
00:08:36,305 --> 00:08:39,145
So the number of enemies a three, when I shoot them,

170
00:08:39,140 --> 00:08:40,390
one of them dies,

171
00:08:40,385 --> 00:08:42,175
the last element is removed.

172
00:08:42,170 --> 00:08:44,840
That's why we are going from the bottom to the top.

173
00:08:44,840 --> 00:08:47,270
So the number of enemies is to 0.

174
00:08:47,270 --> 00:08:50,620
So the bullets that work for that kept going. Also.

175
00:08:50,615 --> 00:08:52,345
This one, there you go,

176
00:08:52,340 --> 00:08:57,370
The number of elements or the number of enemies is 0.

177
00:08:57,365 --> 00:09:00,835
Great. So now we know that we are able to kill the enemies.

178
00:09:00,830 --> 00:09:03,400
We are able to remove them from the list.

179
00:09:03,395 --> 00:09:08,845
Lastly, we want to open the door whenever the number of enemies 0,

180
00:09:08,840 --> 00:09:12,410
and that's going to be part of your challenge.

181
00:09:12,410 --> 00:09:16,060
Your challenge is to open the doors after the enemies die.

182
00:09:16,055 --> 00:09:19,345
So check to see that the enemies list is empty.

183
00:09:19,340 --> 00:09:21,250
This will be, I don't know,

184
00:09:21,245 --> 00:09:22,985
I will leave it to you.

185
00:09:22,985 --> 00:09:28,025
Then you'll need to go through all the doors and the doors to close.

186
00:09:28,025 --> 00:09:31,075
And you'll need to activate all of the doors.

187
00:09:31,070 --> 00:09:32,920
And I'll give you a small hint.

188
00:09:32,915 --> 00:09:34,895
You need to check the list length.

189
00:09:34,895 --> 00:09:37,175
You can use the dot count.

190
00:09:37,175 --> 00:09:38,495
Well, we've already done this.

191
00:09:38,495 --> 00:09:44,065
If you want. You can use a for each loop to go through the doors or you can try

192
00:09:44,060 --> 00:09:49,850
to use the for loop that we just learned and to get the length of the array,

193
00:09:49,850 --> 00:09:52,100
this is a good exercise in loops.

194
00:09:52,100 --> 00:09:54,070
We have a lot of loops. That's good.

195
00:09:54,065 --> 00:09:59,335
So pause the video right now and go do the challenge.

196
00:09:59,330 --> 00:10:01,640
Okay, welcome back.

197
00:10:01,640 --> 00:10:05,000
So I'm just going to keep the debugger right here.

198
00:10:05,000 --> 00:10:06,290
And what we're going to do,

199
00:10:06,290 --> 00:10:14,050
we're going to check if the enemies dot count is equal to 0.

200
00:10:14,045 --> 00:10:18,715
Then we are going to use the for loop.

201
00:10:18,710 --> 00:10:23,450
I'm going to create an int I equals 0.

202
00:10:23,450 --> 00:10:27,040
So we are starting from the 0.

203
00:10:27,035 --> 00:10:35,305
We are going to keep looping while I is less than the doors to open or sorry,

204
00:10:35,300 --> 00:10:37,730
doors to close dot length.

205
00:10:37,730 --> 00:10:40,190
When we want to access the length of an array,

206
00:10:40,190 --> 00:10:45,680
we use dot length when we want to access the length of the list, we use dot count.

207
00:10:45,680 --> 00:10:47,960
So there you go. Now you have two examples.

208
00:10:47,960 --> 00:10:51,940
You can even add a comment in here to make sure that you remember.

209
00:10:51,935 --> 00:10:55,025
And at each step we are going to add a one.

210
00:10:55,025 --> 00:11:01,015
So now door to close or actually door to close. Yes.

211
00:11:01,010 --> 00:11:05,420
And I'm going to access it using the I because I is increasing every time.

212
00:11:05,420 --> 00:11:07,840
So let's say we already have two doors.

213
00:11:07,835 --> 00:11:11,855
So we have index 0 and index one. We start off at 0.

214
00:11:11,855 --> 00:11:14,035
We get the door to close at 0.

215
00:11:14,030 --> 00:11:19,130
We set active to false.

216
00:11:19,125 --> 00:11:20,245
There we go.

217
00:11:20,245 --> 00:11:21,955
We will no longer have the door.

218
00:11:21,955 --> 00:11:23,695
We check is the I,

219
00:11:23,695 --> 00:11:28,585
which is currently 0, is less than the doors dot length, which is 2.

220
00:11:28,585 --> 00:11:31,035
So yes, 0 is less than 2.

221
00:11:31,030 --> 00:11:35,910
I plus, plus, or actually we do this and then I plus, plus.

222
00:11:35,905 --> 00:11:38,865
We go back here, I is, okay,

223
00:11:38,860 --> 00:11:42,910
so we no longer go back here I is now one is one less than two?

224
00:11:42,910 --> 00:11:43,800
Yes, it is.

225
00:11:43,795 --> 00:11:46,855
We have r equals to 0 dot-dot-dot active,

226
00:11:46,855 --> 00:11:48,715
sorry, I equals 1.

227
00:11:48,715 --> 00:11:50,215
We set active. There we go.

228
00:11:50,215 --> 00:11:50,775
It's false.

229
00:11:50,770 --> 00:11:52,440
Finally, I becomes two.

230
00:11:52,435 --> 00:11:53,605
Is two less than two?

231
00:11:53,605 --> 00:11:54,585
No, it's not. B.

232
00:11:54,580 --> 00:11:56,050
Go out of the loop.

233
00:11:56,050 --> 00:11:57,490
We save all of that.

234
00:11:57,490 --> 00:11:59,320
We go back into our game.

235
00:11:59,320 --> 00:12:01,670
We run the gain,

236
00:12:01,665 --> 00:12:04,135
we have the console right here,

237
00:12:04,130 --> 00:12:05,240
so the number of enemies,

238
00:12:05,240 --> 00:12:06,850
F3, you can see them.

239
00:12:06,845 --> 00:12:10,675
We should 12, okay,

240
00:12:10,670 --> 00:12:13,370
the enemies that we shoot him.

241
00:12:13,370 --> 00:12:15,910
Second one, how many bullets does take?

242
00:12:15,905 --> 00:12:19,975
One? It takes only one. Nice.

243
00:12:19,970 --> 00:12:21,370
Let's see why is he?

244
00:12:21,365 --> 00:12:23,965
Because I remember we added his life to be three.

245
00:12:23,960 --> 00:12:24,920
There you go.

246
00:12:24,920 --> 00:12:26,290
The enemy died.

247
00:12:26,285 --> 00:12:30,805
You can see that at 0 the doors open and we can walk through.

248
00:12:30,800 --> 00:12:32,120
How cool is that?

249
00:12:32,120 --> 00:12:35,330
So finally, everything seems to be working, okay.

250
00:12:35,330 --> 00:12:37,100
There are a couple of bugs.

251
00:12:37,100 --> 00:12:40,550
One of them is the blood is not disappearing because of the animations.

252
00:12:40,550 --> 00:12:43,090
We haven't still added the key at the end.

253
00:12:43,085 --> 00:12:44,635
The skeleton right here.

254
00:12:44,630 --> 00:12:46,400
How big is his life?

255
00:12:46,400 --> 00:12:48,650
The enemies house is three,

256
00:12:48,650 --> 00:12:50,330
so there seems to be a problem.

257
00:12:50,330 --> 00:12:52,510
He is dying immediately. Why?

258
00:12:52,505 --> 00:12:57,365
Because if we go into the layer bullet controller,

259
00:12:57,365 --> 00:13:01,495
the damage amount is 100 k.

260
00:13:01,490 --> 00:13:03,330
So the damage amount is standardized.

261
00:13:03,325 --> 00:13:05,585
Life of the enemies is 3.

262
00:13:05,585 --> 00:13:06,805
Think that's the problem.

263
00:13:06,800 --> 00:13:10,280
So let me make the half of this guy.

264
00:13:10,280 --> 00:13:12,230
So I just want to make sure that we are

265
00:13:12,230 --> 00:13:15,980
not having something wrong save that run the game.

266
00:13:15,980 --> 00:13:20,330
Because sometimes we might call a method too many times so we are giving too much damage.

267
00:13:20,330 --> 00:13:23,020
So if I check, okay, so there you go.

268
00:13:23,015 --> 00:13:25,055
He needs several bullets.

269
00:13:25,055 --> 00:13:27,775
123 and there you go.

270
00:13:27,770 --> 00:13:29,600
Okay, so everything is working fine.

271
00:13:29,600 --> 00:13:33,740
The doors are opening whenever we are killing all the enemies,

272
00:13:33,740 --> 00:13:35,590
everything seems to be working.

273
00:13:35,585 --> 00:13:38,125
We've learned a lot about loops in this section,

274
00:13:38,120 --> 00:13:40,390
we've learned actually a lot of information.

275
00:13:40,385 --> 00:13:41,765
I hope you're enjoying.

276
00:13:41,765 --> 00:13:43,255
I hope you're having fun.

277
00:13:43,250 --> 00:13:44,680
I hope you're learning a lot.

278
00:13:44,675 --> 00:13:46,045
I hope you are doing your research.

279
00:13:46,040 --> 00:13:48,740
I hope you are always committing your changes.

280
00:13:48,739 --> 00:13:54,279
I hope your game developer brains are getting stronger with each and every single video.

281
00:13:54,275 --> 00:13:56,435
I hope you are not very frustrated,

282
00:13:56,435 --> 00:13:59,285
and I hope you are very happy.

283
00:13:59,285 --> 00:14:02,225
So I'll see you in the next section.

284
00:14:02,225 --> 00:14:04,825
Don't forget to add a review.

