Skip to content

Instantly share code, notes, and snippets.

@SethuSenthil
Created December 22, 2018 03:54
Show Gist options
  • Save SethuSenthil/9b47277dcda8152382532afea1e54837 to your computer and use it in GitHub Desktop.
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
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