-
-
Save christopher4lis/452bc4442208e3123e6abf69458081df to your computer and use it in GitHub Desktop.
Chris Courses Pacman Tutorial: Pre-built map, loop, and switch case statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thxx!