Advertisement
ezmash

Fog (MV)

Oct 31st, 2015
770
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Fog
  3. // by Shaz
  4. // Last Updated: 2015.10.31
  5. //=============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Adds a fog overlay to maps
  9.  * @author Shaz
  10.  *
  11.  * @help
  12.  *
  13.  * Plugin Command:
  14.  *   ChangeFog filename scroll-x scroll-y opacity
  15.  *
  16.  *   filename = name of file (no extension) in img/fogs folder
  17.  *   scroll-x, scroll-y = amount to scroll each frame (-ve is up/left)
  18.  *                        could be a number or a formula
  19.  *   opacity = fog opacity (0-255)
  20.  *
  21.  */
  22.  
  23. (function() {
  24.   var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  25.   Game_Interpreter.prototype.pluginCommand = function(command, args) {
  26.     _Game_Interpreter_pluginCommand.call(this, command, args);
  27.  
  28.     if (command.toUpperCase() === 'CHANGEFOG') {
  29.       $gameMap.changeFog(args);
  30.     };
  31.   };
  32.  
  33.   ImageManager.loadFog = function(filename, hue) {
  34.     return this.loadBitmap('img/fogs/', filename, hue, true);
  35.   };
  36.  
  37.   var _Game_Map_initialize = Game_Map.prototype.initialize;
  38.   Game_Map.prototype.initialize = function() {
  39.     _Game_Map_initialize.call(this);
  40.     this._fogName = '';
  41.     this._fogSx = 0;
  42.     this._fogSy = 0;
  43.     this._fogOpacity = 0;
  44.     this._fogX = 0;
  45.     this._fogY = 0;
  46.   };
  47.  
  48.   var _Game_Map_setup = Game_Map.prototype.setup;
  49.   Game_Map.prototype.setup = function(mapId) {
  50.     _Game_Map_setup.call(this, mapId);
  51.     this.setupFog();
  52.   };
  53.  
  54.   Game_Map.prototype.setupFog = function() {
  55.     this._fogName = $dataMap.meta.fogName || '';
  56.     this._fogSx = Number($dataMap.meta.fogSx || 0);
  57.     this._fogSy = Number($dataMap.meta.fogSy || 0);
  58.     this._fogOpacity = Number($dataMap.meta.fogOpacity || 0);
  59.     this._fogX = 0;
  60.     this._fogY = 0;
  61.   };
  62.  
  63.   Game_Map.prototype.changeFog = function(args) {
  64.     this._fogName = args[0];
  65.     this._fogSx = eval(args[1]);
  66.     this._fogSy = eval(args[2]);
  67.     this._fogOpacity = eval(args[3]);
  68.   };
  69.  
  70.   var _Game_Map_setDisplayPos = Game_Map.prototype.setDisplayPos;
  71.   Game_Map.prototype.setDisplayPos = function(x, y) {
  72.     _Game_Map_setDisplayPos.call(this, x, y);
  73.     if (this.isLoopHorizontal()) {
  74.       this._fogX = x;
  75.     } else {
  76.       this._fogX = this._displayX;
  77.     }
  78.  
  79.     if (this.isLoopVertical()) {
  80.       this._fogY = y;
  81.     } else {
  82.       this._fogY = this._displayY;
  83.     }
  84.   };
  85.  
  86.   Game_Map.prototype.fogOx = function() {
  87.     return this._fogX * this.tileWidth() / 2;
  88.   };
  89.  
  90.   Game_Map.prototype.fogOy = function() {
  91.     return this._fogY * this.tileHeight() / 2;
  92.   };
  93.  
  94.   Game_Map.prototype.fogName = function() {
  95.     return this._fogName;
  96.   };
  97.  
  98.   Game_Map.prototype.fogOpacity = function() {
  99.     return this._fogOpacity;
  100.   };
  101.  
  102.   var _Game_Map_update = Game_Map.prototype.update;
  103.   Game_Map.prototype.update = function(sceneActive) {
  104.     _Game_Map_update.call(this, sceneActive);
  105.     this.updateFog();
  106.   };
  107.  
  108.   Game_Map.prototype.updateFog = function() {
  109.     this._fogX += this._fogSx / this.tileWidth() / 2;
  110.     this._fogY += this._fogSy / this.tileHeight() / 2;
  111.   };
  112.  
  113.   var _Spriteset_Map_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
  114.   Spriteset_Map.prototype.createLowerLayer = function() {
  115.     _Spriteset_Map_createLowerLayer.call(this);
  116.     this.createFog();
  117.   };
  118.  
  119.   var _Spriteset_Map_update = Spriteset_Map.prototype.update;
  120.   Spriteset_Map.prototype.update = function() {
  121.     _Spriteset_Map_update.call(this);
  122.     this.updateFog();
  123.   };
  124.  
  125.   Spriteset_Map.prototype.createFog = function() {
  126.     this._fog = new TilingSprite();
  127.     this._fog.move(0, 0, Graphics.width, Graphics.height);
  128.     this._baseSprite.addChild(this._fog);
  129.   };
  130.  
  131.   Spriteset_Map.prototype.updateFog = function() {
  132.     if (this._fogName !== $gameMap.fogName()) {
  133.       this._fogName = $gameMap.fogName();
  134.       this._fog.bitmap = ImageManager.loadFog(this._fogName);
  135.     }
  136.     if (this._fog.bitmap) {
  137.       this._fog.origin.x = $gameMap.fogOx();
  138.       this._fog.origin.y = $gameMap.fogOy();
  139.       this._fog.opacity = $gameMap.fogOpacity();
  140.     }
  141.   };
  142.  
  143. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement