GameView.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. import { FiniteStateMachine } from "../libraries/FiniteStateMachine.js";
  2. import { MainMenuState, DigState, UpgradeState, ShopState, CreditsState, StoryUpdateState } from "./states/index.js";
  3. export class GameView {
  4. constructor(viewElement) {
  5. this.element = viewElement
  6. this.stateMachine = new FiniteStateMachine();
  7. this.stateMachine.registerState("mainmenu", new MainMenuState(this))
  8. this.stateMachine.registerState("storyupdate", new StoryUpdateState(this))
  9. this.stateMachine.registerState("dig", new DigState(this))
  10. this.stateMachine.registerState("upgrade", new UpgradeState(this))
  11. this.stateMachine.registerState("shop", new ShopState(this))
  12. this.stateMachine.registerState("credits", new CreditsState(this))
  13. }
  14. async init(scaledCanvas) {
  15. this.stateMachine.getAllStates().forEach(state => { state.init(scaledCanvas) })
  16. this.stateMachine.setCurrentState("mainmenu");
  17. this.scaledCanvas = scaledCanvas
  18. this.stateMachine.getCurrentState().enter();
  19. }
  20. draw(ctx, scaledCanvas) {
  21. this.stateMachine.getCurrentState().draw(ctx, scaledCanvas);
  22. }
  23. update(delta) {
  24. this.stateMachine.getCurrentState().update(delta);
  25. }
  26. }