Skip to content

Commit 43abbab

Browse files
committed
Section 22: Drawing Horizontal Segments
1 parent 10be00c commit 43abbab

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const cells = 3
55
const width = 600
66
const height = 600
77

8+
const unitLength = width / cells
9+
810
const engine = Engine.create()
911
const { world } = engine
1012
const render = Render.create({
@@ -122,12 +124,21 @@ stepThroughCell(startRow, startColumn)
122124
// console.log(horizontals);
123125

124126

125-
horizontals.forEach((row) => {
126-
row.forEach((open) => {
127+
horizontals.forEach((row, rowIndex) => {
128+
row.forEach((open, columnIndex) => {
127129
if(open === true) {
128130
return
129131
}
130132

131-
const wall = Bodies.rectangle()
133+
const wall = Bodies.rectangle(
134+
columnIndex * unitLength + unitLength / 2,
135+
rowIndex * unitLength + unitLength,
136+
unitLength,
137+
10,
138+
{
139+
isStatic: true,
140+
}
141+
)
142+
World.add(world, wall)
132143
})
133144
})

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

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

7474
## 17. 21 Validating Wall Structure
7575

76-
## 18. 22 Iterating Over Walls
76+
## 18. 22 Iterating Over Walls
77+
78+
## 19. 23 Drawing Horizontal Segments

0 commit comments

Comments
 (0)