设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 486|回复: 2
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2454
在线时间
409 小时
注册时间
2016-2-3
帖子
755
跳转到指定楼层
1
发表于 2024-1-29 11:46:49 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

JS 代码复制
  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.  
  34. (function () {
  35.  
  36.     Game_CharacterBase.prototype.setRidingCharacter = function (characterName, idx, charaHeight, charadx, charady) {
  37.         this.clearRidingCharacter();
  38.         this._ridingCharacterName = characterName;
  39.         this._ridingCharacterIndex = idx | 0;
  40.         this._charadx = charadx | 0;
  41.         this._charady = charady | 0;
  42.         this._charaHeight = charaHeight | 0;
  43.         this._ridingHeightDelta = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  44.         SceneManager.goto(Scene_Map)
  45.     };
  46.  
  47.     Game_CharacterBase.prototype.setRidingCharacterFront = function (characterName) {
  48.         this._ridingCharacterNameFront = characterName;
  49.     }
  50.  
  51.     // 设置3*4帧的高度波动
  52.     Game_CharacterBase.prototype.setRidingHeightDelta = function (arr) {
  53.         this._ridingHeightDelta = arr || [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  54.     }
  55.  
  56.     // 检查角色是否骑坐骑
  57.     Game_CharacterBase.prototype.isRiding = function () {
  58.         return !!this._ridingCharacterName;
  59.     };
  60.  
  61.     // 清除角色的坐骑行走图
  62.     Game_CharacterBase.prototype.clearRidingCharacter = function () {
  63.         this._ridingCharacterName = '';
  64.         this._ridingCharacterNameFront = '';
  65.         this._ridingCharacterIndex = 0;
  66.         SceneManager.goto(Scene_Map)
  67.     };
  68.  
  69.     // 覆盖Sprite_Character的_updateBitmap方法
  70.     const _Sprite_Character_updateBitmap = Sprite_Character.prototype.updateBitmap;
  71.     Sprite_Character.prototype.updateBitmap = function () {
  72.         _Sprite_Character_updateBitmap.call(this);
  73.  
  74.         // 检查角色是否骑坐骑,如果是,则拼接角色和坐骑的行走图
  75.         if (this._character.isRiding()) {
  76.             const characterName = this._character.characterName();
  77.             const ridingCharacterName = this._character._ridingCharacterName;
  78.             const ridingCharacterNameFront = this._character._ridingCharacterNameFront;
  79.             var characterIndex = this._character.characterIndex();
  80.             const index = this._character._ridingCharacterIndex;
  81.  
  82.             const characterBitmap = ImageManager.loadCharacter(characterName);
  83.             const ridingCharacterBitmap = ImageManager.loadCharacter(ridingCharacterName);
  84.  
  85.             var bitmapSizeX = parseInt(ridingCharacterBitmap.width / 12);
  86.             var bitmapSizeY = parseInt(ridingCharacterBitmap.height / 8);
  87.             var chaBitmapSize = 48;
  88.  
  89.             let chax = this._character._charadx;
  90.             let chay = this._character._charady;
  91.  
  92.             let drx = 0;
  93.             let dry = 0;
  94.             if (ridingCharacterName.contains("$")) {
  95.                 bitmapSizeX = ridingCharacterBitmap.width / 3;
  96.                 bitmapSizeY = ridingCharacterBitmap.height / 4;
  97.                 drx = (this.characterPatternX() * bitmapSizeX)
  98.                 dry = ((this._character.direction() - 2) / 2 * bitmapSizeY)
  99.             } else {
  100.                 drx = (index % 4 * bitmapSizeX * 3 + this.characterPatternX() * bitmapSizeX)
  101.                 dry = (Math.floor(index / 4) * bitmapSizeY * 4 + (this._character.direction() - 2) / 2 * bitmapSizeY)
  102.             }
  103.  
  104.             if (characterName.contains("$")) {
  105.                 chaBitmapSize = characterBitmap.width / 3;
  106.                 characterIndex = 0;
  107.             }
  108.  
  109.             let dx = (characterIndex % 4 * chaBitmapSize * 3)
  110.             let dy = (Math.floor(characterIndex / 4) * chaBitmapSize * 4 + (this._character.direction() - 2) / 2 * chaBitmapSize)
  111.  
  112.             let dirX = (this._character.direction() == 4 ? chax : 0) + (this._character.direction() == 6 ? -chax : 0);
  113.             let dirY = (this._character.direction() == 8 ? chay : 0) + (this._character.direction() == 2 ? -chay : 0);
  114.  
  115.             let heightDelta = this._character._ridingHeightDelta[this.characterPatternX() + this.characterPatternY() * 3];
  116.  
  117.             let posX = parseInt((bitmapSizeX - chaBitmapSize) / 2 + dirX + chax);
  118.             let posY = parseInt(-heightDelta + (bitmapSizeY - chaBitmapSize) / 2 + dirY + bitmapSizeY - this._character._charaHeight - 8);
  119.  
  120.             console.log("pos", posX, posY)
  121.  
  122.  
  123.             const combinedBitmap = new Bitmap(bitmapSizeX + chax * 2, bitmapSizeY * 2);
  124.             console.log("combinedBitmap", combinedBitmap.width, combinedBitmap.height)
  125.             combinedBitmap.blt(ridingCharacterBitmap, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
  126.             combinedBitmap.blt(characterBitmap, dx, dy, chaBitmapSize, chaBitmapSize, posX, posY);
  127.  
  128.             if (ridingCharacterNameFront) {
  129.                 const ridingCharacterBitmapFront = ImageManager.loadCharacter(ridingCharacterNameFront);
  130.                 combinedBitmap.blt(ridingCharacterBitmapFront, drx, dry, bitmapSizeX, bitmapSizeY, chax, bitmapSizeY);
  131.             }
  132.  
  133.             this.bitmap = combinedBitmap;
  134.         }
  135.     };
  136.  
  137.     Sprite_Character.prototype.updateCharacterFrame = function () {
  138.         const pw = this.patternWidth();
  139.         const ph = this.patternHeight();
  140.         const sx = (this.characterBlockX() + this.characterPatternX()) * pw;
  141.         const sy = (this.characterBlockY() + this.characterPatternY()) * ph;
  142.  
  143.         if (this._character.isRiding()) return;
  144.         else this.setFrame(sx, sy, pw, ph);
  145.     };
  146.  
  147. })();

评分

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

查看全部评分

MV/MZ Zeros魔塔样板

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

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



Lv3.寻梦者

梦石
0
星屑
1684
在线时间
239 小时
注册时间
2018-7-5
帖子
77
2
发表于 2024-1-29 14:50:24 | 只看该作者
好!!!
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
66
在线时间
8 小时
注册时间
2024-2-19
帖子
3
3
发表于 2024-3-12 17:08:37 | 只看该作者
66666,厉害
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-28 15:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表