Skip to content

Commit fad20a5

Browse files
Normalize vector before reflecting for bat bounce. (#173)
Co-authored-by: Simon (Darkside) Jackson <[email protected]>
1 parent 02e9564 commit fad20a5

File tree

12 files changed

+14
-5
lines changed

12 files changed

+14
-5
lines changed

articles/tutorials/building_2d_games/12_collision_detection/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ If you run the game right now and move the slime around, you will notice a few i
311311

312312
We can now implement these features using collision detection and response in our game. In the *DungeonSlime* project (your main game project), open the `Game1.cs` file and make the following changes to the `Game1` class:
313313

314-
[!code-csharp[](./snippets/game1.cs?highlight=1,5,25-29,40-45,76–176,181–193,293–294)]
314+
[!code-csharp[](./snippets/game1.cs?highlight=1,5,25-29,40-45,76–177,182–194,294–295)]
315315

316316
The key changes made here are:
317317

articles/tutorials/building_2d_games/12_collision_detection/snippets/game1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ protected override void Update(GameTime gameTime)
151151
// normal.
152152
if (normal != Vector2.Zero)
153153
{
154+
normal.Normalize();
154155
_batVelocity = Vector2.Reflect(_batVelocity, normal);
155156
}
156157

articles/tutorials/building_2d_games/13_working_with_tilemaps/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ This tilemap configuration creates a simple dungeon layout with walls around the
186186

187187
With all of the assets now in place and configured, we can update the `Game1` class to load the tilemap and draw it. We will also need to update the collision logic so that the boundary is no longer the edge of the screen, but instead the edges of the wall tiles of the tilemap. Open `Game1.cs` and make the following updates:
188188

189-
[!code-csharp[](./snippets/game1.cs?highlight=31-35,46-61,80-82,109,111,113,125,118,120,122,124,142,145,147,150,153,156,158,161,176–178,300–301)]
189+
[!code-csharp[](./snippets/game1.cs?highlight=31-35,46-61,80-82,109,111,113,125,118,120,122,124,142,145,147,150,153,156,158,161,177–179,301–302)]
190190

191191
The key changes to the `Game1` class include:
192192

articles/tutorials/building_2d_games/13_working_with_tilemaps/snippets/game1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ protected override void Update(GameTime gameTime)
166166
// normal.
167167
if (normal != Vector2.Zero)
168168
{
169+
normal.Normalize();
169170
_batVelocity = Vector2.Reflect(_batVelocity, normal);
170171
}
171172

articles/tutorials/building_2d_games/14_soundeffects_and_music/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Add these files to your content project using the MGCB Editor:
175175

176176
Next, open the `Game1.cs` file and update it to the following:
177177

178-
[!code-csharp[](./snippets/game1.cs?highlight=3,6,39-43,92-111,200-201,219-220)]
178+
[!code-csharp[](./snippets/game1.cs?highlight=3,6,39-43,92-111,201-202,220-221)]
179179

180180
The key changes here are:
181181

articles/tutorials/building_2d_games/14_soundeffects_and_music/snippets/game1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ protected override void Update(GameTime gameTime)
195195
// normal.
196196
if (normal != Vector2.Zero)
197197
{
198+
normal.Normalize();
198199
_batVelocity = Vector2.Reflect(_batVelocity, normal);
199200

200201
// Play the bounce sound effect

articles/tutorials/building_2d_games/15_audio_controller/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ The key changes made here are:
131131

132132
Next, update the `Game1` class to use the audio controller for audio playback. Open `Game1.cs` and make the following updates:
133133

134-
[!code-csharp[](./snippets/game1.cs?highlight=45-46,77-78,104-105,194–195,213–214,267–285)]
134+
[!code-csharp[](./snippets/game1.cs?highlight=45-46,77-78,104-105,195–196,214–215,268–286)]
135135

136136
> [!NOTE]
137137
> Note there were a lot of replacements in the `LoadContent` method, switching from loading and initializing the background Song and replacing it with a call to the new `AudioController` to do all the work managing the Song reference. Much cleaner.

articles/tutorials/building_2d_games/15_audio_controller/snippets/game1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ protected override void Update(GameTime gameTime)
189189
// normal.
190190
if (normal != Vector2.Zero)
191191
{
192+
normal.Normalize();
192193
_batVelocity = Vector2.Reflect(_batVelocity, normal);
193194

194195
// Play the bounce sound effect.

articles/tutorials/building_2d_games/16_working_with_spritefonts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ The key changes here are:
217217

218218
Finally, open the `Game1.cs` file and make the following changes:
219219

220-
[!code-csharp[](./snippets/game1.cs?highlight=48-58,93-99,129-130,240-241,385-396)]
220+
[!code-csharp[](./snippets/game1.cs?highlight=48-58,93-99,129-130,241-242,386-397)]
221221

222222
The key changes made are:
223223

articles/tutorials/building_2d_games/16_working_with_spritefonts/snippets/game1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ protected override void Update(GameTime gameTime)
213213
// normal.
214214
if (normal != Vector2.Zero)
215215
{
216+
normal.Normalize();
216217
_batVelocity = Vector2.Reflect(_batVelocity, normal);
217218

218219
// Play the bounce sound effect.

0 commit comments

Comments
 (0)