initial: dungeon crawler with Bun + TypeScript modular architecture
- 19 TypeScript modules under src/ (constants, entities, room, game, render) - Canvas 2D rendering with dark fantasy palette - Room-based navigation, random 7x7 map generation - Two combat modes: ranged (pistol) and melee (knife) - Wall collision with door opening support - Minimap, HP bar, enemy AI - Bun build pipeline: src/main.ts -> dist/main.js + dist/index.html
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// Global keyboard state (shared mutable map)
|
||||
export const KEYS: Record<string, boolean> = {};
|
||||
|
||||
export function setupInput(): void {
|
||||
window.addEventListener('keydown', (e: KeyboardEvent) => {
|
||||
KEYS[e.key] = true;
|
||||
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', ' '].includes(e.key)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
window.addEventListener('keyup', (e: KeyboardEvent) => {
|
||||
KEYS[e.key] = false;
|
||||
});
|
||||
window.addEventListener('blur', () => {
|
||||
// Reset all keys on window blur to avoid stuck keys
|
||||
for (const k in KEYS) delete KEYS[k];
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user