base2020/src/game/Input.ts

24 lines
518 B
TypeScript
Raw Permalink Normal View History

import { KeyHandler, KeyName } from "../applet/Keyboard";
2020-02-16 04:15:59 +00:00
export class Buttons implements KeyHandler {
keys: KeyName[] = [];
public update(key: KeyName, state: "press" | "release") {
const newKeys = this.keys.filter(k => k != key);
if(state == "press") {
newKeys.push(key);
newKeys.sort();
}
this.keys = newKeys;
}
public block() {
this.keys = [];
}
public getPressed(): KeyName[] {
return this.keys.slice();
}
}