Advertisement
nio_kasgami

Scene_BaseConversion

May 11th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //-----------------------------------------------------------------------------
  2. // Scene_Base
  3. //
  4. // The superclass of all scenes within the game.
  5.  
  6. declare class Stage {}
  7. declare class WindowLayer {}
  8. declare class ScreenSprite {}
  9. declare var ImageManager;
  10. declare var AudioManager;
  11. declare var SceneManager;
  12. declare var Graphics;
  13. declare var $gameParty;
  14. declare var Scene_Gameover;
  15.  
  16.  
  17.  
  18. class Scene_Base extends Stage {
  19.  
  20.   private _active : boolean;
  21.   private _fadeSign : number;
  22.   private _fadeDuration : number;
  23.   private _fadeSprite : any;
  24.   private _windowLayer : any;
  25.   private addChild: any;
  26.   private children: any;
  27.  
  28.   constructor() {
  29.     super();
  30.     this._active = false;
  31.     this._fadeSign = 0;
  32.     this._fadeDuration = 0;
  33.     this._fadeSprite = null;
  34.   }
  35.  
  36.   create(){}
  37.  
  38.   isActive(){
  39.     return this._active;
  40.   }
  41.  
  42.   isReady(){
  43.     return ImageManager.isReady();
  44.   }
  45.  
  46.   start(){
  47.       this._active = true;
  48.   }
  49.  
  50.   update(){
  51.       this.updateFade();
  52.       this.updateChildren();
  53.       AudioManager.checkErrors();
  54.   }
  55.  
  56.   stop(){
  57.       this._active = false;
  58.   }
  59.  
  60.   isBusy(){
  61.       return this._fadeDuration > 0;
  62.   }
  63.  
  64.   terminate(){}
  65.  
  66.   createWindowLayer(){
  67.       let width = Graphics.boxWidth;
  68.       let height = Graphics.boxHeight;
  69.       let x = (Graphics.width - width) / 2;
  70.       let y = (Graphics.height - height) / 2;
  71.       this._windowLayer = new WindowLayer();
  72.       this._windowLayer.move(x, y, width, height);
  73.       this.addChild(this._windowLayer);
  74.   }
  75.  
  76.   addWindow(window : any){
  77.       this._windowLayer.addChild(window);
  78.   }
  79.  
  80.   startFadeIn(duration : any, white? : boolean){
  81.       this.createFadeSprite(white);
  82.       this._fadeSign = 1;
  83.       this._fadeDuration = duration || 30;
  84.       this._fadeSprite.opacity = 255;
  85.   }
  86.  
  87.   startFadeOut(duration : any, white? : boolean){
  88.       this.createFadeSprite(white);
  89.       this._fadeSign = -1;
  90.       this._fadeDuration = duration || 30;
  91.       this._fadeSprite.opacity = 0;
  92.   }
  93.  
  94.   createFadeSprite(white? : boolean){
  95.     if(!this._fadeSprite){
  96.         this._fadeSprite = new ScreenSprite();
  97.     }
  98.     if(white){
  99.         this._fadeSprite.setWhite();
  100.     } else {
  101.         this._fadeSprite.setBlack();
  102.     }
  103.   }
  104.  
  105.   updateFade(){
  106.     if(this._fadeDuration > 0){
  107.         let d = this._fadeDuration;
  108.         if(this._fadeSign > 0){
  109.             this._fadeSprite.opacity -= this._fadeSprite.opacity / d;
  110.         } else {
  111.             this._fadeSprite.opacity += (255 - this._fadeSprite.opacity) / d;
  112.         }
  113.         this._fadeDuration--;
  114.     }
  115.   }
  116.  
  117.   updateChildren(){
  118.       this.children.forEach(function(child) {
  119.         if(child.update){
  120.             child.update();
  121.         }
  122.       });
  123.   }
  124.  
  125.   popScene(){
  126.       SceneManager.pop();
  127.   }
  128.  
  129.   checkGameover(){
  130.     if($gameParty.isAllDead()){
  131.         SceneManager.goto(Scene_Gameover);
  132.     }
  133.   }
  134.  
  135.   fadeOutAll(){
  136.       let time = this.slowFadeSpeed() / 60;
  137.       AudioManager.fadeOutBgm(time);
  138.       AudioManager.fadeOutBgs(time);
  139.       AudioManager.fadeOutMe(time);
  140.  
  141.       this.startFadeOut(this.slowFadeSpeed());
  142.   }
  143.  
  144.   fadeSpeed(){
  145.       return 24;
  146.   }
  147.  
  148.   slowFadeSpeed(){
  149.       return this.fadeSpeed() * 2;
  150.   }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement