﻿1
00:00:03,280 --> 00:00:06,240
hello everyone

2
00:00:04,240 --> 00:00:07,919
this is part two on how to make a tower

3
00:00:06,240 --> 00:00:09,760
defense game in scratch

4
00:00:07,919 --> 00:00:11,759
in this tutorial i will be setting up

5
00:00:09,760 --> 00:00:13,280
the enemy lists which will be used for

6
00:00:11,759 --> 00:00:15,200
tower aiming and shooting

7
00:00:13,280 --> 00:00:16,880
and i will also begin making our first

8
00:00:15,200 --> 00:00:17,600
tower that we will be able to place on

9
00:00:16,880 --> 00:00:19,439
the map

10
00:00:17,600 --> 00:00:21,680
if you haven't seen part one check it

11
00:00:19,439 --> 00:00:23,439
out link is in the description below

12
00:00:21,680 --> 00:00:25,359
and before we start we will be doing

13
00:00:23,439 --> 00:00:27,119
some code which involves lists

14
00:00:25,359 --> 00:00:28,400
but i won't be going into too much

15
00:00:27,119 --> 00:00:29,920
detail about them right now

16
00:00:28,400 --> 00:00:31,599
because they'll be used in the next

17
00:00:29,920 --> 00:00:34,000
video anyways

18
00:00:31,599 --> 00:00:35,200
let's get started so first off before we

19
00:00:34,000 --> 00:00:37,120
start creating the turrets

20
00:00:35,200 --> 00:00:39,760
we have to first add some lists to the

21
00:00:37,120 --> 00:00:43,120
enemies so let's go to variables

22
00:00:39,760 --> 00:00:46,239
and then i'm going to make a list

23
00:00:43,120 --> 00:00:48,320
and i'll call the first one um enemyx

24
00:00:46,239 --> 00:00:49,920
all right and then keep it for all

25
00:00:48,320 --> 00:00:52,879
sprites

26
00:00:49,920 --> 00:00:55,760
and i'll create another list and then i

27
00:00:52,879 --> 00:00:59,120
will call this enemy y

28
00:00:55,760 --> 00:01:02,480
okay and then i'll create another list

29
00:00:59,120 --> 00:01:05,600
and call it enemy progress

30
00:01:02,480 --> 00:01:08,640
and i'll create one more and call this

31
00:01:05,600 --> 00:01:10,640
enemy ids okay

32
00:01:08,640 --> 00:01:12,799
so the reason i'm creating these lists

33
00:01:10,640 --> 00:01:14,640
is because i need a way to track

34
00:01:12,799 --> 00:01:16,159
all of the enemies on the screen and

35
00:01:14,640 --> 00:01:16,720
this is so that the towers that i will

36
00:01:16,159 --> 00:01:18,960
create

37
00:01:16,720 --> 00:01:21,280
will know which enemy to target so of

38
00:01:18,960 --> 00:01:24,000
course the enemy x and enemy y lists

39
00:01:21,280 --> 00:01:25,840
will track the enemy x and y positions

40
00:01:24,000 --> 00:01:27,439
and then the enemy progress list will

41
00:01:25,840 --> 00:01:28,799
track the distance each clone has

42
00:01:27,439 --> 00:01:31,520
traveled on the track

43
00:01:28,799 --> 00:01:32,880
and the enemy id list will just have all

44
00:01:31,520 --> 00:01:36,079
of the clone numbers

45
00:01:32,880 --> 00:01:40,320
so i'm going to hide all of these lists

46
00:01:36,079 --> 00:01:43,280
okay and then under the windfly clicked

47
00:01:40,320 --> 00:01:44,960
i am going to drag a delete all and

48
00:01:43,280 --> 00:01:48,479
change this to delete all

49
00:01:44,960 --> 00:01:50,079
of enemy x and then also delete all of

50
00:01:48,479 --> 00:01:53,439
enemy y

51
00:01:50,079 --> 00:01:55,200
delete all of enemy progress and delete

52
00:01:53,439 --> 00:01:56,960
all of enemy ids

53
00:01:55,200 --> 00:02:00,000
and then i'm going to put this right

54
00:01:56,960 --> 00:02:02,000
after the hide

55
00:02:00,000 --> 00:02:04,320
okay so this just makes sure that all of

56
00:02:02,000 --> 00:02:06,640
the lists are empty when the game starts

57
00:02:04,320 --> 00:02:08,239
so now let's create a new variable and

58
00:02:06,640 --> 00:02:11,520
then i will call this um

59
00:02:08,239 --> 00:02:13,120
something like clone number okay

60
00:02:11,520 --> 00:02:15,040
and then for this one make sure to

61
00:02:13,120 --> 00:02:17,040
select for the sprite only

62
00:02:15,040 --> 00:02:19,440
and this is because each clone will have

63
00:02:17,040 --> 00:02:21,520
a separate value for this clone number

64
00:02:19,440 --> 00:02:23,360
so select for the sprite only and then

65
00:02:21,520 --> 00:02:25,760
click ok

66
00:02:23,360 --> 00:02:26,480
all right and this clone number variable

67
00:02:25,760 --> 00:02:28,720
will track

68
00:02:26,480 --> 00:02:29,840
which clone is which inside of all of

69
00:02:28,720 --> 00:02:31,920
these lists

70
00:02:29,840 --> 00:02:34,959
so when the flag is clicked let's set

71
00:02:31,920 --> 00:02:37,120
clone number to zero

72
00:02:34,959 --> 00:02:39,360
and then inside of this repeat loop

73
00:02:37,120 --> 00:02:40,560
let's change clone number by one

74
00:02:39,360 --> 00:02:43,040
and then i'm going to put this right

75
00:02:40,560 --> 00:02:44,959
before the create clone myself

76
00:02:43,040 --> 00:02:46,640
and now each clone that is created

77
00:02:44,959 --> 00:02:47,680
should have a different value for this

78
00:02:46,640 --> 00:02:50,480
clone number variable

79
00:02:47,680 --> 00:02:51,120
from 1 to 10. so now when a clone is

80
00:02:50,480 --> 00:02:53,840
created

81
00:02:51,120 --> 00:02:55,120
i'm going to add a item to the four list

82
00:02:53,840 --> 00:02:58,560
that we created

83
00:02:55,120 --> 00:03:01,360
so inside of the lists let's drag a

84
00:02:58,560 --> 00:03:02,840
add and then i'm going to change this to

85
00:03:01,360 --> 00:03:05,840
add

86
00:03:02,840 --> 00:03:08,480
um nothing to enemy x

87
00:03:05,840 --> 00:03:10,319
and this just adds an empty new item

88
00:03:08,480 --> 00:03:13,519
into the enemy x list

89
00:03:10,319 --> 00:03:16,080
and then i'm going to duplicate this

90
00:03:13,519 --> 00:03:18,480
and then also add an empty item to the

91
00:03:16,080 --> 00:03:21,760
enemy y list

92
00:03:18,480 --> 00:03:22,640
and then for the enemy progress i am

93
00:03:21,760 --> 00:03:27,920
going to add

94
00:03:22,640 --> 00:03:30,720
0 for that and lastly for the enemy ids

95
00:03:27,920 --> 00:03:32,720
i am going to add the clone number

96
00:03:30,720 --> 00:03:34,239
alright so each enemy that is created

97
00:03:32,720 --> 00:03:36,400
will have their own enemy x

98
00:03:34,239 --> 00:03:37,280
enemy y and enemy progress which they

99
00:03:36,400 --> 00:03:40,400
will change

100
00:03:37,280 --> 00:03:42,159
as well as their own enemy id alright

101
00:03:40,400 --> 00:03:44,319
so i'm going to drag this under the

102
00:03:42,159 --> 00:03:46,959
winnestar as a clone

103
00:03:44,319 --> 00:03:48,000
and now each enemy will update these

104
00:03:46,959 --> 00:03:49,680
three lists

105
00:03:48,000 --> 00:03:52,080
and by the way this might seem a bit

106
00:03:49,680 --> 00:03:53,120
confusing but it'll make more sense once

107
00:03:52,080 --> 00:03:56,159
i create the turrets

108
00:03:53,120 --> 00:03:58,400
which will use these lists so inside of

109
00:03:56,159 --> 00:04:01,280
the enemy movement block

110
00:03:58,400 --> 00:04:02,080
i'm going to grab a replace item 1 of

111
00:04:01,280 --> 00:04:04,159
block

112
00:04:02,080 --> 00:04:07,360
okay and then i'm going to drag this

113
00:04:04,159 --> 00:04:09,920
under the enemy movement custom block

114
00:04:07,360 --> 00:04:10,959
and then for this i'm going to replace

115
00:04:09,920 --> 00:04:14,319
the clone number

116
00:04:10,959 --> 00:04:17,519
so replace item clone number of enemy

117
00:04:14,319 --> 00:04:20,880
x with go to motion

118
00:04:17,519 --> 00:04:22,560
the enemy x position okay

119
00:04:20,880 --> 00:04:25,040
so and then i'm going to right click

120
00:04:22,560 --> 00:04:27,520
duplicate this block

121
00:04:25,040 --> 00:04:29,759
and instead of enemy x i'm going to

122
00:04:27,520 --> 00:04:31,759
change this to enemy y

123
00:04:29,759 --> 00:04:34,880
and of course i am going to replace that

124
00:04:31,759 --> 00:04:37,919
with the y position

125
00:04:34,880 --> 00:04:40,720
and then lastly for the enemy progress i

126
00:04:37,919 --> 00:04:43,520
am going to duplicate this again

127
00:04:40,720 --> 00:04:44,560
and change this to enemy progress and

128
00:04:43,520 --> 00:04:46,320
then for this

129
00:04:44,560 --> 00:04:47,759
sense this is going to show how far the

130
00:04:46,320 --> 00:04:50,479
enemy has moved

131
00:04:47,759 --> 00:04:52,800
i am going to actually go to variables

132
00:04:50,479 --> 00:04:55,840
and then go to the lists

133
00:04:52,800 --> 00:04:59,120
and then i am going to grab a item one

134
00:04:55,840 --> 00:05:01,759
of enemy id's block and then i'm going

135
00:04:59,120 --> 00:05:04,240
to change this to enemy progress

136
00:05:01,759 --> 00:05:05,199
and inside of this right here i'm going

137
00:05:04,240 --> 00:05:08,000
to drag

138
00:05:05,199 --> 00:05:10,639
a clone number variable and then i'm

139
00:05:08,000 --> 00:05:12,080
going to go to operators drag a plus

140
00:05:10,639 --> 00:05:14,160
operator

141
00:05:12,080 --> 00:05:15,440
all right and then drag this on the left

142
00:05:14,160 --> 00:05:18,479
side

143
00:05:15,440 --> 00:05:21,360
and then i'm going to add the move speed

144
00:05:18,479 --> 00:05:23,280
on the right side alright so pretty much

145
00:05:21,360 --> 00:05:25,199
what this does is that when the enemy

146
00:05:23,280 --> 00:05:27,680
moves five steps

147
00:05:25,199 --> 00:05:29,120
then the enemy progress will increase by

148
00:05:27,680 --> 00:05:31,520
five

149
00:05:29,120 --> 00:05:33,680
okay so now i am going to put this

150
00:05:31,520 --> 00:05:37,120
inside of here

151
00:05:33,680 --> 00:05:39,600
and then i'm going to drag this back

152
00:05:37,120 --> 00:05:40,560
all right so lastly we have to add a few

153
00:05:39,600 --> 00:05:43,199
more things

154
00:05:40,560 --> 00:05:45,520
for when the enemy leaves the screen so

155
00:05:43,199 --> 00:05:48,560
inside of the if touching edge

156
00:05:45,520 --> 00:05:52,160
i am going to go to the lists again

157
00:05:48,560 --> 00:05:54,880
and then drag a replace item of block

158
00:05:52,160 --> 00:05:56,080
and then in here drag a clone number

159
00:05:54,880 --> 00:05:59,520
variable

160
00:05:56,080 --> 00:06:02,160
and change this to enemy x

161
00:05:59,520 --> 00:06:02,880
and then inside of the value i think i'm

162
00:06:02,160 --> 00:06:06,080
going to do

163
00:06:02,880 --> 00:06:09,039
a blank okay and then

164
00:06:06,080 --> 00:06:10,560
i am going to duplicate this change this

165
00:06:09,039 --> 00:06:13,600
to enemy y

166
00:06:10,560 --> 00:06:16,720
and also leave it blank and then lastly

167
00:06:13,600 --> 00:06:20,560
i am going to go to the lists again

168
00:06:16,720 --> 00:06:24,560
and this time actually um grab a delete

169
00:06:20,560 --> 00:06:24,960
one of block and then i am going to grab

170
00:06:24,560 --> 00:06:28,240
a

171
00:06:24,960 --> 00:06:31,440
item number of block and then put the

172
00:06:28,240 --> 00:06:32,960
clone number variable in here

173
00:06:31,440 --> 00:06:34,880
and then this is going to be for the

174
00:06:32,960 --> 00:06:35,840
enemy ids list so we can leave it like

175
00:06:34,880 --> 00:06:38,319
that

176
00:06:35,840 --> 00:06:40,000
and i will drag this back inside of the

177
00:06:38,319 --> 00:06:41,759
value

178
00:06:40,000 --> 00:06:43,520
all right so i know i'm sort of speeding

179
00:06:41,759 --> 00:06:45,919
along with this but pretty much

180
00:06:43,520 --> 00:06:46,639
now we know all of the clones x and y

181
00:06:45,919 --> 00:06:48,880
positions

182
00:06:46,639 --> 00:06:49,919
as well as their progress and their

183
00:06:48,880 --> 00:06:52,160
clone numbers

184
00:06:49,919 --> 00:06:54,000
so i'm going to put this inside of the

185
00:06:52,160 --> 00:06:56,400
if touching edge

186
00:06:54,000 --> 00:06:57,199
and then instead of hiding i'm going to

187
00:06:56,400 --> 00:07:00,479
actually

188
00:06:57,199 --> 00:07:02,800
delete the clone all right

189
00:07:00,479 --> 00:07:04,080
and now i believe that should be fine

190
00:07:02,800 --> 00:07:06,720
for the enemies

191
00:07:04,080 --> 00:07:08,720
so if i just show all of these lists for

192
00:07:06,720 --> 00:07:11,280
now

193
00:07:08,720 --> 00:07:11,759
then when the enemies appear then they

194
00:07:11,280 --> 00:07:14,240
should

195
00:07:11,759 --> 00:07:15,759
add their values to these four lists as

196
00:07:14,240 --> 00:07:18,880
you can see

197
00:07:15,759 --> 00:07:20,400
and then once they disappear then this

198
00:07:18,880 --> 00:07:23,919
enemy ids list

199
00:07:20,400 --> 00:07:26,319
should decrease in size

200
00:07:23,919 --> 00:07:27,440
like this and then the values should

201
00:07:26,319 --> 00:07:29,440
turn blank

202
00:07:27,440 --> 00:07:30,560
alright cool so of course there are no

203
00:07:29,440 --> 00:07:32,720
changes to the game

204
00:07:30,560 --> 00:07:34,639
other than these four lists but now we

205
00:07:32,720 --> 00:07:37,680
can start creating the towers

206
00:07:34,639 --> 00:07:39,680
so i'm going to hide these

207
00:07:37,680 --> 00:07:41,840
and then i'm going to create a new

208
00:07:39,680 --> 00:07:45,039
sprite

209
00:07:41,840 --> 00:07:48,720
and for now i will make a simple tower

210
00:07:45,039 --> 00:07:51,280
so i will make this a gray color

211
00:07:48,720 --> 00:07:51,280
okay

212
00:07:52,560 --> 00:07:55,919
and i think a black outline should be

213
00:07:55,039 --> 00:07:59,599
fine

214
00:07:55,919 --> 00:08:02,240
maybe a dark gray all right

215
00:07:59,599 --> 00:08:02,960
and then for the tower i think i'll make

216
00:08:02,240 --> 00:08:08,400
a simple

217
00:08:02,960 --> 00:08:12,560
square maybe a lighter gray

218
00:08:08,400 --> 00:08:16,000
with a larger outline all right

219
00:08:12,560 --> 00:08:16,000
might make it a bit smaller

220
00:08:16,639 --> 00:08:18,960
okay

221
00:08:20,160 --> 00:08:27,199
and i'll make the outline a bit smaller

222
00:08:22,240 --> 00:08:31,199
as well

223
00:08:27,199 --> 00:08:32,800
okay and then i am going to create one

224
00:08:31,199 --> 00:08:34,880
more rectangle

225
00:08:32,800 --> 00:08:35,919
this is going to be how the turret

226
00:08:34,880 --> 00:08:39,039
shoots

227
00:08:35,919 --> 00:08:42,560
all right and i think

228
00:08:39,039 --> 00:08:45,040
this should be fine

229
00:08:42,560 --> 00:08:47,040
okay so this is my simple turret and

230
00:08:45,040 --> 00:08:48,560
make sure that this square right here is

231
00:08:47,040 --> 00:08:50,560
centered in the middle

232
00:08:48,560 --> 00:08:52,480
and not this entire thing because

233
00:08:50,560 --> 00:08:53,360
otherwise the turret won't rotate

234
00:08:52,480 --> 00:08:57,360
correctly

235
00:08:53,360 --> 00:09:01,120
so only center this square in the middle

236
00:08:57,360 --> 00:09:03,120
okay so now let's go inside of the code

237
00:09:01,120 --> 00:09:04,800
and i'm going to drag a wind flag

238
00:09:03,120 --> 00:09:07,600
clicked

239
00:09:04,800 --> 00:09:08,000
and then i'm going to go into looks drag

240
00:09:07,600 --> 00:09:10,080
a set

241
00:09:08,000 --> 00:09:13,360
size to a hundred percent drag a switch

242
00:09:10,080 --> 00:09:15,519
costume to costume one

243
00:09:13,360 --> 00:09:16,800
and oh yeah actually i'm going to create

244
00:09:15,519 --> 00:09:19,279
a really simple shop

245
00:09:16,800 --> 00:09:20,959
where you can buy and place turrets so

246
00:09:19,279 --> 00:09:24,880
actually i am going to

247
00:09:20,959 --> 00:09:28,000
set the size to something like 25

248
00:09:24,880 --> 00:09:29,839
okay that's a bit too small so maybe 50

249
00:09:28,000 --> 00:09:32,959
percent

250
00:09:29,839 --> 00:09:36,560
60 65

251
00:09:32,959 --> 00:09:39,120
okay so 65 and then

252
00:09:36,560 --> 00:09:40,399
i'm gonna put this turret right over

253
00:09:39,120 --> 00:09:43,839
here somewhere

254
00:09:40,399 --> 00:09:46,320
so on the top right corner all right

255
00:09:43,839 --> 00:09:47,680
and then i'm going to drag this go to xy

256
00:09:46,320 --> 00:09:49,680
block

257
00:09:47,680 --> 00:09:51,519
and pretty much what i'm planning to do

258
00:09:49,680 --> 00:09:54,000
is that i'm gonna make it so

259
00:09:51,519 --> 00:09:55,920
if i click this image right here then it

260
00:09:54,000 --> 00:09:57,279
will create a clone of the turret for me

261
00:09:55,920 --> 00:09:58,800
to place on the map

262
00:09:57,279 --> 00:10:00,800
so to do that i am going to go to

263
00:09:58,800 --> 00:10:02,000
variables and then create two new

264
00:10:00,800 --> 00:10:05,120
variables

265
00:10:02,000 --> 00:10:08,320
the first one is going to be called um

266
00:10:05,120 --> 00:10:11,279
let's call it mouse action

267
00:10:08,320 --> 00:10:12,560
all right and then click ok and then for

268
00:10:11,279 --> 00:10:15,680
the second one

269
00:10:12,560 --> 00:10:19,839
i'm going to create let's call this can

270
00:10:15,680 --> 00:10:19,839
show radius circle

271
00:10:20,480 --> 00:10:25,120
and then click ok alright so i want to

272
00:10:23,279 --> 00:10:25,839
make it so that if i click this right

273
00:10:25,120 --> 00:10:28,079
here

274
00:10:25,839 --> 00:10:30,000
then it will create a clone of a turret

275
00:10:28,079 --> 00:10:32,560
which will follow my mouse pointer

276
00:10:30,000 --> 00:10:33,680
until i click again and then the turret

277
00:10:32,560 --> 00:10:35,440
stays in place

278
00:10:33,680 --> 00:10:36,959
so to do that we are going to use the

279
00:10:35,440 --> 00:10:40,480
mouse action variable

280
00:10:36,959 --> 00:10:43,600
so i'm going to first set mouse action

281
00:10:40,480 --> 00:10:46,560
to none when the flag is clicked

282
00:10:43,600 --> 00:10:48,560
and then i'm going to go to control drag

283
00:10:46,560 --> 00:10:52,240
a forever loop

284
00:10:48,560 --> 00:10:55,120
and then forever i'm going to check if

285
00:10:52,240 --> 00:10:57,200
go to sensing if the turret is touching

286
00:10:55,120 --> 00:11:00,399
the mouse pointer

287
00:10:57,200 --> 00:11:04,079
and the mouse is down

288
00:11:00,399 --> 00:11:07,200
so sensing again mouse down

289
00:11:04,079 --> 00:11:10,480
then i'm going to go to variables

290
00:11:07,200 --> 00:11:14,320
and then set mouse action to

291
00:11:10,480 --> 00:11:16,720
something like let's say selected

292
00:11:14,320 --> 00:11:18,800
okay so this is going to be the first

293
00:11:16,720 --> 00:11:19,360
click which means that this sprite right

294
00:11:18,800 --> 00:11:21,920
here

295
00:11:19,360 --> 00:11:22,880
creates a clone of a new turret and then

296
00:11:21,920 --> 00:11:25,440
the turret clone

297
00:11:22,880 --> 00:11:27,680
should follow our mouse pointer so let's

298
00:11:25,440 --> 00:11:32,079
go to control

299
00:11:27,680 --> 00:11:32,079
and then let's drag a 1xr as a clone

300
00:11:32,480 --> 00:11:37,120
and then inside of it i'm going to drag

301
00:11:34,959 --> 00:11:39,279
a forever loop

302
00:11:37,120 --> 00:11:40,880
and i'm going to drag an if else

303
00:11:39,279 --> 00:11:45,120
statement

304
00:11:40,880 --> 00:11:50,000
and check if go to variables

305
00:11:45,120 --> 00:11:51,760
if the mouse action is equal to selected

306
00:11:50,000 --> 00:11:53,600
which means that the clone should follow

307
00:11:51,760 --> 00:11:55,519
the mouse pointer

308
00:11:53,600 --> 00:11:58,560
then of course we are going to go to

309
00:11:55,519 --> 00:12:01,760
motion and drag a go to

310
00:11:58,560 --> 00:12:05,200
and change it to mouse pointer alright

311
00:12:01,760 --> 00:12:08,560
and also make sure to create a clone

312
00:12:05,200 --> 00:12:09,600
of myself once the original sprite is

313
00:12:08,560 --> 00:12:12,160
clicked

314
00:12:09,600 --> 00:12:13,120
and i'm also going to add a wait until

315
00:12:12,160 --> 00:12:15,600
block

316
00:12:13,120 --> 00:12:18,399
so wait until and then i'm going to

317
00:12:15,600 --> 00:12:22,160
right click duplicate this

318
00:12:18,399 --> 00:12:24,800
and put it in here and i'm going to say

319
00:12:22,160 --> 00:12:26,320
wait until touching mouse pointer and

320
00:12:24,800 --> 00:12:29,120
not mouse down

321
00:12:26,320 --> 00:12:29,920
so i'm going to go to operators drag a

322
00:12:29,120 --> 00:12:32,240
knot

323
00:12:29,920 --> 00:12:33,680
and put the mouse down on there and put

324
00:12:32,240 --> 00:12:35,839
it back

325
00:12:33,680 --> 00:12:36,880
all right cool and now i'm going to put

326
00:12:35,839 --> 00:12:40,959
this

327
00:12:36,880 --> 00:12:43,360
right before the create clone of myself

328
00:12:40,959 --> 00:12:45,360
alright so now if we try it then we

329
00:12:43,360 --> 00:12:45,760
should have a clone which appears under

330
00:12:45,360 --> 00:12:48,399
it

331
00:12:45,760 --> 00:12:49,440
once we click the sprite right here

332
00:12:48,399 --> 00:12:51,360
alright cool

333
00:12:49,440 --> 00:12:53,600
so now of course we want to place the

334
00:12:51,360 --> 00:12:56,399
turret once we click again

335
00:12:53,600 --> 00:12:59,519
so i'm going to go to control and then

336
00:12:56,399 --> 00:13:02,079
drag another when i start as a clone

337
00:12:59,519 --> 00:13:03,360
and in this one i'm going to check

338
00:13:02,079 --> 00:13:06,880
forever

339
00:13:03,360 --> 00:13:10,320
if mouse down so sensing

340
00:13:06,880 --> 00:13:11,440
if mouse down then i'm going to wait

341
00:13:10,320 --> 00:13:15,120
until

342
00:13:11,440 --> 00:13:18,240
not mouse down so this ensures that

343
00:13:15,120 --> 00:13:20,160
the player does one full click so wait

344
00:13:18,240 --> 00:13:23,360
until not mouse down

345
00:13:20,160 --> 00:13:26,639
then i'm going to go to variables

346
00:13:23,360 --> 00:13:30,079
and set the mouse action

347
00:13:26,639 --> 00:13:32,399
to none okay

348
00:13:30,079 --> 00:13:33,600
and for the clone i am also going to set

349
00:13:32,399 --> 00:13:37,920
the size

350
00:13:33,600 --> 00:13:41,360
to its normal size which was 100 percent

351
00:13:37,920 --> 00:13:44,240
okay so now if you try it then

352
00:13:41,360 --> 00:13:45,839
if i click then we have a clone and then

353
00:13:44,240 --> 00:13:49,440
once i click again

354
00:13:45,839 --> 00:13:51,839
then it stays on the track alright cool

355
00:13:49,440 --> 00:13:53,040
so of course we all know that towers in

356
00:13:51,839 --> 00:13:55,680
tower defense games

357
00:13:53,040 --> 00:13:57,199
have ranges so now i'm going to create a

358
00:13:55,680 --> 00:13:58,639
new sprite

359
00:13:57,199 --> 00:14:00,880
and this is going to be the range for

360
00:13:58,639 --> 00:14:03,839
this tower

361
00:14:00,880 --> 00:14:04,720
and for the range i am going to create a

362
00:14:03,839 --> 00:14:08,720
simple

363
00:14:04,720 --> 00:14:12,639
circle so i will press shift

364
00:14:08,720 --> 00:14:16,160
and then hold for a perfect circle

365
00:14:12,639 --> 00:14:18,399
all right and i will make the fill a

366
00:14:16,160 --> 00:14:21,440
white color

367
00:14:18,399 --> 00:14:24,639
and i think the outline for this is fine

368
00:14:21,440 --> 00:14:24,639
maybe a bit smaller

369
00:14:25,120 --> 00:14:28,800
um okay i think an outline of four is

370
00:14:27,920 --> 00:14:31,600
okay

371
00:14:28,800 --> 00:14:34,160
and now inside of the code i'm going to

372
00:14:31,600 --> 00:14:36,000
drag a when fly clicked

373
00:14:34,160 --> 00:14:37,279
and then i'm going to first hide the

374
00:14:36,000 --> 00:14:41,440
range sprite

375
00:14:37,279 --> 00:14:42,560
so drag and hide and i think i'm also

376
00:14:41,440 --> 00:14:44,560
going to make it

377
00:14:42,560 --> 00:14:45,600
sort of transparent or sort of

378
00:14:44,560 --> 00:14:48,480
see-through

379
00:14:45,600 --> 00:14:49,120
so i'm going to change this to set ghost

380
00:14:48,480 --> 00:14:52,320
effect

381
00:14:49,120 --> 00:14:55,600
to 50 so let's try it out

382
00:14:52,320 --> 00:14:58,320
oops okay it's hidden so show

383
00:14:55,600 --> 00:14:59,519
all right i think that looks pretty good

384
00:14:58,320 --> 00:15:02,480
and now

385
00:14:59,519 --> 00:15:04,480
i'm going to create one more variable so

386
00:15:02,480 --> 00:15:07,600
let's call this um

387
00:15:04,480 --> 00:15:10,160
something like view radius

388
00:15:07,600 --> 00:15:11,600
so this is going to determine how large

389
00:15:10,160 --> 00:15:13,680
this circle will be

390
00:15:11,600 --> 00:15:15,920
and now we should be good so let's go

391
00:15:13,680 --> 00:15:18,079
back to our turrets right

392
00:15:15,920 --> 00:15:19,519
and by the way i'm going to name this

393
00:15:18,079 --> 00:15:23,279
turret

394
00:15:19,519 --> 00:15:26,720
okay and also i'm going to name this uh

395
00:15:23,279 --> 00:15:30,720
radius circle i guess

396
00:15:26,720 --> 00:15:33,839
or turret range circle

397
00:15:30,720 --> 00:15:34,639
all right and inside of the turret

398
00:15:33,839 --> 00:15:37,839
sprite

399
00:15:34,639 --> 00:15:38,639
i am going to first set the can show

400
00:15:37,839 --> 00:15:41,839
radius circle

401
00:15:38,639 --> 00:15:44,560
variable to no

402
00:15:41,839 --> 00:15:46,480
all right and this means that the range

403
00:15:44,560 --> 00:15:48,800
circle will be hidden

404
00:15:46,480 --> 00:15:49,759
however once we are actually dragging

405
00:15:48,800 --> 00:15:52,800
the turret

406
00:15:49,759 --> 00:15:55,040
we want to show the range circle so

407
00:15:52,800 --> 00:15:56,480
inside of the if mouse action is equal

408
00:15:55,040 --> 00:15:59,040
to selected

409
00:15:56,480 --> 00:15:59,839
i'm going to set the can show ready

410
00:15:59,040 --> 00:16:02,880
circle

411
00:15:59,839 --> 00:16:05,440
to yes and then

412
00:16:02,880 --> 00:16:06,480
up over here once we actually place the

413
00:16:05,440 --> 00:16:08,880
tower

414
00:16:06,480 --> 00:16:11,120
then i'm going to hide it again so i'm

415
00:16:08,880 --> 00:16:14,480
going to drag the cancho radius circle

416
00:16:11,120 --> 00:16:17,199
to no all right cool so now inside of

417
00:16:14,480 --> 00:16:20,800
the turret range sprite

418
00:16:17,199 --> 00:16:22,000
we want to check forever and then i'm

419
00:16:20,800 --> 00:16:25,440
going to drag in if

420
00:16:22,000 --> 00:16:28,560
else so we want to check if

421
00:16:25,440 --> 00:16:30,399
the can show radius circle variable is

422
00:16:28,560 --> 00:16:32,720
equal to yes

423
00:16:30,399 --> 00:16:34,240
then of course we want to show the

424
00:16:32,720 --> 00:16:37,040
radius circle

425
00:16:34,240 --> 00:16:38,880
so drag a show and we also want to make

426
00:16:37,040 --> 00:16:42,079
it go to the mouse pointer

427
00:16:38,880 --> 00:16:44,880
so let's drag a go to

428
00:16:42,079 --> 00:16:45,920
and change this to mouse pointer all

429
00:16:44,880 --> 00:16:49,040
right cool

430
00:16:45,920 --> 00:16:51,120
and then inside of the else we want to

431
00:16:49,040 --> 00:16:53,920
hide

432
00:16:51,120 --> 00:16:54,320
and now if we try it out then if we

433
00:16:53,920 --> 00:16:57,199
click

434
00:16:54,320 --> 00:16:57,920
on the image then as you can see we have

435
00:16:57,199 --> 00:17:00,639
the turret

436
00:16:57,920 --> 00:17:02,079
along with the radius circle and if i

437
00:17:00,639 --> 00:17:04,799
place it down

438
00:17:02,079 --> 00:17:05,679
then the circle disappears all right

439
00:17:04,799 --> 00:17:07,600
cool

440
00:17:05,679 --> 00:17:09,199
and i think i'm going to make the turret

441
00:17:07,600 --> 00:17:11,760
a bit smaller

442
00:17:09,199 --> 00:17:13,120
so maybe set size to something like 75

443
00:17:11,760 --> 00:17:16,839
percent

444
00:17:13,120 --> 00:17:18,079
let's try it out and okay i think that's

445
00:17:16,839 --> 00:17:21,280
fine

446
00:17:18,079 --> 00:17:23,839
and now we have our radius

447
00:17:21,280 --> 00:17:25,120
all right cool alright so let's try it

448
00:17:23,839 --> 00:17:26,959
out again

449
00:17:25,120 --> 00:17:28,559
and let's see if we can place multiple

450
00:17:26,959 --> 00:17:34,160
turrets

451
00:17:28,559 --> 00:17:35,840
um okay so let's see um

452
00:17:34,160 --> 00:17:37,360
oh yeah one thing to change is that the

453
00:17:35,840 --> 00:17:40,000
mouse action variable

454
00:17:37,360 --> 00:17:41,039
should actually be for this sprite only

455
00:17:40,000 --> 00:17:43,200
so

456
00:17:41,039 --> 00:17:45,120
um sorry about that so let's create a

457
00:17:43,200 --> 00:17:46,559
new mouse action variable

458
00:17:45,120 --> 00:17:48,640
and then i'll actually add a space in

459
00:17:46,559 --> 00:17:51,120
between it so mouse action

460
00:17:48,640 --> 00:17:51,760
and then select for the spy only all

461
00:17:51,120 --> 00:17:55,200
right

462
00:17:51,760 --> 00:17:55,919
and then click ok and now i'm going to

463
00:17:55,200 --> 00:17:57,679
replace

464
00:17:55,919 --> 00:17:59,520
all of the previous mouse action

465
00:17:57,679 --> 00:18:03,440
variables with the new one

466
00:17:59,520 --> 00:18:05,600
so the one with the space

467
00:18:03,440 --> 00:18:06,880
okay change this to the one with the

468
00:18:05,600 --> 00:18:10,240
space

469
00:18:06,880 --> 00:18:10,720
and this one all right and then i will

470
00:18:10,240 --> 00:18:14,080
delete

471
00:18:10,720 --> 00:18:16,320
my old mouse action variable

472
00:18:14,080 --> 00:18:17,600
all right and now it should work with

473
00:18:16,320 --> 00:18:21,120
multiple turrets

474
00:18:17,600 --> 00:18:23,600
so if i try it out then all right cool

475
00:18:21,120 --> 00:18:25,520
so now i can place multiple turrets and

476
00:18:23,600 --> 00:18:28,240
the range always follows the one that is

477
00:18:25,520 --> 00:18:30,080
following my mouse

478
00:18:28,240 --> 00:18:31,440
and now i'm going to hide all of these

479
00:18:30,080 --> 00:18:33,760
variables

480
00:18:31,440 --> 00:18:34,559
and by the way the view radius variable

481
00:18:33,760 --> 00:18:37,360
will be used

482
00:18:34,559 --> 00:18:38,640
in the next video so i'll just have it

483
00:18:37,360 --> 00:18:41,120
created for now

484
00:18:38,640 --> 00:18:42,480
but i won't touch it and let's go inside

485
00:18:41,120 --> 00:18:45,679
of the enemy as well

486
00:18:42,480 --> 00:18:46,799
and hide the variables all right so now

487
00:18:45,679 --> 00:18:48,880
we have our four

488
00:18:46,799 --> 00:18:49,840
enemy lists that will be used for the

489
00:18:48,880 --> 00:18:52,960
turret

490
00:18:49,840 --> 00:18:55,039
as well as a simple turret shop where we

491
00:18:52,960 --> 00:19:00,240
can place these down

492
00:18:55,039 --> 00:19:00,240
on the map all right cool

493
00:19:01,360 --> 00:19:05,120
anyways that's it for this tutorial if

494
00:19:03,440 --> 00:19:07,520
you enjoyed it then give it a thumbs up

495
00:19:05,120 --> 00:19:08,880
and subscribe too if you haven't already

496
00:19:07,520 --> 00:19:10,640
again in this video

497
00:19:08,880 --> 00:19:12,160
we mostly just completed the setup for

498
00:19:10,640 --> 00:19:14,400
the turret aiming and shooting

499
00:19:12,160 --> 00:19:16,559
which we will do in the next video

500
00:19:14,400 --> 00:19:25,840
anyways that's it for this tutorial

501
00:19:16,559 --> 00:19:25,840
see ya


