Skip to content

Commit c753962

Browse files
committed
Section 22: Adding a Win Animation
1 parent 7b18650 commit c753962

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

22-Javascript-with-the-Canvas-API/02-Maze copy/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Matter.js library
22
const { Engine, Render, Runner, World, Bodies, Body, Events } = Matter
33

4-
const cells = 3
4+
const cells = 6
55
const width = 600
66
const height = 600
77

@@ -140,6 +140,7 @@ horizontals.forEach((row, rowIndex) => {
140140
unitLength,
141141
10,
142142
{
143+
label: 'wall',
143144
isStatic: true,
144145
}
145146
)
@@ -158,7 +159,8 @@ verticals.forEach((row, rowIndex) => {
158159
rowIndex * unitLength + unitLength / 2,
159160
10,
160161
unitLength,
161-
{
162+
{
163+
label: 'wall',
162164
isStatic: true,
163165
}
164166
)
@@ -220,7 +222,14 @@ Events.on(engine, 'collisionStart', (event) => {
220222
labels.includes(collision.bodyA.label) &&
221223
labels.includes(collision.bodyB.label)
222224
) {
223-
console.log('User won!')
225+
// console.log('User won!')
226+
// alert('User won!')
227+
world.gravity.y = 1
228+
world.bodies.forEach((body) => {
229+
if(body.label === 'wall') {
230+
Body.setStatic(body, false)
231+
}
232+
})
224233
}
225234
})
226235
})

22-Javascript-with-the-Canvas-API/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ console.log(grid)
8989

9090
## 25. 29 Disabling Gravity
9191

92-
## 26. 30 Detecting a Win
92+
## 26. 30 Detecting a Win
93+
94+
## 27. 31 Adding a Win Animation

0 commit comments

Comments
 (0)