查看: 2284|回复: 4

[原创发布] 坐骑插件(图层合成,再也不用担心每个角色都要做坐骑...

[复制链接]
梦石
0
星屑
2632
在线时间
420 小时
注册时间
2016-2-3
回帖
679
发表于 2024-1-29 11:46:49 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 79160475 于 2024-1-29 17:11 编辑

只需要一张坐骑行走图,加坐骑遮挡图层(可选),就能让角色坐上坐骑。再也不用手动一一拼接x个人物*y个坐骑。
插件1.0版本,可能还有点bug,暂未测试对mv的支持。
QQ录屏20240128173553_-original-original.gif

  1. //=============================================================================
  2. // Zeros_RidingSystem.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc
  6. * @author 零殇
  7. *
  8. * @param v
  9. * @desc 版本
  10. * @default 1.0
  11. *
  12. * @help
  13. *
  14. * 上坐骑图片叫做Vehicle.png,放在img/characters下面,目前只适配角色大小和坐骑图大小一样的(标准)图片,否则会出现问题
  15. * 坐骑图片编号:图片第一行0 1 2 3,第二行4 5 6 7
  16. *
  17. * 使用方法:
  18. * 事件.setRidingCharacter('Vehicle',坐骑图片编号,玩家x偏移,玩家y偏移,玩家在坐骑上的高度);
  19. *
  20. * setRidingCharacterFront('Vehicle')  //设置坐骑前景(如果有的话可以设置这张覆盖在角色上面的图片)
  21. *
  22. * 比如:
  23. * 上坐骑
  24. * $gamePlayer.setRidingCharacter('Vehicle',0,5,5,20);
  25. * 设置坐骑前景
  26. * $gamePlayer.setRidingCharacterFront('VehicleFrontz')
  27. * 下坐骑
  28. * $gamePlayer.clearRidingCharacter()
  29. *
  30. * 初代版本,可能有bug,欢迎反馈
  31. * 觉得好用可以支持下零殇的游戏,Steam搜索《魔塔地牢》
  32. */

  33. (function () {

  34.     Game_CharacterBase.prototype.setRidingCharacter = function (characterName, idx, charaHeight, charadx, charady) {
  35.         this.clearRidingCharacter();
  36.         this._ridingCharacterName = characterName;
  37.         this._ridingCharacterIndex = idx | 0;
  38.         this._charadx = charadx | 0;
  39.         this._charady = charady | 0;
  40.         this._charaHeight = charaHeight | 0;
  41.         this._ridingHeightDelta = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  42.         SceneManager.goto(Scene_Map)
  43.     };

  44.     Game_CharacterBase.prototype.setRidingCharacterFront = function (characterName) {
  45.         this._ridingCharacterNameFront = characterName;
  46.     }

  47.     // 设置3*4帧的高度波动
  48.     Game_CharacterBase.prototype.setRidingHeightDelta = function (arr) {
  49.         this._ridingHeightDelta = arr || [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  50.     }

  51.     // 检查角色是否骑坐骑
  52.     Game_CharacterBase.prototype.isRiding = function () {
  53.         return !!this._ridingCharacterName;
  54.     };

  55.     // 清除角色的坐骑行走图
  56.     Game_CharacterBase.prototype.clearRidingCharacter = function () {
  57.         this._ridingCharacterName = '';
  58.         this._ridingCharacterNameFront = '';
  59.         this._ridingCharacterIndex = 0;
  60.         SceneManager.goto(Scene_Map)
  61.     };

  62.     // 覆盖Sprite_Character的_updateBitmap方法
  63.     const _Sprite_Character_updateBitmap = Sprite_Character.prototype.updateBitmap;
  64.     Sprite_Character.prototype.updateBitmap = function () {
  65.         _Sprite_Character_updateBitmap.call(this);

  66.         // 检查角色是否骑坐骑,如果是,则拼接角色和坐骑的行走图
  67.         if (this._character.isRiding()) {
  68.             const characterName = this._character.characterName();
  69.             const ridingCharacterName = this._character._ridingCharacterName;
  70.             const ridingCharacterNameFront = this._character._ridingCharacterNameFront;
  71.             var characterIndex = this._character.characterIndex();
  72.             const index = this._character._ridingCharacterIndex;

  73.             const characterBitmap = ImageManager.loadCharacter(characterName);
  74.             const ridingCharacterBitmap = ImageManager.loadCharacter(ridingCharacterName);

  75.             var bitmapSizeX = parseInt(ridingCharacterBitmap.width / 12);
  76.             var bitmapSizeY = parseInt(ridingCharacterBitmap.height / 8);
  77.             var chaBitmapSize = 48;

  78.             let chax = this._character._charadx;
  79.             let chay = this._character._charady;

  80.             let drx = 0;
  81.             let dry = 0;
  82.             if (ridingCharacterName.contains("$")) {
  83.                 bitmapSizeX = ridingCharacterBitmap.width / 3;
  84.                 bitmapSizeY = ridingCharacterBitmap.height / 4;
  85.                 drx = (this.characterPatternX() * bitmapSizeX)
  86.                 dry = ((this._character.direction() - 2) / 2 * bitmapSizeY)
  87.             } else {
  88.                 drx = (index % 4 * bitmapSizeX * 3 + this.characterPatternX() * bitmapSizeX)
  89.                 dry = (Math.floor(index / 4) * bitmapSizeY * 4 + (this._character.direction() - 2) / 2 * bitmapSizeY)
  90.             }

  91.             if (characterName.contains("$")) {
  92.                 chaBitmapSize = characterBitmap.width / 3;
  93.                 characterIndex = 0;
  94.             }

  95.             let dx = (characterIndex % 4 * chaBitmapSize * 3)
  96.             let dy = (Math.floor(characterIndex / 4) * chaBitmapSize * 4 + (this._character.direction() - 2) / 2 * chaBitmapSize)

  97.             let dirX = (this._character.direction() == 4 ? chax : 0) + (this._character.direction() == 6 ? -chax : 0);
  98.             let dirY = (this._character.direction() == 8 ? chay : 0) + (this._character.direction() == 2 ? -chay : 0);

  99.             let heightDelta = this._character._ridingHeightDelta[this.characterPatternX() + this.characterPatternY() * 3];

  100.             let posX = parseInt((bitmapSizeX - chaBitmapSize) / 2 + dirX + chax);
  101.             let posY = parseInt(-heightDelta + (bitmapSizeY - chaBitmapSize) / 2 + dirY + bitmapSizeY - this._character._charaHeight - 8);

  102.             console.log("pos", posX, posY)


  103.             const combinedBitmap = new Bitmap(bitmapSizeX + chax * 2, bitmapSizeY * 2);
  104.             console.log("combinedBitmap", combinedBitmap.width, combinedBitmap.height)
  105.             combinedBitmap.blt(ridingCharacterBitmap, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
  106.             combinedBitmap.blt(characterBitmap, dx, dy, chaBitmapSize, chaBitmapSize, posX, posY);

  107.             if (ridingCharacterNameFront) {
  108.                 const ridingCharacterBitmapFront = ImageManager.loadCharacter(ridingCharacterNameFront);
  109.                 combinedBitmap.blt(ridingCharacterBitmapFront, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
  110.             }

  111.             this.bitmap = combinedBitmap;
  112.         }
  113.     };

  114.     Sprite_Character.prototype.updateCharacterFrame = function () {
  115.         const pw = this.patternWidth();
  116.         const ph = this.patternHeight();
  117.         const sx = (this.characterBlockX() + this.characterPatternX()) * pw;
  118.         const sy = (this.characterBlockY() + this.characterPatternY()) * ph;

  119.         if (this._character.isRiding()) return;
  120.         else this.setFrame(sx, sy, pw, ph);
  121.     };

  122. })();
复制代码

评分

参与人数 3赞 +3 收起 理由
rfvtgbzxc + 1 精品文章
妾而君亦然 + 1 我很赞同
马铃薯条 + 1 我很赞同

查看全部评分

MV/MZ Zeros魔塔样板

原创ARPG系统火爆出售中(论坛优惠价)(内含90+功能)
-------------------------------------------------------------------
*事件党*福利!本人两年的事件研究大集合

!点击上面看*事件党*详情(内含200+收集插件)
!
!
!
梦石
0
星屑
1864
在线时间
255 小时
注册时间
2018-7-5
回帖
62
发表于 2024-1-29 14:50:24 | 显示全部楼层
好!!!
回复

使用道具 举报

梦石
0
星屑
93
在线时间
13 小时
注册时间
2024-2-19
回帖
3
发表于 2024-3-12 17:08:37 | 显示全部楼层
66666,厉害
回复

使用道具 举报

梦石
0
星屑
1076
在线时间
156 小时
注册时间
2022-5-19
回帖
103
发表于 2024-6-13 19:40:00 | 显示全部楼层
用完这个插件角色踩在水上面不会显示在水下的那种效果,
回复

使用道具 举报

梦石
0
星屑
2632
在线时间
420 小时
注册时间
2016-2-3
回帖
679
 楼主| 发表于 2024-7-5 12:09:43 | 显示全部楼层
jm1280065234 发表于 2024-6-13 19:40
用完这个插件角色踩在水上面不会显示在水下的那种效果,

没试过,你可以试试下
MV/MZ Zeros魔塔样板

原创ARPG系统火爆出售中(论坛优惠价)(内含90+功能)
-------------------------------------------------------------------
*事件党*福利!本人两年的事件研究大集合

!点击上面看*事件党*详情(内含200+收集插件)
!
!
!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部