base2020/src/Game/Input.ts

24 lines
518 B
TypeScript
Raw Normal View History

2020-02-16 04:15:59 +00:00
import { KeyHandler, KeyName } from "../Applet/Keyboard";
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();
}
}