楼主: VIPArcher

[通用发布] 【MV发布】瞎糊一个真·八方向脚本试试js怎么玩

[复制链接]
梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2015-11-19 14:21:21 | 显示全部楼层
话说楼主打算做增加帧数的功能么
试了下英文论坛的发现完全冲突,那个破坏力太强了直接把整个行走图划分了读,不是按默认的一个行走图分四个人物的
http://mvplugins.com/plugin/Shaz/More%20Character%20Frames
这种模式跟另外一个待机/走路/跑步的插件也冲突
http://mvplugins.com/plugin/Galv/Galvs%20Character%20Animations

点评

和这样的脚本冲突不是肯定的事嘛=。=  发表于 2015-11-19 14:22
回复

使用道具 举报

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2015-11-23 03:34:49 | 显示全部楼层
折腾了一下把三个行走图脚本整合了
八方向(LZ的),待机动作(如下),增加动画帧数(如下)

增加帧数
http://mvplugins.com/plugin/Shaz/More%20Character%20Frames
待机/行走/跑步动画
http://mvplugins.com/plugin/Galv/Galvs%20Character%20Animations

看脚本的时候就觉得脚本之前没有太多重复定义应该问题不大,果然前两个脚本可以直接共用。问题只在第三个因为一些写法比较暴力。
手写行走图文件名加$似乎是通过MV的内置脚本定义成了大行走图,从MV的编辑器里面都能看出来区别,这种文件不会被划分成4×2的小图。
于是哥折腾了半天稍微做点改动,就可以公用了。。。菜鸟不知道有没有地方有错,还没有测试复杂的图片。

下面是瞎掰的合并了的八方向和增加帧数js,待机动作在这个基础上直接外挂就可以一起用了

[pre lang="javascript"]
//=============================================================================
// VIPArcher_Dir8.js
//=============================================================================
/*:
* @plugindesc 真 · 八方向移动
* @author VIPArcher
*
* @param Dir8_flag
* @desc 使用八方向素材的标志
* @default %
*
* @param Dir8_Affix
* @desc 八方向素材文件后缀
* @default _8D
*
* @help 使用八方向的行走图素材文件名前面添加一个标志,
* 与之对应的8方向的素材与其同名并在后面添加后缀以区别。
* 例如默认的设置就是使用八方向的素材命名为:
* !$%VIPArcher.png
*
* 那么与之对应的八方向的素材就应命名为:
* !$%VIPArcher_8D.png
*
*/

// merge the two plugins
//=============================================================================
// More Character Frames
// by Shaz
// Last Updated: 2015.09.21
//=============================================================================

/*:
* @plugindesc Allows more than 3 Frames
* @author Shaz
*
* @help This plugin does not provide plugin commands.
*
* Add [D L R U] to your character sheet name (with $ prefix) to specify haw
* many frames in each direction (Down, Left, Right, Up).
* Spritesheets with this added to the file name will use a looping frame
* animation rather than the back-and-forth default animation.
*
* The first frame should be the idle/still pose.
*
* eg. $Ralph [8 8 8 8].png
*     is a character sheet consisting of 4 rows with 8 frames per row.
*     Animation will go from frame 1 to 8 then start at 1 again.
*
*        !!! For merging with idle action plugin, do not put $ in file name. Simply define the frame.
*     这里不要用插件默认的$前缀文件,为了和其他插件兼容我们要保持MV默认的4*2划分行走图方式
*     只需要在文件名后面加上[a b c d],分别定义4个方向的帧数
*/


(function() {
    var parameters = PluginManager.parameters('VIPArcher_Dir8');
    var dir8_flag = String(parameters['Dir8_flag'] || '%');
    var dir8_affix = String(parameters['Dir8_Affix'] || '_8D');
    ImageManager.isDir8Character = function(filename) {
        var reg = new RegExp("^\[\\!\\$\\" + dir8_flag + "]+")
        var sign = filename.match(reg);
        return sign && sign[0].contains(dir8_flag);
    };

//multiframe parameters 插入的多帧脚本内容,没有修改
  ImageManager.isMultiFrameCharacter = function(filename) {
    var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
    return frames && frames.length === 5;
  };

  ImageManager.getCharacterFrameCount = function(filename) {
    var frames = filename.match(/\[(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\]/);
    if (!frames) {
      return [3, 3, 3, 3];
    } else {
      return frames.splice(1, 4);
    }
  };
//multiframe parameters end 插入结束

    Game_Player.prototype.moveByInput = function() {
        if (!this.isMoving() && this.canMove()) {
            var direction = Input.dir8
            if (direction > 0) {
                $gameTemp.clearDestination();
            } else if ($gameTemp.isDestinationValid()){
                var x = $gameTemp.destinationX();
                var y = $gameTemp.destinationY();
                direction = this.findDirectionTo(x, y);
            }
            if (direction > 0) {
                if (direction % 2 == 0){
                    this.moveStraight(direction);
                    return;
                }
                if (direction < 5){
                    this.moveDiagonally(direction + 3 , 2);
                } else{
                    this.moveDiagonally(direction - 3 , 8);
                }
            }
        }
    };
    var dir8_move_diagonal = Game_Player.prototype.moveDiagonally;
    Game_Player.prototype.moveDiagonally = function(horz, vert) {
        if (!this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
            this.setMovementSuccess(false);
            return;
        }
        if (this.canPass(this._x, this._y, horz) && !this.canPass(this._x, this._y, vert)){
            this.moveStraight(horz);
            return;
        }
        if (this.canPass(this._x, this._y, vert) && !this.canPass(this._x, this._y, horz)){
            this.moveStraight(vert);
            return;
        }
        if (!this.canPassDiagonally(this._x, this._y, horz, vert)) {
            if (Math.random() > 0.5){
                this.setDirection(vert); this.moveStraight(vert)
            } else {
                this.setDirection(horz); this.moveStraight(horz)
            }
            return;
        }
        dir8_move_diagonal.call(this, horz, vert);
        if (horz > 5) {
            vert > 5 ? this.setDirection(9) : this.setDirection(7);
        }
        else {
            vert > 5 ? this.setDirection(3) : this.setDirection(1);
        };
    };
    Sprite_Character.prototype.characterPatternY = function() {
        if (this._character.direction() % 2 == 0){
            if (this.dir8_bitmap){ this.bitmap = this.dir4_bitmap; }
            return (this._character.direction() - 2) / 2;
        } else {
            if (this.dir8_bitmap){ this.bitmap = this.dir8_bitmap; }
            return parseInt((this._character.direction() + 1) / 3);
        }
    };
    var dir8_set_CharacterBitmap = Sprite_Character.prototype.setCharacterBitmap
    Sprite_Character.prototype.setCharacterBitmap = function() {
        dir8_set_CharacterBitmap.call(this);
        this._isDir8Character = ImageManager.isDir8Character(this._characterName);
        if (this._isDir8Character) {
            this.dir4_bitmap = this.bitmap;
            this.dir8_bitmap = ImageManager.loadCharacter(this._characterName + dir8_affix);
        };
    };

// multiframe code===============插入的多帧代码部分
  var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  Game_CharacterBase.initMembers = function() {
    _Game_CharacterBase_initMembers.call(this);
    this._isMultiFrame = false;
    this._frames = [3, 3, 3, 3];
  };

  var _Game_CharacterBase_maxPattern = Game_CharacterBase.prototype.maxPattern;
  Game_CharacterBase.prototype.maxPattern = function() {
    if (!this._isMultiFrame) {
      return _Game_CharacterBase_maxPattern.call(this);
    } else {
//consider diaganol directions  重写定义 考虑八向脚本兼容
        return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] :  this._frames[(parseInt((this._direction + 1)/ 3))];
    }
  };

  var _Game_CharacterBase_pattern = Game_CharacterBase.prototype.pattern;
  Game_CharacterBase.prototype.pattern = function() {
    if (!this._isMultiFrame) {
      return _Game_CharacterBase_pattern.call(this);
    } else {
//      return this._pattern < this._frames[this._direction / 2 - 1] ? this._pattern : 0;
//      为了简单暂时只用了第一行的帧数作为上限,稍微改一下应该就好了,懒,而且应该不太会用到不同方向不同帧数
                return this._pattern < this._frames[0] ? this._pattern : 0;
    }
  };

  var _Game_CharacterBase_isOriginalPattern = Game_CharacterBase.prototype.isOriginalPattern;
  Game_CharacterBase.prototype.isOriginalPattern = function() {
    if (!this._isMultiFrame) {
      return _Game_CharacterBase_isOriginalPattern.call(this);
    } else {
      return this.pattern() === 0;
    }
  };

  var _Game_CharacterBase_resetPattern = Game_CharacterBase.prototype.resetPattern;
  Game_CharacterBase.prototype.resetPattern = function() {
    if (!this._isMultiFrame) {
      _Game_CharacterBase_resetPattern.call(this);
    } else {
      this.setPattern(0);
    }
  };

  var _Game_CharacterBase_setImage = Game_CharacterBase.prototype.setImage;
  Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
    _Game_CharacterBase_setImage.call(this, characterName, characterIndex);
    this._isMultiFrame = ImageManager.isMultiFrameCharacter(characterName);
    this._frames = ImageManager.getCharacterFrameCount(characterName);
  };

  var _Game_CharacterBase_setTileImage = Game_CharacterBase.prototype.setTileImage;
  Game_CharacterBase.prototype.setTileImage = function(tileId) {
    _Game_CharacterBase_setTileImage.call(this, tileId);
    this._isMultiFrame = false;
    this._frames = [3, 3, 3, 3];
  };

  Game_CharacterBase.prototype.isMultiFrame = function() {
    return this._isMultiFrame;
  };

  Game_CharacterBase.prototype.getDirectionFrames = function() {
//    return this._frames[this._direction / 2 - 1]; 重新定义帧数 兼容八方向
        return this._direction <5 ? this._frames[(parseInt((this._direction + 1)/ 2) - 1)] :  this._frames[(parseInt((this._direction + 1)/ 3))];
  };

  var _Game_Event_initMembers = Game_Event.prototype.initMembers;
  Game_Event.prototype.initMembers = function() {
    _Game_Event_initMembers.call(this);
    if (this._isMultiFrame) {
      this._originalPattern = 0;
    }
  };

  var _Sprite_Character_patternWidth = Sprite_Character.prototype.patternWidth;
  Sprite_Character.prototype.patternWidth = function() {
    if (!this._character.isMultiFrame()) {
      return _Sprite_Character_patternWidth.call(this);
    } else {
// 除4以还原默认的4*2划分方式
      return this.bitmap.width / (4*this._character.getDirectionFrames());
    }
  };
//doranikofu edit redefine block 原始插件没有重定义的部分,需要按照新定义的行走图动画的帧数去修改index的读取位点,默认是3帧
Sprite_Character.prototype.characterBlockX = function() {
    if (this._isBigCharacter) {
        return 0;
    } else {
        var index = this._character.characterIndex();
        return (index % 4) * (this._character.getDirectionFrames());
    }
};
  //==========

})();
[/pre]
回复

使用道具 举报

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2015-11-29 15:16:46 | 显示全部楼层
本帖最后由 doranikofu 于 2015-11-29 16:02 编辑

话说又折腾了一下发现这个只定义了Game_player
貌似对跟随人物和npc都无效吧?。。。
试着把movediagnal从Game_player改高到Game_character或者Game_characterbase都没用。。。这个能通用改到跟随和npc么。。

再就是目前插件是靠读取两个文件分8向,感觉可以考虑整合成一个文件改index实现8向 默认素材就是4×2的 index+4就可以读取下一行的图做斜向图 就看要怎么加进去了
这样不用再读一个文件显示斜向图

点评

最近发现拼图神器 ImageMagick 超级好用。。。拼图神马的完全不是问题  发表于 2015-11-30 00:57
那我改改发到MV区吧。  发表于 2015-11-29 16:44
嗯。我之前也是想整合一个文件,不过有人说改文件名轻松点,拼一个文件麻烦啥啥啥的。  发表于 2015-11-29 16:42
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部