加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员  
 
x
 
 
 
先看下效果  
四方向桥有很多种实现方式,直接写事件控制也不难。 
但试想 一个游戏  N个地图 有N*M个桥   
好家伙 这动点逻辑 直接血压上升。 
 
程序的意思,其实和编码无关,是找到一个问题的范用处理办法。 
但本人经过不断的试错 改进。终于找到了一种 扩展性较高的解决办法。 
 
 
看下MV的事编写了多少 
桥体  2页 执行事件为空 
 
 
空气墙1  1页  执行事件为空 
 
 
空气墙2  1页  执行事件为空 
 
 
 
 
 
脚本基于region标记 
首先的问题便是  
游戏角色 移动时踩到了什么标记 
 
/**region自动触发事件*/     Game_Player.prototype.moveStraight = function(d) {         if (this.canPass(this.x, this.y, d)) {             this._followers.updateMove();             _.Fregion_control( Game_Map.prototype.regionId($gameMap.roundXWithDirection(this.x, d), $gameMap.roundYWithDirection(this.y, d)))         }         Game_Character.prototype.moveStraight.call(this, d);     }; 
 
 /**region自动触发事件*/  
    Game_Player.prototype.moveStraight = function(d) {  
        if (this.canPass(this.x, this.y, d)) {  
            this._followers.updateMove();  
            _.Fregion_control( Game_Map.prototype.regionId($gameMap.roundXWithDirection(this.x, d), $gameMap.roundYWithDirection(this.y, d)))  
        }  
        Game_Character.prototype.moveStraight.call(this, d);  
    };  
 
  
 
 _.Fregion_control是我新增的方法, 
this.canPass(this.x, this.y, d)   3个参数 x y d  xy坐标与d朝向  检查玩家是否能通过前方的图块 
(我之前就一直在canpass的方法里转  进到Game_Map.checkPassage 给我人都看傻了... 
首先MV键盘和鼠标走了两个方法;移动一次 检查自己的位置和前方的位置。有时候没调明白代码可能是你进的太深了) 
如果能通过 进入if  执行更新从者,就是主角后面的队友小人;与我新增的方法。 
 
 
Game_Map.prototype.regionId($gameMap.roundXWithDirection(this.x, d), $gameMap.roundYWithDirection(this.y, d)) 
我写的比较长 
Game_Map.prototype.regionId是传入x y坐标 返回该坐标的region标记   
 而 Game_Player.prototype.moveStraight内的x y是玩家当前的坐标 你要将他向朝向方向移一格 
$gameMap.roundXWithDirection(this.x, d)与$gameMap.roundYWithDirection(this.y, d)自带的方法可以取到移动后的x y 
传入即可 
 
_.Fregion_control=function(region){          console.log(region)     } 
 
 _.Fregion_control=function(region){  
         console.log(region)  
    }  
 
  
 
检查效果 
 
 
 
 
插件配置 
 
 
桥的出入口;桥洞的出入口;桥体 
3个regionid 
 
上桥时打开的开关 
进桥洞时打开的开关 
用于控制 
上桥时  桥洞出入口的空气墙出现 桥体在玩家下方 
进洞时  桥的出入口的空气墙出现 桥体在玩家下方 
 
*@param bridge_up  * @desc  桥的出入口  * @default 245  * @type number  * @parent Bridge  *  *@param bridge_down  * @desc  桥洞的出入口  * @default 246  * @type number  * @parent Bridge  *  *@param bridge_region  * @desc  桥体  * @default 244  * @type number  * @parent Bridge  *  *@param bridge_switchup  * @desc  上桥时打开的开关  * @default  5  * @type number  * @parent Bridge  *  *@param bridge_switchdown  * @desc  进桥洞时打开的开关  * @default  6  * @type number  * @parent Bridge         _.bridge_switchdown= parseInt(params['bridge_switchdown'])||0;     _.bridge_switchup= parseInt(params['bridge_switchup'])||0;     _.bridge_down= parseInt(params['bridge_down'])||-1;     _.bridge_up= parseInt(params['bridge_up'])||-1;     _.bridge_region= parseInt(params['bridge_region'])||-1;     _.bridge_pass=[_.bridge_down,_.bridge_up,_.bridge_region] 
 
 *@param bridge_up  
 * @desc  桥的出入口  
 * @default 245  
 * @type number  
 * @parent Bridge  
 *  
 *@param bridge_down  
 * @desc  桥洞的出入口  
 * @default 246  
 * @type number  
 * @parent Bridge  
 *  
 *@param bridge_region  
 * @desc  桥体  
 * @default 244  
 * @type number  
 * @parent Bridge  
 *  
 *@param bridge_switchup  
 * @desc  上桥时打开的开关  
 * @default  5  
 * @type number  
 * @parent Bridge  
 *  
 *@param bridge_switchdown  
 * @desc  进桥洞时打开的开关  
 * @default  6  
 * @type number  
 * @parent Bridge  
   
   
    _.bridge_switchdown= parseInt(params['bridge_switchdown'])||0;  
    _.bridge_switchup= parseInt(params['bridge_switchup'])||0;  
    _.bridge_down= parseInt(params['bridge_down'])||-1;  
    _.bridge_up= parseInt(params['bridge_up'])||-1;  
    _.bridge_region= parseInt(params['bridge_region'])||-1;  
    _.bridge_pass=[_.bridge_down,_.bridge_up,_.bridge_region]  
 
  
 
脚本读取插件配置的写法 没什么好说的 
 
然后 将_.Fregion_control中写进事务 
_.Fregion_control=function(region){         switch (region) {             case _.bridge_up:                 $gameSwitches.setValue(_.bridge_switchup,!$gameSwitches.value(_.bridge_switchup))                 break             case _.bridge_down:                 $gameSwitches.setValue(_.bridge_switchdown,!$gameSwitches.value(_.bridge_switchdown))                 break         }           if(($gameSwitches.value(_.bridge_switchup)||$gameSwitches.value(_.bridge_switchdown))&&_.bridge_pass.indexOf(region)==-1)         {             $gameSwitches.setValue(_.bridge_switchup,false)             $gameSwitches.setValue(_.bridge_switchdown,false)         }     } 
 
 _.Fregion_control=function(region){  
        switch (region) {  
            case _.bridge_up:  
                $gameSwitches.setValue(_.bridge_switchup,!$gameSwitches.value(_.bridge_switchup))  
                break  
            case _.bridge_down:  
                $gameSwitches.setValue(_.bridge_switchdown,!$gameSwitches.value(_.bridge_switchdown))  
                break  
        }  
   
        if(($gameSwitches.value(_.bridge_switchup)||$gameSwitches.value(_.bridge_switchdown))&&_.bridge_pass.indexOf(region)==-1)  
        {  
            $gameSwitches.setValue(_.bridge_switchup,false)  
            $gameSwitches.setValue(_.bridge_switchdown,false)  
        }  
    }  
 
  
一个switch  玩家踩到桥的出入口  对应的开关置非   原来关闭则打开 原来打开则关闭 
然后通过检查2个开关是否打开 判断玩家是不是在桥上  
如果玩家在桥上而且踩的不是 桥的出入口和桥体   (情况是 玩家踩了出入口 然后扭头回去) 
则2个开关关闭 (玩家下桥) 
 
 
    
 |