0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RPGツクールMV 一番シンプルなHPゲージのプラグインを作ってみた

Last updated at Posted at 2017-12-01

まず肩慣らしに投稿してみます。よろしくお願いします。

画面下部にHPゲージと顔画像が出る、という、考えうる一番シンプルな機能のプラグインを、練習を兼ねて作ってみました。
唯一にして最大の特徴が「パーティ全員の顔とHPが出る」点です。思いっきりevalしまくっているのがお恥ずかしいですが、よろしければ。

SNZ_VerySimpleHud.js
//=============================================================================
// SNZ_VerySimpleHud.js
// Version: 1.0
//----------------------------------------------------------------------------
// by しんぞ
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================

/*:
@plugindesc HPだけわかれば良い、というウインドウです
@author しんぞ

@help Hudと呼ばれるマップ上のウインドウです。
パーティ全員(4人までを想定)の顔画像とHPバーのみ表示します。
ここまでシンプルなものは逆に見当たらなかったので作ってみました。
使用改変再配布ご自由にどうぞ。

ところで、もやしって一人暮らしの味方を名乗るわりには飽きる味だよね。

@param HudSwitchId
@desc このIDのスイッチがONの間だけ表示します。
@default
@type switch

@param FaceSize
@desc 顔画像のサイズです。Javascript式が使えます。
@default 60
@type number

@param FaceY
@desc 顔画像のY座標です。Javascript式が使えます。
@default Graphics.height - 80
@type string

@param LifeY
@desc HPゲージのY座標です。Javascript式が使えます。
@default Graphics.height - 30
@type string

@param LifeHeight
@desc HPゲージの高さです。Javascript式が使えます。
@default 15
@type string

@param FullWidth
@desc 4人表示した場合の横幅です。Javascript式が使えます。
@default Graphics.width
@type string

@param LifeMargin
@desc キャラクター同士の間隔です。Javascript式が使えます。
@default 10
@type string

 */

(function() {
	var Parameters = PluginManager.parameters('SNZ_VerySimpleHud');

	var hudswitchid = String(Parameters['HudSwitchId']);
	var facesize = String(Parameters['FaceSize']);
	var facey = String(Parameters['FaceY']);
	var lifey = String(Parameters['LifeY']);
	var lifeheight = String(Parameters['LifeHeight']);
	var fullwidth = String(Parameters['FullWidth']);
	var lifemargin = String(Parameters['LifeMargin']);
	function Window_lifeHUD() {
	    this.initialize.apply(this, arguments);
	    this.initialize.apply(this, arguments);
	}
	function Window_faceHUD() {
	    this.initialize.apply(this, arguments);
	    this.initialize.apply(this, arguments);
	}

  var _Scene_Base_start = Scene_Base.prototype.start;
  Scene_Base.prototype.start = function() {
    _Scene_Base_start.call(this);
		facesize = eval(facesize);
		facey = eval(facey);
		lifey = eval(lifey);
		lifeheight = eval(lifeheight);
		fullwidth = eval(fullwidth);
		lifemargin = eval(lifemargin);
	}

	Window_lifeHUD.prototype = Object.create(Window_Base.prototype);
	Window_lifeHUD.prototype.constructor = Window_lifeHUD;
	Window_faceHUD.prototype = Object.create(Window_Base.prototype);
	Window_faceHUD.prototype.constructor = Window_faceHUD;

	Window_lifeHUD.prototype.initialize = function(x, y) {
	    var width = this.windowWidth();
	    var height = this.windowHeight();
	    Window_Base.prototype.initialize.call(this, x, y, width, height);
	    this.refresh();
	};
	Window_faceHUD.prototype.initialize = function(x, y) {
	    var width = this.windowWidth();
	    var height = this.windowHeight();
	    Window_Base.prototype.initialize.call(this, x, y, width, height);
	    this.refresh();
	};

	Window_lifeHUD.prototype.windowWidth = function() {
		return eval(fullwidth);
	};
	Window_lifeHUD.prototype.windowHeight = function() {
	    return 100;
	};
	Window_faceHUD.prototype.windowWidth = function() {
	    return Math.max(Window_Base._faceWidth, facesize);
	};
	Window_faceHUD.prototype.windowHeight = function() {
		return Math.max(Window_Base._faceHeight, facesize);
	};

		Window_lifeHUD.prototype.refresh = function() {
		    this.contents.clear();
				if($gameParty.members()[this.hudid]){
			    var color1 = this.hpGaugeColor1();
			    var color2 = this.hpGaugeColor2();
			    this.drawGauge(0, 0, 120, $gameParty.members()[this.hudid].hp / $gameParty.members()[this.hudid].param(0), color1, color2);
				}
	};

		Window_faceHUD.prototype.refresh = function() {
			var nowactor = $gameParty.members()[this.hudid];
			//アクターIDが同じだったら何もしない
			if(!nowactor || (nowactor && nowactor._actorId != this.actor)){
				this.contents.clear();
				if(nowactor){
					var faceIndex = nowactor.faceIndex();
					var bitmap = ImageManager.loadFace(nowactor.faceName());
					var pw = Window_Base._faceWidth;
					var ph = Window_Base._faceHeight;
					var sx = faceIndex % 4 * pw;
					var sy = Math.floor(faceIndex / 4) * ph ;
					var dx = 0;
					var dy = 0;
					var dw = facesize;
					var dh = facesize;
					this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
					//現在のアクターIDを代入しておく
					this.actor = nowactor._actorId;
				}
			}
	};


	Window_lifeHUD.prototype.open = function() {
	    this.refresh();
	    Window_Base.prototype.open.call(this);
	};
	Window_faceHUD.prototype.open = function() {
	    this.refresh();
	    Window_Base.prototype.open.call(this);
	};

	var _Scene_Map_prototype_start = Scene_Map.prototype.start;
	Scene_Map.prototype.start = function() {
	    _Scene_Map_prototype_start.call(this);
			this.createFaceWindow();
			this.createLifeWindow();
	};

	Scene_Map.prototype.createLifeWindow = function() {
		for(i=0; i<4; i++){
			this['_lifeWindow'+i] = new Window_lifeHUD();
			this['_lifeWindow'+i].opacity = 0;
			this['_lifeWindow'+i].x = fullwidth  / 4 * i + lifemargin;
			this['_lifeWindow'+i].y = lifey;
			this['_lifeWindow'+i].padding = 0;
			this['_lifeWindow'+i].hudid = i;
	    this.addWindow(this['_lifeWindow'+i]);
		}
	}
	Scene_Map.prototype.createFaceWindow = function() {
		for(i=0; i<4; i++){
			this['_faceWindow'+i] = new Window_faceHUD();
			this['_faceWindow'+i].opacity = 0;
			this['_faceWindow'+i].x = fullwidth  / 4 * i + lifemargin;
			this['_faceWindow'+i].y = facey;
			this['_faceWindow'+i].padding = 0;
			this['_faceWindow'+i].hudid = i;
	    this.addWindow(this['_faceWindow'+i]);
		}
	}

	var _Scene_Map_prototype_update = Scene_Map.prototype.update;
	Scene_Map.prototype.update = function() {
	    _Scene_Map_prototype_update.call(this);
			for(i=0; i<4; i++){
			this['_lifeWindow'+i].refresh();
			this['_faceWindow'+i].refresh();
		}
			if($gameSwitches.value(hudswitchid)){
				for(i=0; i<4; i++){
					this['_lifeWindow'+i].show();
					this['_faceWindow'+i].show();
			}
		  }else{
				for(i=0; i<4; i++){
					this['_lifeWindow'+i].hide();
					this['_faceWindow'+i].hide();
			}
		  }
	};

	Window_lifeHUD.prototype.drawGauge = function(x, y, width, rate, color1, color2) {
	    var fillW = Math.floor(width * rate);
	    this.contents.fillRect(x, y, width, lifeheight, this.gaugeBackColor());
	    this.contents.fillRect(x, y, fillW, lifeheight, color1);
	};

})();
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?