Created
November 17, 2022 15:04
-
-
Save lajbel/9f178664b17df2096d0fbb5cee083234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Key, KaboomCtx } from "kaboom"; | |
import "kaboom/global"; | |
export interface GlobalInputPlugin { | |
setupInput(inputKeys: { [key: string]: Key }, isDebug: boolean): void; | |
getKey(alias: string): Key; | |
getGlobalInput(): any; | |
} | |
declare global { | |
const setupInput: GlobalInputPlugin["setupInput"]; | |
const getKey: GlobalInputPlugin["getKey"]; | |
const getGlobalInput: GlobalInputPlugin["getGlobalInput"]; | |
} | |
export default function globalInput(_k: KaboomCtx): GlobalInputPlugin { | |
let keys: { [key: string]: Key }; | |
return { | |
setupInput(inputKeys, _isDebug) { | |
keys = inputKeys; | |
}, | |
getKey(alias): Key { | |
return keys[alias]; | |
}, | |
getGlobalInput() { | |
return keys; | |
} | |
} | |
} | |
// use: | |
// load input | |
setupInput({ | |
"move_up": "up", | |
"move_down": "down", | |
"move_left": "left", | |
"move_right": "right", | |
"get_obj": "e", | |
"rotate_obj": "q", | |
"misc_auto_rotate": "rotate", | |
}); | |
// use | |
onKeyDown(getKey("move_right"), () => { | |
ranib.move(RIGHT.scale(ranib.speed)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment