Skip to content

Instantly share code, notes, and snippets.

@christopher4lis
Created February 1, 2022 17:54
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save christopher4lis/452bc4442208e3123e6abf69458081df to your computer and use it in GitHub Desktop.
Save christopher4lis/452bc4442208e3123e6abf69458081df to your computer and use it in GitHub Desktop.
Chris Courses Pacman Tutorial: Pre-built map, loop, and switch case statement
const map = [
['1', '-', '-', '-', '-', '-', '-', '-', '-', '-', '2'],
['|', '.', '.', '.', '.', '.', '.', '.', '.', '.', '|'],
['|', '.', 'b', '.', '[', '7', ']', '.', 'b', '.', '|'],
['|', '.', '.', '.', '.', '_', '.', '.', '.', '.', '|'],
['|', '.', '[', ']', '.', '.', '.', '[', ']', '.', '|'],
['|', '.', '.', '.', '.', '^', '.', '.', '.', '.', '|'],
['|', '.', 'b', '.', '[', '+', ']', '.', 'b', '.', '|'],
['|', '.', '.', '.', '.', '_', '.', '.', '.', '.', '|'],
['|', '.', '[', ']', '.', '.', '.', '[', ']', '.', '|'],
['|', '.', '.', '.', '.', '^', '.', '.', '.', '.', '|'],
['|', '.', 'b', '.', '[', '5', ']', '.', 'b', '.', '|'],
['|', '.', '.', '.', '.', '.', '.', '.', '.', 'p', '|'],
['4', '-', '-', '-', '-', '-', '-', '-', '-', '-', '3']
]
// Additional cases (does not include the power up pellet that's inserted later in the vid)
map.forEach((row, i) => {
row.forEach((symbol, j) => {
switch (symbol) {
case '-':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeHorizontal.png')
})
)
break
case '|':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeVertical.png')
})
)
break
case '1':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeCorner1.png')
})
)
break
case '2':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeCorner2.png')
})
)
break
case '3':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeCorner3.png')
})
)
break
case '4':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/pipeCorner4.png')
})
)
break
case 'b':
boundaries.push(
new Boundary({
position: {
x: Boundary.width * j,
y: Boundary.height * i
},
image: createImage('./img/block.png')
})
)
break
case '[':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/capLeft.png')
})
)
break
case ']':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/capRight.png')
})
)
break
case '_':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/capBottom.png')
})
)
break
case '^':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/capTop.png')
})
)
break
case '+':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/pipeCross.png')
})
)
break
case '5':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
color: 'blue',
image: createImage('./img/pipeConnectorTop.png')
})
)
break
case '6':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
color: 'blue',
image: createImage('./img/pipeConnectorRight.png')
})
)
break
case '7':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
color: 'blue',
image: createImage('./img/pipeConnectorBottom.png')
})
)
break
case '8':
boundaries.push(
new Boundary({
position: {
x: j * Boundary.width,
y: i * Boundary.height
},
image: createImage('./img/pipeConnectorLeft.png')
})
)
break
case '.':
pellets.push(
new Pellet({
position: {
x: j * Boundary.width + Boundary.width / 2,
y: i * Boundary.height + Boundary.height / 2
}
})
)
break
}
})
})
@Tomasmoralessp
Copy link

Thxx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment