Created
December 22, 2018 03:54
-
-
Save SethuSenthil/9b47277dcda8152382532afea1e54837 to your computer and use it in GitHub Desktop.
Game Controls JS --> A simple game controls boiler plate using javascript event codes
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
window.addEventListener("keydown", function(event) { | |
let key = event.code; | |
if(key === 'ArrowUp' || key === 'KeyW' /*|| key === 'Space'*/){ | |
//jump up | |
}else if(key === 'ArrowDown' || key === 'KeyS'){ | |
//go down | |
}else if(key === 'ArrowRight' || key === 'KeyD'){ | |
//move right | |
}else if(key === 'ArrowLeft' || key === 'KeyA'){ | |
//move left | |
}else if(key === 'Space'){ | |
//shoot | |
}else if(key === 'Escape'){ | |
//settings | |
} | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment