Advertisement
jerry2810

MiniMap

Nov 10th, 2015
2,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // MiniMap.js
  3. //=============================================================================
  4. //v1.0
  5. /*:
  6.  * @plugindesc Makes mini map.
  7.  * @author Jeremy Cannady
  8.  *
  9.  *@help YOU MUST HAVE A IMAGE OF YOUR MAP TO USE THIS, the image needs to be in /img/pictures and labled
  10.  *mapx.png where x is the map id number. So map #7 needs to be called map7.png
  11.  *Creates a mini map, 'o' is zoom out, 'L' is zoom in, 'I' is to increase transparency, 'K'
  12.  * is to decrease transparency. You must have the note tage <EnableMiniMap> in the map notes or it wont
  13.  * display the mini map.
  14.  *Plugin commands: AddIconToMiniMap 60 15 30 1  ---->where 60 is the icon index, 15 is the x, 30 is the y
  15.  * and 1 is whether or not it is activated. 1 is active and on map, 0 is not on map.
  16.  *UpdateIconOpacity 15 30 0 ---> where 15 is the x, 30 is the y, and 0 is the new activation. If 0 then it is
  17.  * turned off, if 1 then it is turned on. This only works if you have the correct x and y that the icon is at.
  18. */
  19.  
  20. //=============================================================================
  21. // Create variables and key mapping.
  22. //=============================================================================
  23. Game_Player.prototype.mapScale = 0.07;
  24. Game_Player.prototype.mapTransparency = 200;
  25. Input.keyMapper['79'] = 'ZoomIn';
  26. Input.keyMapper['76'] = 'ZoomOut';
  27. Input.keyMapper['73'] = 'TUP';
  28. Input.keyMapper['75'] = 'TDOWN';
  29. //=============================================================================
  30.  
  31. function Window_MiniMap() {
  32.     this.initialize.apply(this, arguments);
  33. }
  34.  
  35. Window_MiniMap.prototype = Object.create(Window_Base.prototype);
  36. Window_MiniMap.prototype.constructor = Window_MiniMap;
  37. //=============================================================================
  38. // Create variables.
  39. //=============================================================================
  40.     Window_MiniMap.prototype.mapIconData = {};
  41.     Window_MiniMap.prototype.bitmapIcon = [];
  42.     Window_MiniMap.prototype.updateAddIcon = true;
  43. //=============================================================================
  44.  
  45. var Add_Icon_To_MiniMap_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  46. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  47.     Add_Icon_To_MiniMap_pluginCommand.call(this, command, args);
  48.     if (command === "AddIconToMiniMap") {
  49.         var arg1 = JSON.parse(args[0]);
  50.         var arg2 = JSON.parse(args[1]);
  51.         var arg3 = JSON.parse(args[2]);
  52.         var arg4 = JSON.parse(args[3]);
  53.         Window_MiniMap.prototype.addIconToMap(arg1, arg2, arg3, arg4);
  54.     };
  55. };
  56.  
  57. Window_MiniMap.prototype.addIconToMap = function(iconIndex, x, y, opacity){
  58.     if(this.mapIconData[$gameMap._mapId].length > 0){
  59.         for(var i = 0; i < this.mapIconData[$gameMap._mapId].length; i++){
  60.             var array = this.mapIconData[$gameMap._mapId][i]
  61.             if(array[1] !== x && array[2] !== y){
  62.                 this.mapIconData[$gameMap._mapId].push([iconIndex, x, y, opacity])
  63.             };
  64.         };
  65.     }else{
  66.         this.mapIconData[$gameMap._mapId].push([iconIndex, x, y, opacity]);
  67.     };
  68. };
  69.  
  70. Window_MiniMap.prototype.updateIconOpacity = function(x, y, opacity){
  71.     for(var i = 0; i < this.mapIconData[$gameMap._mapId].length; i++){
  72.         var array = this.mapIconData[$gameMap._mapId][i]
  73.         if(array[1] === x && array[2] === y){
  74.             this.mapIconData[$gameMap._mapId][i][3] = opacity;
  75.         };
  76.     };
  77. };
  78.  
  79. var Icon_Opacity_Update_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  80. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  81.     Icon_Opacity_Update_pluginCommand.call(this, command, args);
  82.     if (command === "UpdateIconOpacity") {
  83.         var arg1 = JSON.parse(args[0]);
  84.         var arg2 = JSON.parse(args[1]);
  85.         var arg3 = JSON.parse(args[2]);
  86.         Window_MiniMap.prototype.updateIconOpacity(arg1, arg2, arg3);
  87.     };
  88. };
  89.  
  90. Window_MiniMap.prototype.initialize = function(x, y, width, height) {
  91.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  92.     if(!Window_MiniMap.prototype.mapIconData[$gameMap._mapId]){
  93.         this.mapIconData[$gameMap._mapId] = [];
  94.     }
  95.     this.deactivate();
  96.     this.addMapPNG();
  97.     this.addArrowPNG();
  98. };
  99.  
  100. //=============================================================================
  101. // Update everything...
  102. //=============================================================================
  103. Window_MiniMap.prototype.update = function() {
  104.  
  105.     Window_Base.prototype.update.call(this);
  106.     if(Input.isTriggered("ZoomIn")){$gamePlayer.mapScale += 0.01;};
  107.     if(Input.isTriggered("ZoomOut")){$gamePlayer.mapScale -= 0.01;};
  108.     if(Input.isTriggered("TUP")){$gamePlayer.mapTransparency += 50;
  109.         if($gamePlayer.mapTransparency < 0){$gamePlayer.mapTransparency = 0}};
  110.     if(Input.isTriggered("TDOWN")){$gamePlayer.mapTransparency -= 50;
  111.         if($gamePlayer.mapTransparency > 255){$gamePlayer.mapTransparency = 255}};
  112.     this.addIcon(this.mapIconData[$gameMap._mapId]);
  113.     this.contents.clear();
  114.     this.updateMapPNG();
  115.     this.updateIconPositions(this.mapIconData[$gameMap._mapId]);
  116.     this.bitmapMap.scale.x = $gamePlayer.mapScale;
  117.     this.bitmapMap.scale.y = $gamePlayer.mapScale;
  118.     this.bitmapMap.opacity = $gamePlayer.mapTransparency;
  119.     this.bitmapArrow.opacity = $gamePlayer.mapTransparency;
  120.     this.opacity = $gamePlayer.mapTransparency;
  121.    
  122. };
  123. //=============================================================================
  124.  
  125. Window_MiniMap.prototype.addMapPNG = function() {
  126.     this.bitmapMap = new Sprite(ImageManager.loadPicture("map"+$gameMap._mapId));
  127.     this.bitmapMap.scale.x = $gamePlayer.mapScale;
  128.     this.bitmapMap.scale.y = $gamePlayer.mapScale;
  129.     this.addChild(this.bitmapMap);
  130. };
  131.  
  132. Window_MiniMap.prototype.addArrowPNG = function() {
  133.     this.bitmapArrow = new Sprite(ImageManager.loadPicture("arrow"));
  134.     this.bitmapArrow.scale.x = 0.08;
  135.     this.bitmapArrow.scale.y = 0.08;
  136.     this.bitmapArrow.x = 70;
  137.     this.bitmapArrow.y = 65;
  138.     this.addChild(this.bitmapArrow);
  139. };
  140.  
  141. Window_MiniMap.prototype.addIcon = function(array) {
  142.     if(this.updateAddIcon){
  143.         if(this.mapIconData[$gameMap._mapId][0] === 'undefined'){
  144.         }else{
  145.             for(var i = 0; i < array.length; i++){
  146.                 this.bitmapIcon[i] = new Sprite(ImageManager.loadSystem('IconSet'));
  147.                 this.bitmapIcon[i].scale.x = 0.5;
  148.                 this.bitmapIcon[i].scale.y = 0.5;
  149.                 var pw = Window_Base._iconWidth;
  150.                 var ph = Window_Base._iconHeight;
  151.                 var sx = array[i][0] % 16 * pw;
  152.                 var sy = Math.floor(array[i][0] / 16) * ph;
  153.                 this.addChild(this.bitmapIcon[i]);
  154.                 this.bitmapIcon[i].setFrame(sx,sy,32,32);
  155.             };
  156.         };
  157.         this.updateAddIcon = false;
  158.     };
  159. };
  160.  
  161. Window_MiniMap.prototype.updateIconPositions = function(array){
  162.     var xMap = $gamePlayer.x * 48;
  163.     var yMap = $gamePlayer.y * 48;
  164.     var scale = $gamePlayer.mapScale;
  165.     for(var i = 0; i < array.length; i++){
  166.         var IconXMap = array[i][1]*48;
  167.         var IconYMap = array[i][2]*48;
  168.         if(!this.bitmapIcon[i] === false ){
  169.             if(Math.abs(IconXMap - xMap) > this.width/scale/2 || Math.abs(IconYMap - yMap) > this.width/scale/2){
  170.                 this.bitmapIcon[i].opacity = 0;
  171.             }else{
  172.                 if(array[i][3] === 0){
  173.                 this.bitmapIcon[i].opacity = 0;
  174.                 }else{
  175.                     this.bitmapIcon[i].opacity = $gamePlayer.mapTransparency;
  176.                 };
  177.                 if(IconXMap - xMap == 0 && IconYMap - yMap == 0){
  178.                     this.bitmapIcon[i].x = this.width/2;
  179.                     this.bitmapIcon[i].y = this.height/2;
  180.                 }else if(IconXMap - xMap >= 0 && IconYMap - yMap >= 0){
  181.                     this.bitmapIcon[i].x = this.width/2 + Math.abs(IconXMap - xMap)*scale;
  182.                     this.bitmapIcon[i].y = this.height/2 + Math.abs(IconYMap - yMap)*scale;
  183.                 }else if(IconXMap - xMap >= 0 && IconYMap - yMap <= 0){
  184.                     this.bitmapIcon[i].x = this.width/2 + Math.abs(IconXMap - xMap)*scale;
  185.                     this.bitmapIcon[i].y = this.height/2 - Math.abs(IconYMap - yMap)*scale;
  186.                 }else if(IconXMap - xMap <= 0 && IconYMap - yMap <= 0){
  187.                     this.bitmapIcon[i].x = this.width/2 - Math.abs(IconXMap - xMap)*scale;
  188.                     this.bitmapIcon[i].y = this.height/2 - Math.abs(IconYMap - yMap)*scale;
  189.                 }else{
  190.                     this.bitmapIcon[i].x = this.width/2 - Math.abs(IconXMap - xMap)*scale;
  191.                     this.bitmapIcon[i].y = this.height/2 + Math.abs(IconYMap - yMap)*scale;
  192.                 };
  193.             };
  194.         };
  195.     };
  196. };
  197.  
  198. Window_MiniMap.prototype.updateMapPNG = function() {
  199.     this.bitmapMap.opacity = 200;
  200.     var scale = $gamePlayer.mapScale;
  201.     var xMap = $gamePlayer.x * 48;
  202.     var yMap = $gamePlayer.y * 48;
  203.     var width = this.width/scale;
  204.     var height = this.height/scale;
  205.     this.bitmapMap.x = this.width/2 - xMap * scale;
  206.     this.bitmapMap.y = this.height/2 - yMap * scale;
  207.     if(this.bitmapMap.x < 0 && this.bitmapMap.y < 0){
  208.         this.bitmapMap.setFrame(-this.bitmapMap.x / scale , -this.bitmapMap.y/ scale ,width, height);
  209.         this.bitmapMap.x = 0;
  210.         this.bitmapMap.y = 0;
  211.     }else if(this.bitmapMap.y > 0 && this.bitmapMap.x < 0){
  212.         this.bitmapMap.setFrame(-this.bitmapMap.x/scale , 0 ,width, height-height*(this.bitmapMap.y/this.height)); 
  213.         this.bitmapMap.x = 0;
  214.     }else if(this.bitmapMap.y > 0){
  215.         this.bitmapMap.setFrame(0 , 0 ,width, height-height*(this.bitmapMap.y/this.height));   
  216.     }else if(this.bitmapMap.x < 0){
  217.         this.bitmapMap.setFrame(-this.bitmapMap.x/scale , 0 ,width, height);
  218.         this.bitmapMap.x = 0;
  219.     }else if(this.bitmapMap.y < 0){
  220.         this.bitmapMap.setFrame(0 , -this.bitmapMap.y/scale ,width, height);
  221.         this.bitmapMap.y = 0;
  222.     }else{
  223.         this.bitmapMap.setFrame(0, 0, width, height);
  224.     };
  225. };
  226.  
  227. var alias_Scene_Map_createAllWindowsJC = Scene_Map.prototype.createAllWindows;
  228. Scene_Map.prototype.createAllWindows = function() {
  229.     alias_Scene_Map_createAllWindowsJC.call(this);
  230.     if($dataMap.meta.EnableMiniMap){
  231.         this.createMiniMap();
  232.     };
  233. };
  234.  
  235. Scene_Map.prototype.createMiniMap = function() {
  236.     this._windowMiniMap = new Window_MiniMap(Graphics.width-150,0,150,150);
  237.     this.addChild(this._windowMiniMap);
  238. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement