game.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /// <reference path="audio.ts" />
  2. /// <reference path="background.ts" />
  3. /// <reference path="game/common.ts" />
  4. /// <reference path="game/loading.ts" />
  5. namespace game {
  6. export class MainController extends ScreenManager {
  7. loadingScreen: Screen;
  8. constructor(container: HTMLElement, configUrl: string) {
  9. super(container);
  10. let self = this;
  11. let bgLayer: HTMLElement = container.querySelector('#background');
  12. let gameContext: GameContext = {
  13. container: container,
  14. audioManager: new audio.AudioManager(),
  15. bgManager: new background.BackgroundManager(bgLayer),
  16. assets: null,
  17. config: null,
  18. switchScreen(screen: Screen): void {
  19. self.switchScreen(screen);
  20. }
  21. }
  22. this.loadingScreen = new LoadingScreen(gameContext, configUrl);
  23. document.addEventListener('keydown', (event) => {
  24. if (!event.ctrlKey && !event.metaKey) {
  25. this.activeScreen.handleInput(event.key);
  26. }
  27. });
  28. }
  29. start(): void {
  30. this.switchScreen(this.loadingScreen);
  31. }
  32. }
  33. }