changed ball and bar for a sprite

This commit is contained in:
2021-11-16 22:01:43 +01:00
parent e0ebef2a27
commit bc3ef31728
17 changed files with 77 additions and 24 deletions

24
assets/js/Keyboard.js Normal file
View File

@ -0,0 +1,24 @@
class Keyboard {
constructor(onKeydown) {
this._pressed = {};
this.cb_onKeydown = onKeydown;
window.addEventListener('keydown', e => this.onKeydown(e));
window.addEventListener('keyup', e => this.onKeyup(e));
}
setKeydown(fn) {
this.cb_onKeydown = fn;
}
isDown(keyCode) {
return this._pressed[keyCode];
}
onKeydown(event) {
this._pressed[event.code] = true;
if (this.cb_onKeydown) this.cb_onKeydown(event);
}
onKeyup(event) {
delete this._pressed[event.code];
}
}