52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
function getKeystroke() {
|
|
_listener = function (event) {
|
|
if (
|
|
["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf(
|
|
event.code,
|
|
) > -1
|
|
) {
|
|
event.preventDefault();
|
|
}
|
|
|
|
if (['h', 'a' 'ArrowLeft'].includes(event.key)) {
|
|
player.move('left')
|
|
} else if (['j', 's' 'ArrowDown'].includes(event.key)) {
|
|
player.move('down')
|
|
} else if (['k', 'w' 'ArrowUp'].includes(event.key)) {
|
|
player.move('up')
|
|
} else if (['l', 'd' 'ArrowRight'].includes(event.key)) {
|
|
player.move('right')
|
|
} else if (
|
|
event.key === "Enter" &&
|
|
!terminal.active
|
|
) {
|
|
var playerPosition = [player.canvasX, player.canvasY]
|
|
if (player.direction === 'up') {
|
|
if (computerInteractionZones.some(a => playerPosition.every((v, i) => v === a[i]))) {
|
|
terminal.show();
|
|
}
|
|
if (gamesInteractionZones.some(a => playerPosition.every((v, i) => v === a[i]))) {
|
|
games.show();
|
|
}
|
|
if (portfolioInteractionZones.some(a => playerPosition.every((v, i) => v === a[i]))) {
|
|
portfolio.show();
|
|
}
|
|
}
|
|
|
|
if (player.direction === 'down' || player.direction === 'left') {
|
|
if (musicInteractionZones.some(a => playerPosition.every((v, i) => v === a[i]))) {
|
|
music.show();
|
|
}
|
|
}
|
|
|
|
if (player.direction === 'down' || player.direction === 'up') {
|
|
if (resumeInteractionZones.some(a => playerPosition.every((v, i) => v === a[i]))) {
|
|
indicator.hide('resume');
|
|
indicator.resumeIndicatorShown = true;
|
|
resume.show()
|
|
}
|
|
}
|
|
}
|
|
};
|
|
document.addEventListener("keydown", _listener);
|
|
}
|