标签:html5 lufylegend 游戏脚本 剧情 rpg
注意:本系列教程为长篇连载无底洞,半路杀进来的朋友,如果看不懂的话,请从第一章开始看起,文章目录请点击下面链接。
http://blog.csdn.net/lufy_legend/article/details/8888787
RPGRunMode.set(1); RPGRunMode.set(0);
LRPGObject.runMode = false;
/* * LRPGRunMode.js **/ LRPGRunMode = function(){}; LRPGRunMode.analysis=function(value){ var start = value.indexOf("("); var end = value.indexOf(")"); var params = value.substring(start+1,end).split(","); switch(value.substr(0,start)){ case "RPGRunMode.set": LRPGObject.runMode = (parseInt(params[0]) == 1); LGlobal.script.analysis(); break; default: LGlobal.script.analysis(); } };
if(LRPGObject.runMode)return;
//角色ID,坐标x,坐标y,是否等待 RPGCharacter.moveTo(2,60,13,1);
MapController.prototype.characterMoveTo = function(chara,cx,cy,callback){ var self = this; chara = self.getCharacter(chara); if(!chara)return; if(chara.hasEventListener(Character.MOVE_COMPLETE)){ chara.removeEventListener(Character.MOVE_COMPLETE); } var coordinate = chara.getTo(); var fx = coordinate[0] , fy = coordinate[1]; var returnList = self.query.queryPath(new LPoint(fx,fy),new LPoint(cx,cy)); if(returnList.length > 0){ chara.setRoad(returnList); if(callback){ chara.addEventListener(Character.MOVE_COMPLETE,callback); } } }; MapController.prototype.getCharacter = function(value){ var self = this; if(LString.isInt(value)){ var childList = self.view.charaLayer.childList,child; for(var i=0,l=childList.length;i<l;i++){ child = childList[i]; if(value != child.index)continue; return child; } }else if(typeof value == "object"){ return value; } return null; };
LRPGCharacter.moveTo = function (value,start,end){ var params = value.substring(start+1,end).split(","), wait; if(params.length == 3){ wait = false; }else{ wait = (parseInt(params.pop()) == 1); } //params:index,x,y LRPGObject.RPGMap.characterMoveTo.call(LRPGObject.RPGMap,params[0],parseInt(params[1]),parseInt(params[2]),LRPGCharacter.getMoveCallback(wait)); }; LRPGCharacter.getMoveCallback = function (wait){ var lineValue, callback = LGlobal.script.analysis.bind(LGlobal.script); if(!wait && LGlobal.script.lineList.length > 0){ lineValue = LMath.trim(LGlobal.script.lineList[0]); if(lineValue.indexOf("RPGCharacter.move") == 0){ callback = null; LGlobal.script.analysis(); } } return callback; };
//角色ID,相对坐标x,相对坐标y RPGCharacter.move(2,-4,0);
MapController.prototype.characterMove = function(chara,cx,cy,callback){ var self = this; chara = self.getCharacter(chara); self.characterMoveToCharacter(chara,chara,cx,cy,callback); };
LRPGCharacter.move = function (value,start,end){ var params = value.substring(start+1,end).split(","), wait; if(params.length == 3){ wait = false; }else{ wait = (parseInt(params.pop()) == 1); } //params:index,x,y LRPGObject.RPGMap.characterMove.call(LRPGObject.RPGMap,params[0],parseInt(params[1]),parseInt(params[2]),LRPGCharacter.getMoveCallback(wait)); };
//移动角色ID,参照角色ID,相对坐标x,相对坐标y RPGCharacter.moveToCharacter(2,1,0,4);
MapController.prototype.characterMoveToCharacter = function(chara,toChara,cx,cy,callback){ var self = this; chara = self.getCharacter(chara); toChara = self.getCharacter(toChara); var coordinate = toChara.getTo(); self.characterMoveTo(chara,coordinate[0] + cx,coordinate[1] + cy,callback); };
LRPGCharacter.moveToCharacter = function (value,start,end){ var params = value.substring(start+1,end).split(","), wait; if(params.length == 4){ wait = false; }else{ wait = (parseInt(params.pop()) == 1); } //params:index,index2,x,y LRPGObject.RPGMap.characterMoveToCharacter.call(LRPGObject.RPGMap,params[0],parseInt(params[1]),parseInt(params[2]),parseInt(params[3]),LRPGCharacter.getMoveCallback(wait)); };
RPGCharacter.move(1,4,0,0); RPGCharacter.move(2,4,0,0);
//参数:角色ID,动作,方向(或者角色ID),动作是否循环,是否等待 RPGCharacter.changeAction(2,move,up,0,1); RPGCharacter.changeAction(2,move,left,1); RPGCharacter.changeAction(1,stand,2,1);
MapController.prototype.setActionDirection = function(chara,action,direction,loop,callback){ var self = this; chara = self.getCharacter(chara); if(LString.isInt(direction)){ var toChara = self.getCharacter(direction); var coordinate = chara.getTo(); var coordinateTo = toChara.getTo(); var angle = Math.atan2(coordinateTo[1] - coordinate[1],coordinateTo[0] - coordinate[0])*180/Math.PI + 180; if(angle <= 22.5 || angle >= 337.5){ direction = CharacterDirection.LEFT; }else if(angle > 22.5 && angle <= 67.5){ direction = CharacterDirection.LEFT_UP; }else if(angle > 67.5 && angle <= 112.5){ direction = CharacterDirection.UP; }else if(angle > 112.5 && angle <= 157.5){ direction = CharacterDirection.RIGHT_UP; }else if(angle > 157.5 && angle <= 202.5){ direction = CharacterDirection.RIGHT; }else if(angle > 202.5 && angle <= 247.5){ direction = CharacterDirection.RIGHT_DOWN; }else if(angle > 247.5 && angle <= 292.5){ direction = CharacterDirection.DOWN; }else{ direction = CharacterDirection.LEFT_DOWN; } } chara.setActionDirection(action,direction); if(callback){ if(loop){ callback(); }else{ var fun = function(){ chara.actionObject.anime.stop(); chara.removeEventListener(LEvent.COMPLETE,fun); callback(); }; chara.addEventListener(LEvent.COMPLETE,fun); } } };
LRPGCharacter.changeAction = function (value,start,end){ var params = value.substring(start+1,end).split(","), wait; //params:index,action,direction,loop,wait params[3] = (parseInt(params[3]) == 1); if(params.length == 4){ wait = false; }else{ wait = (parseInt(params.pop()) == 1); } params.push(LRPGCharacter.getActionCallback(wait)); LRPGObject.RPGMap.setActionDirection.apply(LRPGObject.RPGMap,params); }; LRPGCharacter.getActionCallback = function (wait){ var lineValue, callback = LGlobal.script.analysis.bind(LGlobal.script); if(!wait && LGlobal.script.lineList.length > 0){ lineValue = LMath.trim(LGlobal.script.lineList[0]); if(lineValue.indexOf("RPGCharacter.changeAction") == 0){ var start = lineValue.indexOf("("); var end = lineValue.indexOf(")"); var params = lineValue.substring(start+1,end).split(","); if(parseInt(params[3]) == 0)return callback; callback = null; LGlobal.script.analysis(); } } return callback; };
RPGCharacter.changeAction(1,stand,2,1,0); RPGCharacter.changeAction(2,stand,1,1,0);
//人物角色离开场景 //参数:角色ID RPGCharacter.remove(2); //人物角色进入场景 //参数:角色ID,方向,动作,坐标x,坐标y,是否可控 RPGCharacter.add(2,stand,down,52,13,false);
MapController.prototype.addCharacter=function(index,action,direction,x,y,ishero,callback){ var self = this; self.view.addCharaLayer(index,action,direction,x,y,ishero); if(typeof callback == "function")callback(); }; MapController.prototype.removeCharacter=function(index,callback){ var self = this; self.view.removeCharaLayer(index); if(typeof callback == "function")callback(); };
MapView.prototype.removeCharaLayer=function(index){ var self = this; var childList = self.charaLayer.childList,child; for(var i=0,l=childList.length;i<l;i++){ child = childList[i]; if(index == child.index){ self.charaLayer.removeChildAt(i); break; } } };
《游戏脚本的设计与开发》系列文章目录
http://blog.csdn.net/lufy_legend/article/details/8888787
《游戏脚本的设计与开发》-(RPG部分)3.8 通过脚本来自由控制游戏(一)
标签:html5 lufylegend 游戏脚本 剧情 rpg
原文地址:http://blog.csdn.net/lufy_legend/article/details/39011709