Added the bricks (and improve the bouncing)

This commit is contained in:
2021-11-14 23:49:49 +01:00
parent 0f4a403edb
commit 7493713529
12 changed files with 303 additions and 111 deletions

24
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];
}
}