Source: app03/app.js

/**
 * @author    Wolfgang Kowarschick <kowa@hs-augsburg.de>
 * @copyright 2017 - 2018
 * @license   CC-BY-NC-SA-4.0
 */

/**
 * @module app03/app
 */

import                             '/css/app.css';
import wait                   from '/wk/util/wait';
import GameLoop               from '/wk/game/GameLoop';
import {loader, Application}  from 'pixi.js';
import loadResources          from '/wk_pixi/loader/loadResources';

import config                 from './config/config.json';
import concretize             from '/wk/config/concretize';

import ModelStage             from './model/ModelStage';
import ModelCircle            from './model/ModelCircle';
import {initUpdater, update}  from './model/update';

import ViewCircleSprite       from './view/ViewCircleSprite';
import {initRenderer, render} from './view/render';
import imgOwl                 from '/img/owl-150.png';
import imgTux                 from '/img/tux-150.png';

loader
  .add('imgTux', imgTux)
  .add('imgOwl', imgOwl);

const
  c_view_stage
    = document.getElementById('stage'),

  c_pixi_app =
    new Application
        ( document.documentElement.clientWidth,
          document.documentElement.clientHeight,
          { transparent: true,
            view:        c_view_stage
          }
        ),
  
  c_model_stage =
    new ModelStage(concretize
                   ({config:      config.model.stage,
                     environment:
                     { '@right':  document.documentElement.clientWidth,
                       '@bottom': document.documentElement.clientHeight
                     }
                   })
                  ),
  
  c_model_ball =
    new ModelCircle(config.model.ball);

initUpdater({stage: c_model_stage, circle: c_model_ball});

async function init()
{ const
    c_resources =
      await loadResources(),
    c_view_ball =
      new ViewCircleSprite
          (c_pixi_app, c_model_ball, config.view.ball, c_resources);
  
  initRenderer([c_view_ball]);
  
  c_view_stage.classList.remove('hidden');
  await wait(500);
  new GameLoop({update: update, render: render}).start();
}

window.addEventListener('load', init);