1
00:00:08,670 --> 00:00:10,794
This is our last lecture for module seven,

2
00:00:10,794 --> 00:00:14,240
where we've been talking about the
selection control structure.

3
00:00:14,240 --> 00:00:16,750
Here are the learning objectives for the
module.

4
00:00:20,030 --> 00:00:22,868
So over the last two lectures, we've
talked about

5
00:00:22,868 --> 00:00:26,168
the different variance of if statements,
and about switch

6
00:00:26,168 --> 00:00:28,940
statements, and how we use those to
implement the

7
00:00:28,940 --> 00:00:33,810
selection control structure, how we make
decisions in our program.

8
00:00:33,810 --> 00:00:36,624
In this lecture, we're actually going to
look in

9
00:00:36,624 --> 00:00:40,380
detail at how selection works when we
actually implement games.

10
00:00:42,590 --> 00:00:47,720
So, I'm going to start up a project that
I've already built to demonstrate this.

11
00:00:47,720 --> 00:00:49,510
We won't be building code today.

12
00:00:49,510 --> 00:00:52,570
We'll be looking at code that I've already
created.

13
00:00:52,570 --> 00:00:57,658
So when I F5, we see that we have teddy

14
00:00:57,658 --> 00:01:03,980
bears moving outward.
And then bouncing off the walls.

15
00:01:03,980 --> 00:01:07,760
So let's immediately go to an in-lecture
quiz where

16
00:01:07,760 --> 00:01:11,750
you tell me about how you feel about
bouncing off walls.

17
00:01:16,610 --> 00:01:21,230
If we look at, now this is not a
screenshot of what you just saw.

18
00:01:21,230 --> 00:01:23,090
This is a screenshot using slightly

19
00:01:23,090 --> 00:01:26,190
different sprites that show the draw
rectangles.

20
00:01:26,190 --> 00:01:31,551
Around these teddy bears as well.
So, if we think about what it means to

21
00:01:31,551 --> 00:01:37,005
bounce off the walls and how we might do
it, one way we could think

22
00:01:37,005 --> 00:01:42,300
about it is if, in fact, this guy comes
all the way over here.

23
00:01:43,580 --> 00:01:46,044
And the edge of his draw rectangle goes

24
00:01:46,044 --> 00:01:49,124
outside the edge of the window, whoops,
sorry

25
00:01:49,124 --> 00:01:51,742
about that, goes outside the edge of the

26
00:01:51,742 --> 00:01:55,250
window, then, in fact, we should bounce
him.

27
00:01:55,250 --> 00:01:57,460
Right, he's leaving the game world.

28
00:01:57,460 --> 00:02:01,000
Same with this one, except that this is
the edge that we'd worry about.

29
00:02:01,000 --> 00:02:03,720
And of course he might bounce back.
Back and forth and so on.

30
00:02:03,720 --> 00:02:08,865
So, the big idea behind how we can do this
is we can check the

31
00:02:08,865 --> 00:02:13,905
draw rectangle for each of the sprites and
see if they're

32
00:02:13,905 --> 00:02:18,370
outside of the window.
Now let's go back to the code.

33
00:02:20,020 --> 00:02:24,460
When we talked about the teddy bear class
last time.

34
00:02:24,460 --> 00:02:25,760
Sorry, not last time.

35
00:02:25,760 --> 00:02:29,670
When we were doing a more XNA practice, we
had to hand in

36
00:02:29,670 --> 00:02:34,770
the window width and window height to the
teddy bear when we constructed

37
00:02:34,770 --> 00:02:39,019
it, and we did that and we saved it into
these fields here.

38
00:02:40,290 --> 00:02:42,630
So let's look at how one of the bounces
work.

39
00:02:42,630 --> 00:02:47,990
We'll do left-right because that's the one
that, that we just saw.

40
00:02:51,320 --> 00:02:57,250
And I'll zoom in, and we'll look at bounce
left-right.

41
00:02:57,250 --> 00:03:01,230
So this is the method that actually
bounces the teddy bear.

42
00:03:01,230 --> 00:03:05,980
So let's see how it actually works.
Here's an if else-if.

43
00:03:05,980 --> 00:03:09,560
Remember, we said if we have else-ifs, we
don't necessarily have to have else's.

44
00:03:09,560 --> 00:03:11,030
They're optional.

45
00:03:11,030 --> 00:03:13,305
But if the draw rectangle.x, so that's

46
00:03:13,305 --> 00:03:17,080
the upper left-hand corner of the draw
rectangle.

47
00:03:17,080 --> 00:03:20,412
If that is less than 0, that means that
the drawRectangle

48
00:03:20,412 --> 00:03:25,070
is at least partially outside the
left-hand side of the window.

49
00:03:25,070 --> 00:03:26,410
And what a horrible comment.

50
00:03:26,410 --> 00:03:27,840
Let's add an e there.

51
00:03:27,840 --> 00:03:30,100
So we're going to bounce off of the left
side of the window.

52
00:03:31,580 --> 00:03:36,680
We will immediately do this.
Remember, drawRectangle is a rectangle

53
00:03:36,680 --> 00:03:42,385
structure which exposes an x property.
That we can set so we set

54
00:03:42,385 --> 00:03:46,416
it to zero.
We, if the teddy bear has gone off the

55
00:03:46,416 --> 00:03:50,830
left hand side we immediately bring it
exactly to the left hand side.

56
00:03:52,110 --> 00:03:59,680
Velocity in the x direction, we're going
to multiply by woops, let me not do that.

57
00:03:59,680 --> 00:04:02,130
We're going to multiply by negative one.

58
00:04:02,130 --> 00:04:06,460
So in other words, if the x velocity was
negative.

59
00:04:06,460 --> 00:04:07,820
When it went outside on the left.

60
00:04:07,820 --> 00:04:10,100
And we actually know it was negative when
it went

61
00:04:10,100 --> 00:04:12,570
outside on the left, because it was moving
to the left.

62
00:04:13,850 --> 00:04:18,747
We then multiply by negative one so now
we've turned the velocity into

63
00:04:18,747 --> 00:04:23,460
a positive component in the x direction,
so now the teddy bear is.

64
00:04:24,510 --> 00:04:29,120
At the very left edge of the window and
has started moving to the right.

65
00:04:29,120 --> 00:04:31,160
Which is exactly how we bounce it.

66
00:04:33,300 --> 00:04:35,460
We have this else if because the teddy
bear could

67
00:04:35,460 --> 00:04:38,630
also be going out the right hand side of
the screen.

68
00:04:38,630 --> 00:04:40,960
Here it gets a little more complicated.

69
00:04:40,960 --> 00:04:45,178
This code says drawRectangle.x plus
drawRectangle.Width which

70
00:04:45,178 --> 00:04:48,310
is an intuitive way to think about it.

71
00:04:48,310 --> 00:04:53,066
Right, so the left-hand side,
drawRectangle.X, plus the width

72
00:04:53,066 --> 00:04:57,560
of the draw rectangle gets us to the
right-hand side.

73
00:04:57,560 --> 00:04:58,491
And if that's greater

74
00:04:58,491 --> 00:05:04,743
than window width, we do this other stuff.
Now, I will tell you, just because you

75
00:05:04,743 --> 00:05:11,760
ought to know, that drawRectangle also
exposes a right property.

76
00:05:11,760 --> 00:05:15,540
Which is the x location of the right hand
side of the draw rectangle.

77
00:05:15,540 --> 00:05:18,940
So that might even seem more intuitive to
you.

78
00:05:18,940 --> 00:05:20,954
Is that we're checking if the right hand
side

79
00:05:20,954 --> 00:05:24,100
of the draw rectangle is greater than
window width.

80
00:05:24,100 --> 00:05:27,016
If it is, we're going to bounce off,
notice

81
00:05:27,016 --> 00:05:30,094
though we have to change the left hand,
upper

82
00:05:30,094 --> 00:05:32,848
left hand corner of the draw rectangle to

83
00:05:32,848 --> 00:05:36,950
be at window width minus the draw
rectangle width.

84
00:05:36,950 --> 00:05:40,370
We can't just set it to WindowWidth
because then we'd be guaranteeing

85
00:05:40,370 --> 00:05:44,790
that the entire drawRectangle is outside
the window on the right-hand side.

86
00:05:44,790 --> 00:05:46,470
So we start at the WindowWidth and

87
00:05:46,470 --> 00:05:48,990
we back-up the full width of the
drawRectangle,

88
00:05:48,990 --> 00:05:51,210
so that now the whole drawRectangle is
still

89
00:05:51,210 --> 00:05:55,010
in the window, right up against the
right-hand side.

90
00:05:55,010 --> 00:05:57,830
And then we reverse the x velocity again.

91
00:05:57,830 --> 00:06:01,590
So that's the first example of using
selection.

92
00:06:01,590 --> 00:06:05,068
We've got this if else if in our game,
where

93
00:06:05,068 --> 00:06:09,430
we're in fact doing the bouncing off the
walls thing.

94
00:06:11,050 --> 00:06:15,260
I very carefully stopped the game when I
did before.

95
00:06:15,260 --> 00:06:17,590
Now I'm going to let it go a little bit
longer.

96
00:06:19,440 --> 00:06:21,340
So you can see what really happens.

97
00:06:21,340 --> 00:06:22,908
Oh my gosh.

98
00:06:22,908 --> 00:06:30,005
Very sad.
So, you should now do an

99
00:06:30,005 --> 00:06:37,430
in-lecture quiz about collision detection.

100
00:06:37,430 --> 00:06:40,320
Back to our picture of these two bears
again.

101
00:06:40,320 --> 00:06:44,145
You should be able to realize, I guess,
that when the

102
00:06:44,145 --> 00:06:48,750
bears ran into each other, we detected
that they had collided.

103
00:06:48,750 --> 00:06:50,099
That's the collision detection thing.

104
00:06:51,160 --> 00:06:55,830
And then we played the explosion that's
called the collision resolution.

105
00:06:55,830 --> 00:06:58,250
It's how we resolved that particular
collision.

106
00:06:59,410 --> 00:07:05,500
So how did we detect that the teddy bears
had collided with each other?

107
00:07:05,500 --> 00:07:06,350
Well.

108
00:07:06,350 --> 00:07:09,450
The easiest way is to say, well how do

109
00:07:09,450 --> 00:07:14,350
we know that this guy is colliding with
this guy.

110
00:07:14,350 --> 00:07:18,087
Well the easiest way is to say, well if
their

111
00:07:18,087 --> 00:07:23,890
rectangles overlap in any way, then we'll
call that a collision.

112
00:07:25,100 --> 00:07:27,509
Now that is not perfect because you'll

113
00:07:27,509 --> 00:07:30,575
notice there are some spaces inside these
sprites

114
00:07:30,575 --> 00:07:34,371
where they're transparent even though it's
inside the draw

115
00:07:34,371 --> 00:07:38,110
rectangle so that's not a perfect way to
do it.

116
00:07:38,110 --> 00:07:41,860
And of course there is a perfect way to do
it with 2D graphics

117
00:07:41,860 --> 00:07:47,970
and it's called pixel perfect collision
detection because we do it pixel by pixel.

118
00:07:47,970 --> 00:07:52,210
Beyond of the scope of this particular
class, but not rocket science either.

119
00:07:52,210 --> 00:07:55,675
I mean this is a solved problem.
We're going to just

120
00:07:55,675 --> 00:07:57,970
handle the rectangles overlapping because
that let's us

121
00:07:57,970 --> 00:08:00,060
just use what we know at this point.

122
00:08:00,060 --> 00:08:03,290
But obviously there are more complicated
and

123
00:08:03,290 --> 00:08:07,710
better ways to do ultimately collision
detection.

124
00:08:07,710 --> 00:08:10,849
Although almost all of them, even
pixel-perfect

125
00:08:10,849 --> 00:08:15,280
collision detection, uses the
rectangle-overlapping test first.

126
00:08:15,280 --> 00:08:17,453
Because if the draw rectangles don't
overlap,

127
00:08:17,453 --> 00:08:19,350
there's no way there can be a collision.

128
00:08:19,350 --> 00:08:20,757
There's no need to do any

129
00:08:20,757 --> 00:08:23,870
extra complicated math.
Okay.

130
00:08:23,870 --> 00:08:29,320
So let's go look at the code and see how
this actually works in practice.

131
00:08:31,510 --> 00:08:34,634
So we need to go to the part where we have
the collision

132
00:08:34,634 --> 00:08:39,560
detection in our code, and that happens in
game one in this particular instance.

133
00:08:39,560 --> 00:08:40,620
So, zooming in.

134
00:08:42,560 --> 00:08:46,590
And by the way, here's where I created
those game objects, notice that I

135
00:08:46,590 --> 00:08:49,320
used the other teddy bear constructor
overload,

136
00:08:49,320 --> 00:08:51,820
where I get to provide a velocity.

137
00:08:51,820 --> 00:08:54,024
Otherwise we have two teddy bears with
random

138
00:08:54,024 --> 00:08:56,808
velocities and we watched them for long
time potentially

139
00:08:56,808 --> 00:08:59,880
before they finally run into each other
and explode.

140
00:08:59,880 --> 00:09:02,390
And I wanted that gratification as quickly
as possible.

141
00:09:03,410 --> 00:09:10,860
Okay, so in update, here's where we're
doing that collision detection.

142
00:09:10,860 --> 00:09:15,900
Now, both teddy bears expose a property
called active.

143
00:09:15,900 --> 00:09:18,484
So this property is true if the teddy bear

144
00:09:18,484 --> 00:09:21,960
is active and false if the teddy bear is
not.

145
00:09:21,960 --> 00:09:24,261
And this is a fairly common pattern you'll
see

146
00:09:24,261 --> 00:09:28,660
in game development, where we activate and
deactivate particular objects.

147
00:09:28,660 --> 00:09:32,360
So we only want to check for a collision
if both bears are active.

148
00:09:32,360 --> 00:09:35,000
If one or both of them are inactive, we
don't care.

149
00:09:35,000 --> 00:09:39,147
If they collide.
Here is the part where we check that

150
00:09:39,147 --> 00:09:45,630
overlapping of rectangle things.
So bear zero is a teddy bear object.

151
00:09:46,740 --> 00:09:50,830
He's exposing the teddy bear class,
exposes.

152
00:09:53,550 --> 00:09:56,610
A collision rectangle object and notice
that the property is

153
00:09:56,610 --> 00:10:01,320
calling collision rectangle even though
we're just providing the draw rectangle.

154
00:10:01,320 --> 00:10:02,100
Why?

155
00:10:02,100 --> 00:10:06,950
Because, it's really going to be used for
collisions outside of this class.

156
00:10:06,950 --> 00:10:11,238
And we can call this property anything we
want and in fact we could calculate this

157
00:10:11,238 --> 00:10:13,350
property in here every time if we wanted

158
00:10:13,350 --> 00:10:16,860
to and because we have information hiding,
it's great.

159
00:10:16,860 --> 00:10:19,190
The consumer of this class doesn't care.

160
00:10:19,190 --> 00:10:23,510
All they care is they get a rectangle that
they can use to check collisions.

161
00:10:23,510 --> 00:10:26,401
So we've called this CollisionRectangle
here to hide the

162
00:10:26,401 --> 00:10:29,300
fact that it's also the draw rectangle
inside the class.

163
00:10:30,430 --> 00:10:34,910
Okay, so this is therefore a rectangle
object.

164
00:10:35,940 --> 00:10:38,592
We call the intersects method, you'd have
to

165
00:10:38,592 --> 00:10:42,580
go check the documentation but intersects
is a method.

166
00:10:42,580 --> 00:10:44,076
For the rectangle class,

167
00:10:44,076 --> 00:10:47,000
where we hand it another rectangle, and it
returns

168
00:10:47,000 --> 00:10:50,880
true if the rectangles intersect and false
if they don't.

169
00:10:50,880 --> 00:10:52,930
Which is exactly what we need.

170
00:10:52,930 --> 00:10:55,275
So if the rectangles intersect, and both

171
00:10:55,275 --> 00:10:58,430
bears are active, we're going to
deactivate the bears.

172
00:10:58,430 --> 00:11:00,600
We don't care about their collisions or
anything anymore.

173
00:11:01,660 --> 00:11:04,030
And we're going to play the explosion.

174
00:11:04,030 --> 00:11:06,696
And we're going to play the explosion
approximately

175
00:11:06,696 --> 00:11:09,960
at the point where the collision occurred.

176
00:11:09,960 --> 00:11:13,646
So this is actually a really good time for
us to

177
00:11:13,646 --> 00:11:19,680
go back and do an in lecture quiz about
what collision resolution.

178
00:11:19,680 --> 00:11:25,080
Needs because that's what this whole block
of code is, is collision resolution.

179
00:11:25,080 --> 00:11:26,980
THis is the detection part.

180
00:11:26,980 --> 00:11:30,280
Sorry, all three lines.
That's the detection part.

181
00:11:30,280 --> 00:11:31,590
That's the resolution part.

182
00:11:35,150 --> 00:11:39,090
Okay.
So now, we're going to play the explosion.

183
00:11:39,090 --> 00:11:42,262
You should look at the, I'm going to post
this code on the course

184
00:11:42,262 --> 00:11:45,620
website so you can just look at this part
of the code here.

185
00:11:45,620 --> 00:11:48,859
Basically, it figures out where the, where
the

186
00:11:48,859 --> 00:11:52,730
collision rectangle is, the whole overlap
between those

187
00:11:52,730 --> 00:11:56,285
two rectangles, you should read the
Intersect, not

188
00:11:56,285 --> 00:12:00,370
intersects with an s, the Intersect
without an s.

189
00:12:00,370 --> 00:12:03,230
Method documentation to see how that
works.

190
00:12:03,230 --> 00:12:05,260
And then we play this explosion.

191
00:12:06,920 --> 00:12:12,070
And that's all well and good, but what
does it mean to play the explosion?

192
00:12:13,120 --> 00:12:20,186
So let's actually step aback and think
about how animations work in 2-D games.

193
00:12:21,370 --> 00:12:27,400
So here on the right, you see something
called a sprite strip.

194
00:12:27,400 --> 00:12:34,530
It's a strip of frames for an animation
that we will use to play the animation.

195
00:12:34,530 --> 00:12:39,320
And given that cool term, sprite strip,
you should do another in-lecture quiz.

196
00:12:39,320 --> 00:12:42,080
So how do we actually use a sprite strip?

197
00:12:42,080 --> 00:12:44,642
Conceptually, before we look at the code,
how do

198
00:12:44,642 --> 00:12:48,350
we use this sprite strip to actually play
an animation?

199
00:12:48,350 --> 00:12:53,330
Well, clearly, we don't put a
semi-transparent, magenta box over it.

200
00:12:53,330 --> 00:12:58,150
However, that's just for us to look at how
we really play animations.

201
00:12:58,150 --> 00:13:02,770
And the way we really play animations is,
this is just a seqeunce of frames.

202
00:13:02,770 --> 00:13:07,780
And what we want to do is we want to
display the zeroeth frame for a while.

203
00:13:08,910 --> 00:13:12,720
And then when we should move on, we want
to move on to the first frame.

204
00:13:14,000 --> 00:13:16,001
And then once we should move on, we

205
00:13:16,001 --> 00:13:18,485
want to move on to the second frame, and
then

206
00:13:18,485 --> 00:13:21,830
to the third frame, and so on throughout
the animation.

207
00:13:21,830 --> 00:13:23,770
So what we do is.

208
00:13:23,770 --> 00:13:29,190
We display a particular portion of the
sprite strip for some period of time.

209
00:13:30,270 --> 00:13:32,070
And then we move on to the next one, and
move on to

210
00:13:32,070 --> 00:13:34,460
the next one, and move on to the next one,
and so on.

211
00:13:34,460 --> 00:13:37,320
So that's the idea behind playing
animations.

212
00:13:37,320 --> 00:13:43,620
And it turns out that this magenta thing
right here, that I've been moving

213
00:13:43,620 --> 00:13:46,220
over different parts.

214
00:13:46,220 --> 00:13:49,583
Of this texture 2Dm because that's what
it's going to be, it's going to be

215
00:13:49,583 --> 00:13:54,050
a texture 2D we load into our game, is
something called a source rectangle.

216
00:13:54,050 --> 00:13:55,690
So let's go take a look in the code
itself.

217
00:13:59,500 --> 00:14:02,480
So we need to go to the explosion class in
this particular case.

218
00:14:05,060 --> 00:14:10,200
And make it bigger.
And what we're going to care about.

219
00:14:10,200 --> 00:14:12,050
We'll look at a number of different
things.

220
00:14:12,050 --> 00:14:13,090
We have a drawRectangle.

221
00:14:13,090 --> 00:14:16,000
That's where the explosion actually gets
drawn.

222
00:14:16,000 --> 00:14:16,920
Here's the strip name.

223
00:14:16,920 --> 00:14:18,270
I just have one explosion.

224
00:14:18,270 --> 00:14:21,170
The Texture2D for the explosion, like I
said.

225
00:14:21,170 --> 00:14:23,020
We keep track of frame-within-frame
height.

226
00:14:23,020 --> 00:14:25,060
We're not going to cover all the details
in

227
00:14:25,060 --> 00:14:27,160
this class, but you can look at it later.

228
00:14:29,120 --> 00:14:30,272
And here's the key

229
00:14:30,272 --> 00:14:33,660
part based on the conceptual stuff I was
talking about.

230
00:14:33,660 --> 00:14:36,306
We have the source tan, rectangle, that
magenta

231
00:14:36,306 --> 00:14:39,620
rectangle we move around on the sprite
strip.

232
00:14:39,620 --> 00:14:45,080
We keep track of our current frame, we
keep track of how long we want each frame

233
00:14:45,080 --> 00:14:51,290
to last, and we keep track of how long
we've been showing the current frame.

234
00:14:51,290 --> 00:14:55,479
So there's this sort of deeper, more
generally applicaple idea here

235
00:14:55,479 --> 00:14:58,540
that we're going to sort of have a timer.

236
00:14:58,540 --> 00:15:00,550
And when the timer goes off, we're

237
00:15:00,550 --> 00:15:03,480
going to do something and restart the
timer.

238
00:15:03,480 --> 00:15:07,456
In this particular case, what's going to
happen is, when the timer goes off, we're

239
00:15:07,456 --> 00:15:11,540
going to move to the next frame in the
animation, and start the timer again.

240
00:15:11,540 --> 00:15:14,940
So that we know when it's time to move on
to the next frame, and so on.

241
00:15:14,940 --> 00:15:18,090
But, the approach we're going to use,
which is an update.

242
00:15:18,090 --> 00:15:20,636
Is going to be generally applicable
whenever

243
00:15:20,636 --> 00:15:21,690
you need a timer.

244
00:15:22,900 --> 00:15:27,660
Okay, so we're only going to update if
it's playing, this is a Boolean variable.

245
00:15:27,660 --> 00:15:29,020
And here's what we do.

246
00:15:29,020 --> 00:15:34,124
We take the elapsed frame time, how long
the animation frame has been

247
00:15:34,124 --> 00:15:39,040
playing so far.
And we take this game time parameter.

248
00:15:40,270 --> 00:15:46,980
And we extract from it the ElapsedGameTime
since update was last called.

249
00:15:46,980 --> 00:15:52,000
So this is sort of the delta between the
last time update was called and this time.

250
00:15:53,370 --> 00:15:56,594
And we'll convert that or extract the
milliseconds property

251
00:15:56,594 --> 00:16:00,740
which will tell us exactly how many
milliseconds it's been.

252
00:16:00,740 --> 00:16:04,430
With a fixed frame rate, it's going to be
16 milliseconds all the time.

253
00:16:04,430 --> 00:16:07,210
But it's worth checking just in case.

254
00:16:07,210 --> 00:16:09,694
If you write your code generally
applicable this way,

255
00:16:09,694 --> 00:16:11,962
then it will work whether you're running
fix time

256
00:16:11,962 --> 00:16:13,710
step or not.
Okay.

257
00:16:13,710 --> 00:16:17,820
So we add to the ElapsedFrameTime.
And here's, wow, another if statement.

258
00:16:19,070 --> 00:16:23,890
If the ElapsedFrameTime is greater than
how long we should show each frame.

259
00:16:23,890 --> 00:16:26,640
It means, it's time to move on to the next
frame.

260
00:16:27,760 --> 00:16:32,464
So we reset the frame timer, because now
we're starting

261
00:16:32,464 --> 00:16:37,012
to display a new frame, and we advance the
animation.

262
00:16:37,012 --> 00:16:40,260
And we advance the animation with another
if statement, just to make

263
00:16:40,260 --> 00:16:43,940
sure we don't try to run past the end of
the sprite strip.

264
00:16:43,940 --> 00:16:47,240
So we set the current frame while we check
to see if the

265
00:16:47,240 --> 00:16:51,870
current frame is less than num frames
minus 1 because it's zero based.

266
00:16:53,720 --> 00:16:56,930
If it is, there's another frame to show.

267
00:16:56,930 --> 00:17:02,114
So we add one to the current frame counter
and then we call this method that you

268
00:17:02,114 --> 00:17:04,350
can go look at on your own.

269
00:17:04,350 --> 00:17:09,490
But this method right here is the thing
that moves that magenta rectangle.

270
00:17:11,130 --> 00:17:14,840
So that's what happens if there's still
more frames to show.

271
00:17:14,840 --> 00:17:19,366
If there aren't, here's the else part, if
there aren't, we set playing to false,

272
00:17:19,366 --> 00:17:26,390
because we're done showing the animation.
So, one more in-lecture quiz for you.

273
00:17:31,280 --> 00:17:35,930
And to recap, we looked at numerous
different uses of the if statement here.

274
00:17:35,930 --> 00:17:38,465
We looked at bouncing, we looked at
collision

275
00:17:38,465 --> 00:17:41,260
detection We looked at how we can play
animations,

276
00:17:41,260 --> 00:17:44,380
and this particular case is part of
collision resolution

277
00:17:44,380 --> 00:17:47,530
but we could do it sort of anytime we
want.

278
00:17:47,530 --> 00:17:49,558
There are actually some other if
statements in

279
00:17:49,558 --> 00:17:51,534
there as well that you may have noticed
that,

280
00:17:51,534 --> 00:17:53,198
you know, if something is active we do

281
00:17:53,198 --> 00:17:56,190
something, if the animation was playing we
update it.

282
00:17:56,190 --> 00:18:01,536
So, we saw a whole bunch of different
ways, that we can use selection in actual

283
00:18:01,536 --> 00:18:07,000
game scenarios, where there's very small,
still no user interaction game.

284
00:18:08,540 --> 00:18:10,508
Good news, we're at the end of module
seven.

285
00:18:10,508 --> 00:18:16,228
Even better news, in module eight, we'll
finally start learning how to get

286
00:18:16,228 --> 00:18:21,880
user input in an XNA game so that the
player can interact with the game world.