├── README.md ├── resource ├── assets │ ├── loading │ │ ├── loading_logo.jpg │ │ ├── loading_tiao.jpg │ │ ├── loading_tiao_bg.jpg │ │ ├── loading_view.png │ │ └── loading_view_bg.png │ └── sound │ │ └── bg.mp3 ├── easygame_config.json ├── loading_main.json ├── loading_view.json └── resource.json └── src └── org └── easygame ├── animate ├── AnimateData.ts ├── AnimateManager.ts └── AnimateTexture.ts ├── component ├── DebugWin.ts ├── DefaultGuideWin.ts ├── DefaultLoadingView.ts ├── DefaultRenderer.ts ├── LoadingBaseUI.ts ├── MessageTips.ts ├── ReceiveGroup.ts ├── Template.ts ├── View.ts ├── Win.ts └── effect │ ├── BaseEffect.ts │ ├── IEffect.ts │ └── RollerDown.ts ├── core ├── GlobalSetting.ts ├── HeartBeat.ts ├── ObjectPool.ts └── Version.ts ├── effect ├── EffectData.ts ├── EffectUtil.ts └── TweenEffect.ts ├── event ├── EventManager.ts ├── EventType.ts └── MyEvent.ts ├── framework ├── EasyGame.ts ├── PopupManager.ts ├── ResManager.ts ├── ViewManager.ts └── msghandle │ ├── BaseHandle.ts │ ├── IHandle.ts │ └── MessageControler.ts ├── guide ├── GuideChapter.ts ├── GuideExecuteManager.ts ├── GuideItem.ts └── GuideManager.ts ├── report ├── Report.ts └── bean │ ├── ReportLogin.ts │ └── ReportShop.ts ├── rpg ├── DirectionUtil.ts ├── RpgSetting.ts ├── animate │ ├── AnimateManager.ts │ ├── BaseAnimate.ts │ ├── EffectAnimate.ts │ ├── HitAnimate.ts │ ├── IAnimate.ts │ ├── ParalleQueue.ts │ └── SequenceQueue.ts ├── astar │ ├── AStar.ts │ ├── BinaryHeap.ts │ ├── Grid.ts │ ├── Link.ts │ └── Node.ts ├── control │ ├── ActorCtrl.ts │ ├── NpcCtrl.ts │ └── PlayerCtrl.ts ├── data │ ├── ActorData.ts │ ├── GameData.ts │ └── IActorData.ts └── display │ ├── Actor.ts │ ├── Camera.ts │ ├── Map.ts │ ├── Npc.ts │ ├── Player.ts │ └── Scene.ts ├── ui ├── BaseGroup.ts ├── Button.ts ├── Group.ts ├── HGroup.ts ├── Image.ts ├── Label.ts ├── LabelImage.ts ├── List.ts ├── ListAd.ts ├── MovieClip.ts ├── ScrollGroup.ts ├── Style.ts ├── TextInput.ts └── Video.ts └── utils ├── DateUtil.ts ├── Debug.ts ├── HitTestUtil.ts ├── HttpUtil.ts ├── LocalStorage.ts ├── MD5.ts ├── MathUtil.ts ├── ObjectUtil.ts ├── ParabolaUtil.ts ├── ProgressCalculate.ts ├── ShakeUtil.ts ├── Sound.ts ├── SpriteUtils.ts ├── StringUtil.ts └── UUID.ts /README.md: -------------------------------------------------------------------------------- 1 | Easy Game For Egret 2 | ========= 3 | 简单易用的easy game游戏框架,让游戏制作飞起来! 4 | 5 | 1.HTML5游戏制作的框架 6 | -------------------- 7 | * 框架基于egret引擎 8 | 9 | 2.我们的目的: 10 | -------------------- 11 | * 提供一整套游戏的解决方案,包括:易用的UI,页面切换,窗口,数据,事件,协议的控制 12 | 13 | * 在UI层,我们会提供一个UI工具,方便生成UI代码 14 | 15 | * 在游戏协议层,我们提供一个协议规范和协议代码生成工具,方便生成协议代码 16 | 17 | 3.为什么UI又造轮子: 18 | -------------------- 19 | * 各种skin方式的UI我们基本不看好,貌似高级,但是对游戏制作来说,绝对是梦魇.高效率的UI才是王道. 20 | * 所以我们的这个轮子可以说简单暴力,但是效率应该最高. 21 | * 不要跟我说皮肤自适应的问题,在小游戏中可以,大点的游戏行不通.在游戏制作中,叫换皮,不会是简单的源素材x2,x3的!甚至规格,尺寸,样式,布局都会改变,因此游戏中换皮基本是全换!UI层得再来一次,未避免重复劳动,总结出来的经验就是把UI独立出来,避免带入逻辑,这样换皮的代价最小. 22 | * 打包的游戏大小也是要重点考虑的问题,因此有必要打造专属游戏的UI.所以我们又造了一遍轮子! 23 | 24 | 4.工具说明: 25 | -------------------- 26 | EasyGame工具中自带了该源码,在使用EasyGame生成项目的时候,会自动在项目是src目录中带入框架源码. 27 | 配套的工具可以从我们的完整上下载,该工具是免费使用的. 28 | 29 | 30 | 5.技术问题,请移步我们的网站: 31 | -------------------- 32 | * http://www.easygame.org 33 | 34 | 6.联系我们 35 | -------------------- 36 | * stonelu 37 | * EMAIL:stonelu@126.com 38 | * QQ:1296199532 39 | 40 | * leon 41 | * EMAIL:420766818@qq.com 42 | * QQ:420766818 43 | -------------------------------------------------------------------------------- /resource/assets/loading/loading_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/loading/loading_logo.jpg -------------------------------------------------------------------------------- /resource/assets/loading/loading_tiao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/loading/loading_tiao.jpg -------------------------------------------------------------------------------- /resource/assets/loading/loading_tiao_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/loading/loading_tiao_bg.jpg -------------------------------------------------------------------------------- /resource/assets/loading/loading_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/loading/loading_view.png -------------------------------------------------------------------------------- /resource/assets/loading/loading_view_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/loading/loading_view_bg.png -------------------------------------------------------------------------------- /resource/assets/sound/bg.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stonelu/easygame/9fc6099a28648879e3952f7cc709a3d3acfe69b1/resource/assets/sound/bg.mp3 -------------------------------------------------------------------------------- /resource/easygame_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"${project_name}", 3 | "product":"${module_name}", 4 | "version":"0.0.1", 5 | "desc":"可自行加入其它配置信息,信息内容自行读取", 6 | "report":{ 7 | "desc":"报表设置,name:渠道的名称,rate:汇率,unit:货币单位,storage:存储(local/net)", 8 | "url":"http://www.easygame.org/", 9 | "provide":1, 10 | "channel":[ 11 | {"id":1, "app_id":"", "name":"easygame", "rate":1, "unit":"元", "storage":"local", "report":false} 12 | ] 13 | }, 14 | "dev":{ 15 | "desc":"开发模式设置,scale_mode:适配方式,debug:debug开关,loading_max:并发下载最大限制", 16 | "scale_mode":"egret", 17 | "debug":"false", 18 | "loading_max":5 19 | } 20 | } -------------------------------------------------------------------------------- /resource/loading_main.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": 3 | [ 4 | {"name":"loading_view","type":"image","url":"assets/loading/loading_view.png"}, 5 | {"name":"loading_view_bg","type":"image","url":"assets/loading/loading_view_bg.png"}, 6 | {"name":"loading_logo","type":"image","url":"assets/loading/loading_logo.jpg"}, 7 | {"name":"loading_tiao","type":"image","url":"assets/loading/loading_tiao.jpg"}, 8 | {"name":"loading_tiao_bg","type":"image","url":"assets/loading/loading_tiao_bg.jpg"} 9 | ], 10 | 11 | "groups": 12 | [ 13 | {"name":"loading_main","keys":"loading_view,loading_view_bg,loading_logo,loading_tiao,loading_tiao_bg"} 14 | ] 15 | } -------------------------------------------------------------------------------- /resource/loading_view.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": 3 | [ 4 | {"name":"loading_view","type":"image","url":"assets/loading/loading_view.png"}, 5 | {"name":"loading_view_bg","type":"image","url":"assets/loading/loading_view_bg.png"}, 6 | {"name":"loading_logo","type":"image","url":"assets/loading/loading_logo.jpg"}, 7 | {"name":"loading_tiao","type":"image","url":"assets/loading/loading_tiao.jpg"}, 8 | {"name":"loading_tiao_bg","type":"image","url":"assets/loading/loading_tiao_bg.jpg"} 9 | ], 10 | 11 | "groups": 12 | [ 13 | {"name":"loading_view","keys":"loading_view,loading_view_bg,loading_logo,loading_tiao,loading_tiao_bg"} 14 | ] 15 | } -------------------------------------------------------------------------------- /resource/resource.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources": 3 | [ 4 | {"name":"easygame_config","type":"json","url":"easygame_config.json"}, 5 | {"name":"sound_bg","type":"sound","soundType":"music","url":"assets/sound/bg.mp3"} 6 | ], 7 | 8 | "groups": 9 | [ 10 | {"name":"sound","keys":"sound_bg"}, 11 | {"name":"group_easygame_config","keys":"easygame_config"} 12 | ] 13 | } -------------------------------------------------------------------------------- /src/org/easygame/animate/AnimateManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 动画数据 30 | */ 31 | export class AnimateManager { 32 | private static _animiateDataDict:any = {}; 33 | 34 | private static waiting_groups:Array = [];//等待下载的group列表 35 | private static waiting_names:Array = [];//等待下载的name列表 36 | private static names_down:Array = [];//已下载的那么集合 37 | 38 | /** 39 | * 获取动画数据 40 | */ 41 | public static getAnimateData(name:string):AnimateData{ 42 | //easy.Debug.log = "getAnimateData=" + name; 43 | if (AnimateManager._animiateDataDict[name]) { 44 | return AnimateManager._animiateDataDict[name]; 45 | } 46 | if (RES.isGroupLoaded(name + "_animate_group")) { 47 | AnimateManager._animiateDataDict[name] = new AnimateData(name); 48 | return AnimateManager._animiateDataDict[name]; 49 | } else { 50 | AnimateManager.loadAnimate(name); 51 | } 52 | return null; 53 | } 54 | /** 55 | * url加载json data数据到RES中 56 | */ 57 | public static loadAnimate(name:string):void { 58 | if (!easy.StringUtil.isUsage(name)) return; 59 | if (AnimateManager.names_down.indexOf(name) >= 0 || RES.isGroupLoaded(name + "_animate_group")) return; 60 | if (AnimateManager.waiting_groups.indexOf(name) < 0) AnimateManager.waiting_groups.push(name); 61 | if (AnimateManager.waiting_names.indexOf(name) < 0) AnimateManager.waiting_names.push(name); 62 | AnimateManager.names_down.push(name); 63 | easy.HeartBeat.addListener(AnimateManager, AnimateManager.onHeartBeatCheckLoadedFile, 60); 64 | } 65 | 66 | /** 67 | * 开始下载数据 68 | * @param name 69 | */ 70 | private static fireDownAnimate(name:string):void { 71 | if (easy.GlobalSetting.isNative()){ 72 | ResManager.loadConfig("resource/assets/animate/" + name + "_loader.json", [name + "_animate_group"], AnimateManager.onLoadingGroupJosnFileComplete, AnimateManager); 73 | } else { 74 | ResManager.loadConfig("resource/assets/animate/" + name + "_loader.json?r=" + Math.floor(Math.random()*9999999999), [name + "_animate_group"], AnimateManager.onLoadingGroupJosnFileComplete, AnimateManager); 75 | } 76 | } 77 | /** 78 | * loading配置文件的Group加载完成 79 | * @param event 80 | */ 81 | private static onLoadingGroupJosnFileComplete(event:RES.ResourceEvent):void{ 82 | //console.log("animate load complete!!!=" + event.groupName); 83 | if (event && easy.StringUtil.isUsage(event.groupName) && event.groupName.indexOf("_animate_group") >=0) { 84 | var groupName:string = event.groupName.substring(0, event.groupName.indexOf("_animate_group")); 85 | if (AnimateManager.waiting_names.indexOf(groupName) >= 0) AnimateManager.waiting_names.splice(AnimateManager.waiting_names.indexOf(groupName),1); 86 | if (AnimateManager.waiting_groups.indexOf(groupName) >= 0) AnimateManager.waiting_groups.splice(AnimateManager.waiting_groups.indexOf(groupName),1); 87 | var myEvent:MyEvent = MyEvent.getEvent(EventType.RESOURCE_DOWNLOADED); 88 | myEvent.addItem("name", groupName); 89 | myEvent.send(); 90 | } 91 | AnimateManager.onHeartBeatCheckLoadedFile(); 92 | } 93 | 94 | /** 95 | * 检测是否有文件没有下载完成,重新加入下载列表中 96 | */ 97 | private static onHeartBeatCheckLoadedFile():void { 98 | if (AnimateManager.waiting_groups.length == 0 && AnimateManager.waiting_names.length == 0) { 99 | easy.HeartBeat.removeListener(AnimateManager, AnimateManager.onHeartBeatCheckLoadedFile); 100 | } 101 | if(AnimateManager.waiting_groups.length > 0 && AnimateManager.waiting_names.length > 0){ 102 | var reloadArr:Array = []; 103 | for(var i = AnimateManager.waiting_names.length-1; i >= 0; i--) { 104 | if (AnimateManager.waiting_groups.indexOf(AnimateManager.waiting_names[i]) >= 0) { 105 | reloadArr.push(AnimateManager.waiting_names[i]); 106 | AnimateManager.waiting_names.splice(i,1); 107 | AnimateManager.waiting_groups.splice(AnimateManager.waiting_groups.indexOf(AnimateManager.waiting_names[i]),1); 108 | } 109 | } 110 | var resName:string = null; 111 | while(reloadArr.length > 0) { 112 | //easy.Debug.log = "onHeartBeatCheckLoadedFile 111111111111111"; 113 | AnimateManager.fireDownAnimate(reloadArr.pop()); 114 | } 115 | } 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /src/org/easygame/animate/AnimateTexture.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 动画元数据 30 | */ 31 | export class AnimateTexture { 32 | public id:string = null;//名称 33 | public frame:number = 0;//播放时长 34 | public width:number = 0;//材质宽 35 | public height:number = 0;//材质高 36 | public x:number = 0;//x值 37 | public y:number = 0;//y值 38 | public offsetX:number = 0;//offset x值 39 | public offsetY:number = 0;//offset y值 40 | public texutre:egret.Texture = null;//材质 41 | public resId:string = null;//不合并的时候的资源id 42 | public constructor() { 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/org/easygame/component/DefaultGuideWin.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class DefaultGuideWin extends Win{ 30 | public constructor(){ 31 | super(); 32 | } 33 | 34 | /** 35 | * 创建对象 36 | */ 37 | public createChildren():void { 38 | super.createChildren(); 39 | } 40 | 41 | public get guideItem():GuideItem{ 42 | if (this._data) return this._data; 43 | return null; 44 | } 45 | /** 46 | * 进入的逻辑 47 | * 可以再次根据外部数据情况做一些逻辑处理 48 | */ 49 | public enter():void { 50 | if (this.guideItem){ 51 | this.x += this.guideItem.oxWin; 52 | this.y += this.guideItem.oyWin; 53 | } 54 | super.enter(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/org/easygame/component/DefaultLoadingView.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class DefaultLoadingView extends LoadingBaseUI { 29 | 30 | private _gridWidth:number = 256; 31 | private _gridHeight:number = 256; 32 | 33 | private _bmpBg:egret.Bitmap = null;//bg 34 | private _bmpLogo:egret.Bitmap = null;//logo 35 | 36 | public constructor() { 37 | super(); 38 | } 39 | public createChildren():void { 40 | super.createChildren(); 41 | this.showBg = false; 42 | this.setSize(this._gridWidth, this._gridHeight); 43 | 44 | this._bmpBg = new egret.Bitmap(); 45 | this.addChild(this._bmpBg); 46 | this._bmpBg.texture = RES.getRes("loading_view_bg"); 47 | this._bmpBg.anchorOffsetX = this._bmpBg.width * 0.5; 48 | this._bmpBg.anchorOffsetY = this._bmpBg.height * 0.5; 49 | this._bmpBg.x = this.cx; 50 | this._bmpBg.y = this.cy; 51 | 52 | this._bmpLogo = new egret.Bitmap(); 53 | this.addChild(this._bmpLogo); 54 | this._bmpLogo.texture = RES.getRes("loading_view"); 55 | this._bmpLogo.anchorOffsetX = this._bmpLogo.width * 0.5; 56 | this._bmpLogo.anchorOffsetY = this._bmpLogo.height * 0.5; 57 | this._bmpLogo.x = this.cx; 58 | this._bmpLogo.y = this.cy; 59 | } 60 | /** 61 | * 根据waitview的ui数据,进行下载控制 62 | */ 63 | public enter():void { 64 | super.enter(); 65 | this._bmpBg.rotation = 0; 66 | this.alpha = 0; 67 | //显示loading图像 68 | HeartBeat.addListener(this, this.onShowLoadingGraphics); 69 | } 70 | /** 71 | * 完成下载,回调加载view 72 | */ 73 | public outer():void { 74 | super.outer(); 75 | //console.log("@@LoadingViewUI outer") 76 | HeartBeat.removeListener(this, this.onShowLoadingGraphics); 77 | } 78 | /** 79 | * 显示下载进度的图形 80 | */ 81 | public onShowLoadingGraphics():void { 82 | if (this.alpha < 1) this.alpha += 0.05; 83 | this._bmpBg.rotation += 2; 84 | this._bmpLogo.rotation -= 1; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/org/easygame/component/DefaultRenderer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class DefaultRenderer extends Group{ 30 | /** 31 | * 对应的ui展现 32 | */ 33 | public _ui:BaseGroup = null; 34 | /** 35 | * ui资源已准备好 36 | * @type {boolean} 37 | * @private 38 | */ 39 | public _uiResReady:boolean = false; 40 | 41 | public _selected:boolean; 42 | /** 43 | * item render所在的list 44 | * @type {null} 45 | */ 46 | public list:List = null; 47 | 48 | public constructor(){ 49 | super(); 50 | } 51 | 52 | public createChildren():void{ 53 | super.createChildren(); 54 | this.setSize(100, 65); 55 | } 56 | /** 57 | * 设置数据 58 | */ 59 | public set data(value:any){ 60 | this._data = value; 61 | this.invalidate(); 62 | } 63 | public get data():any{ 64 | return this._data; 65 | } 66 | /** 67 | * 刷新 68 | */ 69 | public refresh():void { 70 | this.data = this._data; 71 | } 72 | 73 | /** 74 | * 设置选中 75 | */ 76 | public set selected(value:boolean){ 77 | this.setSelected(value); 78 | } 79 | public setSelected(value:boolean){ 80 | if (this._selected != value) { 81 | this._selected = value; 82 | this.invalidate(); 83 | } 84 | } 85 | public get selected():boolean{ 86 | return this._selected; 87 | } 88 | /** 89 | * 获取ui层的显示对象 90 | * @returns {egret.Sprite} 91 | */ 92 | public getUI():any { 93 | return this._ui; 94 | } 95 | /** 96 | * 设置ui层的显示对象 97 | * @param myui 98 | */ 99 | public setUI(myui:BaseGroup) { 100 | this._ui = myui; 101 | //console.log("!!!view set ui!! 000 this._ui=" + egret.getQualifiedClassName(this._ui)); 102 | if (this._ui) { 103 | this.addChild(this._ui); 104 | this.setSize(this._ui.width, this._ui.height); 105 | //console.log("!!!view set ui!! 1111 this._ui=" + egret.getQualifiedClassName(this._ui)); 106 | } 107 | this.showBg = false; 108 | } 109 | /** 110 | * 做ui的销毁 111 | * 一般情况下,需要手动调用销毁 112 | */ 113 | public destroy():void { 114 | if (this._ui){ 115 | //if (this._ui.hasOwnProperty("destroy"))this._ui.destroy(); 116 | this._ui = null; 117 | } 118 | } 119 | /** 120 | * 首次材质下载完成会调用加载一次,刷新UI皮肤显示 121 | * 使用了框架的UI机制,单ui的资源下载完成会调用改方法刷新 122 | * 若view中有逻辑使用到ui的素材,应该在这里做素材的赋值 123 | */ 124 | public validateNow():void{ 125 | //console.log("clz=" + egret.getQualifiedClassName(this) + ", validateNow!!") 126 | if (this._ui && this._ui["validateNow"]) this._ui["validateNow"](); 127 | this.drawDelay = false; 128 | if (this._ui)this._ui.drawDelay = false; 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /src/org/easygame/component/MessageTips.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 一个文字提示显示 30 | */ 31 | export class MessageTips extends BaseGroup { 32 | private static _instance:MessageTips = null;// 33 | private _dulation:number = 15;//停留时间 34 | private _mssageArr:Array = [];//消息内容 35 | private speed:number = 5;//文字移动的速度 36 | 37 | private _labelArr:Array = [];//当前正在显示的label 38 | 39 | private _showNext:boolean = false;//可以显示下一条 40 | 41 | public constructor() { 42 | super(); 43 | } 44 | public static getInstance():MessageTips{ 45 | if (MessageTips._instance == null) MessageTips._instance = new MessageTips(); 46 | return MessageTips._instance; 47 | } 48 | 49 | /** 50 | * 显示弹出的文字内容 51 | * @param msg 52 | */ 53 | public static showMessage(msg:string, delay:number = 0, color:number = 0xfff666, x:number = 65535, y:number= 65535,speed:number = 5):void { 54 | MessageTips.getInstance().showMsg(msg, delay, color, x, y, speed); 55 | } 56 | 57 | /** 58 | * 显示message提示信息 59 | * @param msg 60 | * @param color 61 | */ 62 | public showMsg(msg:string, delay:number = 0, color:number = 0xfff666, x:number = 65535, y:number= 65535,speed:number = 5):void { 63 | HeartBeat.addListener(this, this.onHeartBeat); 64 | if (this._labelArr.length == 0) this._showNext = true; 65 | this._mssageArr.push({msg:msg, color:color, x:x, y:y, delay:delay, speed:speed}); 66 | } 67 | /** 68 | * 呼吸计算位移 69 | */ 70 | private onHeartBeat():void { 71 | if (this._labelArr.length == 0 && this._mssageArr.length == 0) { 72 | HeartBeat.removeListener(this, this.onHeartBeat); 73 | return; 74 | } 75 | var label:Label = null; 76 | if(this._showNext && this._mssageArr.length > 0){//新文字,加入上浮 77 | var item:Object = this._mssageArr.shift(); 78 | label =ObjectPool.getByClass(Label, "msgtips");//从缓存中拿一个label 79 | label.text = item["msg"]; 80 | label.color = item["color"]; 81 | label.bold = true; 82 | //label.stroke = 1; 83 | //label.strokeColor = 0x000000; 84 | label.alpha = 0; 85 | label.fontSize = 40; 86 | label.showBg = false; 87 | label.autoSize = true; 88 | if (item["delay"] > 0) { 89 | label.setData(-item["delay"]);//计数停留时间帧 90 | } else { 91 | label.setData(0);//计数停留时间帧 92 | } 93 | easy.GlobalSetting.STAGE.addChild(label); 94 | label.draw(); 95 | if (item["x"] == 65535){ 96 | label.x = GlobalSetting.DISPLAY_WIDTH/2 - label.cx; 97 | } else { 98 | label.x = item["x"]; 99 | } 100 | if (item["y"] == 65535){ 101 | label.y = GlobalSetting.DISPLAY_HEIGHT/2; 102 | } else { 103 | label.y = item["y"]; 104 | } 105 | this._labelArr.push({label:label,speed:item["speed"]}); 106 | //console.log("x=" + label._x + ", y=" + label._y + ", ix=" + item["x"] + ",iy=" + item["y"]) 107 | } 108 | for (var i = 0; i< this._labelArr.length; i++){ 109 | item = this._labelArr[i]; 110 | label = item["label"]; 111 | if (label.getData() < 0) { 112 | label.setData(label.getData() + 1); 113 | continue; 114 | } 115 | //if (label._y == ViewManager.currentView.cy/2 && label.getData() < this._dulation) {//停留 116 | // label.setData(label.getData() + 1); 117 | //} else { 118 | if (label.getData() < this._dulation) { 119 | label.y -= item["speed"]; 120 | label.alpha += 0.1; 121 | } else { 122 | label.y -= (item["speed"] + 3); 123 | label.alpha -= 0.1; 124 | } 125 | //} 126 | if (label.y < 0){//回收 127 | this._labelArr.splice(i,1); 128 | label.removeFromParent(); 129 | ObjectPool.recycleClass(label, "msgtips"); 130 | } 131 | var sp:egret.DisplayObject = ViewManager.currentView; 132 | if (sp == null) sp = easy.GlobalSetting.STAGE; 133 | if (i == (this._labelArr.length - 1) && (sp.height/2 - this._labelArr[i].y) > 5){ 134 | this._showNext = true; 135 | } 136 | } 137 | 138 | } 139 | } 140 | } -------------------------------------------------------------------------------- /src/org/easygame/component/Template.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy{ 28 | /** 29 | * view和win的基本类 30 | * 定义了接收协议packet和event的能力,方便在已经展示的时候,通过packet和event的事件进行驱动刷新显示 31 | */ 32 | export class Template extends ReceiveGroup { 33 | public constructor() { 34 | super(); 35 | } 36 | /** 37 | * outer的过渡效果 38 | */ 39 | public outerTransition():void { 40 | //super.outerTransition();//调用父类的话,就会被移除 41 | //TODO 可以覆盖这里,写自己想要的out效果 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/org/easygame/component/Win.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy{ 28 | /** 29 | * win的基本类 30 | * 所有的ui组件都应该放置在ui层中 31 | * 在win中只处理view相关的逻辑,对ui成层的组件进行操作 32 | */ 33 | export class Win extends ReceiveGroup { 34 | /** 35 | * 进入的效果 36 | */ 37 | private _outerEffect:IEffect = null; 38 | /** 39 | * win成对应的ui展现 40 | * @type {null} 41 | * @private 42 | */ 43 | public constructor() { 44 | super(); 45 | this._loadingUIClz = PopupManager.defaultLoadingClass; 46 | } 47 | public createChildren():void { 48 | super.createChildren(); 49 | } 50 | /** 51 | * enter的过渡效果 52 | */ 53 | public enterTransition():void { 54 | super.enterTransition(); 55 | } 56 | /** 57 | * enter的过渡效果结束 58 | */ 59 | public enterTransitionComplete():void { 60 | super.enterTransitionComplete(); 61 | } 62 | /** 63 | * win进入的逻辑 64 | * 可以再次根据外部数据情况做一些逻辑处理 65 | */ 66 | public enter():void { 67 | super.enter(); 68 | var key:string = egret.getQualifiedClassName(this); 69 | var myEvent:easy.MyEvent = easy.MyEvent.getEvent(easy.EventType.WIN_ENTER); 70 | myEvent.addItem("data", key); 71 | myEvent.send(); 72 | } 73 | 74 | /** 75 | * win退出的逻辑 76 | * 做一些数据的销毁或者初始化,保证下次进入的时候,不会残留 77 | */ 78 | public outer():void { 79 | super.outer(); 80 | var key:string = egret.getQualifiedClassName(this); 81 | var myEvent:easy.MyEvent = easy.MyEvent.getEvent(easy.EventType.WIN_OUTER); 82 | myEvent.addItem("data", key); 83 | myEvent.send(); 84 | } 85 | 86 | /** 87 | * 舞台尺寸变化 88 | */ 89 | public onStageResize():void { 90 | //super.onStageResize(); 91 | this.x = ViewManager.currentView.cx - this.cx; 92 | this.y = ViewManager.currentView.cy - this.cy; 93 | //调整当前view的loading的位置 94 | var loading:LoadingBaseUI = ObjectPool.getByClass(this._loadingUIClz, "loadingwin", false); 95 | if (loading && loading.parent){//loading 在显示中 96 | loading.x = 0; 97 | loading.y = 0; 98 | } 99 | } 100 | 101 | /** 102 | * 关闭窗口类 103 | */ 104 | public hiddent():void { 105 | easy.PopupManager.hidden(this); 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /src/org/easygame/component/effect/BaseEffect.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class BaseEffect implements IEffect{ 29 | public _outerTarget:ReceiveGroup = null; 30 | public _enterTarget:ReceiveGroup = null; 31 | public constructor() { 32 | } 33 | 34 | /** 35 | * 准备数据,播放效果 36 | */ 37 | public play():void { 38 | this._enterTarget = ViewManager._waitChangeView; 39 | this._outerTarget = ViewManager.currentView; 40 | if (this._enterTarget == this._outerTarget)this._outerTarget = null; 41 | this.onPlayEffect(); 42 | } 43 | 44 | public onPlayEffect():void { 45 | if (this._outerTarget)this._outerTarget.outerTransition(); 46 | if (this._enterTarget)this._enterTarget.enterTransition(); 47 | } 48 | public onEffectComplete():void { 49 | if (this._outerTarget)this._outerTarget.outerTransitionComplete(); 50 | if (this._enterTarget)this._enterTarget.enterTransitionComplete(); 51 | this._outerTarget = null; 52 | this._enterTarget = null; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/org/easygame/component/effect/IEffect.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export interface IEffect { 29 | play():void; 30 | } 31 | } -------------------------------------------------------------------------------- /src/org/easygame/component/effect/RollerDown.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class RollerDown extends BaseEffect{ 29 | public constructor() { 30 | super(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/easygame/core/ObjectPool.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 对象池,针对经常创建的对象进行 回收并复用,减少对象创建的消耗 30 | * 不给垃圾回收的机会 31 | */ 32 | export class ObjectPool { 33 | private static _dataPool:any = {};//池数据 34 | //public static length:number = 0;//长度 35 | /** 36 | * 传入一个class,给你一个class对象的实例 37 | * 使用class的名称作为对象映射的key 38 | * 该class的构造函数必须是无参数要求 39 | * 从对象池中提取Object 40 | * @param clz 要提取的objec的Class 41 | * @return clz 对象的实例 42 | */ 43 | public static getByClass(clz:any, flag:string = "", pop:boolean = true):any { 44 | var key:string = egret.getQualifiedClassName(clz); 45 | key = flag + key; 46 | var item:any = ObjectPool.getObject(key, pop); 47 | if (item == null) item = new clz(); 48 | if (!pop) { 49 | ObjectPool.recycleClass(item, flag); 50 | } 51 | return item; 52 | } 53 | 54 | /** 55 | * 释放object,使得objec返回到pool池,可以继续重复利用 56 | * 使用class的名称作为对象映射的key 57 | * @param item 要返回池中的item对象 58 | */ 59 | public static recycleClass(obj:any, flag:string = ""):void { 60 | if (!obj) return; 61 | var key:string = egret.getQualifiedClassName(obj); 62 | key = flag + key; 63 | ObjectPool.recycleObject(key, obj); 64 | } 65 | 66 | /** 67 | * 查询是否有某class名称的对象池存在 68 | * @param clz 69 | * @returns {any} 70 | */ 71 | public static hasClass(clz:any, flag:string = ""):boolean { 72 | return ObjectPool.getByClass(clz, flag, false); 73 | } 74 | 75 | /** 76 | * 根据name从对象池中提取Object 77 | * @param name 要提取的objec的name 78 | * @param pop 是否从对象池中弹出 79 | * @return clz 对象的实例 80 | */ 81 | public static getObject(name:string, pop:boolean = true):any { 82 | if (ObjectPool._dataPool.hasOwnProperty(name) && ObjectPool._dataPool[name].length > 0) { 83 | var obj:any = null; 84 | if (pop) { 85 | obj = ObjectPool._dataPool[name].pop(); 86 | if (ObjectPool._dataPool[name].length == 0) delete ObjectPool._dataPool[name]; 87 | } else { 88 | obj = ObjectPool._dataPool[name][0]; 89 | } 90 | return obj; 91 | } 92 | return null; 93 | } 94 | 95 | /** 96 | * 使用name存储对象 97 | * @param item 98 | * @param name 99 | * @param group 100 | */ 101 | public static setObject(name:string, item:any):void { 102 | ObjectPool.recycleObject(name, item); 103 | } 104 | 105 | /** 106 | * 回收对象,使用name存储 107 | * 反之,通过name提取 108 | * @param name 109 | * @param item 110 | */ 111 | public static recycleObject(name:string, item:any):void { 112 | if (!item) return; 113 | if (!ObjectPool._dataPool.hasOwnProperty(name)) { 114 | ObjectPool._dataPool[name] = []; 115 | } 116 | if (item.hasOwnProperty("destroy"))item.destroy(); 117 | if (ObjectPool._dataPool[name].indexOf(item) < 0) { 118 | ObjectPool._dataPool[name].push(item); 119 | } 120 | } 121 | 122 | /** 123 | * 查询是否有name名称的对象池存在 124 | * @param name 125 | * @returns {any} 126 | */ 127 | public static hasObject(name:string):boolean { 128 | return ObjectPool.getObject(name, false); 129 | } 130 | 131 | /** 132 | * 释放所有clz归属的objec的引用 133 | * 获取class的名称作为对象映射的key,把对应的对象列表引用释放 134 | * @param clz 要释放的objec的Class 135 | */ 136 | public static dispose(clz:any):void { 137 | var key:string = egret.getQualifiedClassName(clz); 138 | ObjectPool.disposeObjects(key); 139 | } 140 | 141 | /** 142 | * 释放某个对象池的所有对象 143 | * 获取name对应的对象列表, 把引用释放 144 | * @param name 145 | */ 146 | public static disposeObjects(name:string):void { 147 | if (ObjectPool._dataPool.hasOwnProperty(name)) { 148 | ObjectPool._dataPool[name].length = 0; 149 | delete ObjectPool._dataPool[name]; 150 | } 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /src/org/easygame/core/Version.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy{ 28 | /** 29 | * 框架的版本号 30 | */ 31 | export class Version { 32 | public static version:string = "0.0.40"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/org/easygame/effect/EffectData.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class EffectData { 30 | 31 | public oldX:number = 0; 32 | public oldY:number = 0; 33 | public newX:number = 0; 34 | public newY:number = 0; 35 | 36 | public oldAlpha:number = 0; 37 | public newAlpha:number = 0; 38 | 39 | public oldRotation:number = 0; 40 | public newRotation:number = 0; 41 | 42 | public oldScaleX:number = 0; 43 | public newScaleX:number = 0; 44 | public oldScaleY:number = 0; 45 | public newScaleY:number = 0; 46 | 47 | public oldAnchorX:number = 0; 48 | public newAnchorX:number = 0; 49 | public oldAnchorY:number = 0; 50 | public newAnchorY:number = 0; 51 | public anchorEnabled:boolean = false; 52 | 53 | public isPlay:boolean = false;//当前是否播放 54 | public loop:boolean = false;//是否循环 55 | 56 | 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /src/org/easygame/event/EventType.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class EventType { 30 | public static SOCKET_CONNECT:string = "SOCKET_CONNECT";//socket连接完成 31 | public static SOCKET_DISCONNECT_ERROR:string = "SOCKET_DISCONNECT_ERROR";//socket异常 32 | public static SOCKET_DISCONNECT:string = "SOCKET_DISCONNECT";//socket连接断开 33 | public static SOCKET_SEND_SHOW:string = "SOCKET_SEND_SHOW";//socket发送数据显示等待框 34 | public static SOCKET_SEND_HIDE:string = "SOCKET_SEND_HIDE";//socket发送数据隐藏等待框 35 | public static SOCKET_SEND_TIMEOUT:string = "SOCKET_SEND_TIMEOUT";//socket发送超时 36 | 37 | public static STAGE_RESIZE:string = "STAGE_RESIZE";//屏幕尺寸变化 38 | public static UI_CONFIG_VOLUME:string = "UI_CONFIG_VOLUME";//声音开关 39 | public static UI_CONFIG_FULLSCREEN:string = "UI_CONFIG_FULLSCREEN";//全屏信号 40 | public static UI_LOADER_COMPLETED:string = "UI_LOADER_COMPLETED";//loader下载完成事件 41 | //动画播放事件 42 | public static MOVIEWCLIP_PLAY:string = "MOVIEWCLIP_PLAY";//动画播放事件 43 | public static MOVIEWCLIP_PLAY_END:string = "MOVIEWCLIP_PLAY_END";//动画播放事件 44 | //debug模式事件 45 | public static UI_DEBUG_OPEN:string="DEBUG_UI_OPEN"; //debug ui的开启 46 | public static UI_DEBUG_CLOSE:string="DEBUG_UI_CLOSE"; //debug ui的关闭 47 | 48 | public static VOLUME_CHANGED:string = "VOLUME_CHANGED";//音乐开关改变 49 | 50 | public static RESOURCE_DOWNLOADED:string = "RESOURCE_DOWNLOADED";//资源下载完成{id:id, group:group} 51 | public static RESOURCE_PROGRESS:string = "RESOURCE_PROGRESS";//资源下载进度通知 52 | public static PROJECT_RES_DOWNLOADED:string = "PROJECT_RES_DOWNLOADED";//项目公用资源加载完成 53 | 54 | public static GUIDE_FREEDBACK:string="GUIDE_FREEDBACK"; //通知新手导航管理器专用 55 | public static GUIDE_END:string="GUIDE_END"; //新手导航向结束 56 | public static GUIDE_SIMULATE:string="GUIDE_SIMULATE"; //新手导航模拟 57 | //view enter事件{data=class name} 58 | public static VIEW_ENTER:string = "VIEW_ENTER"; 59 | //view outer事件{data=class name} 60 | public static VIEW_OUTER:string = "VIEW_OUTER"; 61 | //win enter事件{data=class name} 62 | public static WIN_ENTER:string = "WIN_ENTER"; 63 | //win outer事件{data=class name} 64 | public static WIN_OUTER:string = "WIN_OUTER"; 65 | 66 | /** 67 | * 新手引导-{"type":0,可接受任务;1,可完成任务。} 68 | */ 69 | public static GUIDE_TASK_TALKING_NOTIFY:string = "GUIDE_TASK_TALKING_NOTIFY";//任务对话通知 70 | /** 71 | * 新手导航参数通知,参数为定制内容 72 | */ 73 | public static GUIDE_PARAM_NOTIFY:string = "GUIDE_PARAM_NOTIFY";//新手导航参数通知 74 | /** 75 | * 新手引导-对话面板关闭. 76 | */ 77 | public static GUIDE_WIN_CLOSE_NOTIFY:string = "GUIDE_WIN_CLOSE_NOTIFY"; 78 | public static GUIDE_TASK_CLOSE_NOTIFY:string = "GUIDE_TASK_CLOSE_NOTIFY"; 79 | /** 80 | * 停止新手引导播放 81 | */ 82 | public static GUIDE_STOP_ITEM:string = "GUIDE_STOP_ITEM"; 83 | 84 | 85 | /** 86 | * 剧情模式 {"action":value} 87 | */ 88 | public static STORY_TALKING:string = "STORY_TALKING"; 89 | /** 90 | * 剧情结束. 91 | */ 92 | public static STORY_END:string = "STORY_END"; 93 | 94 | //guide产生的event执行事件通知 95 | public static GUIDE_EVENT_EXE:string = "GUIDE_EVENT_EXE"; 96 | //guide 事件执行完毕 97 | public static GUIDE_EVENT_END:string = "GUIDE_EVENT_END"; 98 | //剧情章节结束 99 | public static GUIDE_CHAPTER_END:string = "GUIDE_CHAPTER_END"; 100 | //声音结束 101 | public static SOUND_COMPLETE:string = "SOUND_COMPLETE"; 102 | public static SOUND_STOP:string = "SOUND_STOP"; 103 | //视频结束 104 | public static VIDEO_END:string = "VIDEO_END"; 105 | } 106 | } -------------------------------------------------------------------------------- /src/org/easygame/event/MyEvent.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class MyEvent { 29 | public callStack:string = null; 30 | public type:string = null; 31 | public datas:Object = {}; 32 | 33 | /** 34 | *

事件基类构造函数,包含一个参数

35 | * @param type 事件类型 36 | */ 37 | public constructor(typeValue:string) { 38 | this.type = typeValue; 39 | } 40 | 41 | /** 42 | *

添加单个对象到结果集中

43 | * @param value 要添加的对象 44 | */ 45 | 46 | public addItem(property:string, value:any):void { 47 | this.datas[property] = value; 48 | } 49 | 50 | /** 51 | * 获取property对应的内容 52 | * @param property 53 | * @returns {null} 54 | */ 55 | public getItem(property:string):any { 56 | if (this.datas.hasOwnProperty(property)){ 57 | return this.datas[property]; 58 | } 59 | return null; 60 | } 61 | 62 | /** 63 | * 查询是否携带了proprty名称的数据 64 | * @param property 65 | * @returns {boolean} 66 | */ 67 | public hasItem(property:string):any { 68 | return this.datas.hasOwnProperty(property); 69 | } 70 | 71 | /** 72 | * 回收对象到对象池中 73 | */ 74 | public destory():void { 75 | this.callStack = null; 76 | for (var item in this.datas) { 77 | delete this.datas[item]; 78 | } 79 | } 80 | 81 | /** 82 | * 删除property名称的数据 83 | * @param proprty 84 | */ 85 | public removeItem(property:string):boolean { 86 | if (this.datas.hasOwnProperty(property)){ 87 | delete this.datas[property]; 88 | return true; 89 | } 90 | return false; 91 | } 92 | 93 | /** 94 | * 派发event对象 95 | */ 96 | public send():void { 97 | EventManager.dispatchEvent(this); 98 | } 99 | 100 | /** 101 | * 从对象池中获取一个type类型的event对象 102 | * @param type 103 | * @returns {MyEvent} 104 | */ 105 | public static getEvent(type:string):MyEvent { 106 | return EventManager.getEvent(type); 107 | } 108 | 109 | /** 110 | * 快捷发送一个type类型的event事件 111 | * @param type 112 | */ 113 | public static sendEvent(type:string, param:any = null):void { 114 | EventManager.dispatch(type, param); 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /src/org/easygame/framework/msghandle/BaseHandle.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 数据集中处理 30 | */ 31 | export class BaseHandle implements IHandle{ 32 | public METHOD_DEF:Object = {};//消息和方法的映射关系表 33 | public EVENT_DEF:Array = []; 34 | public constructor() { 35 | this.initWeekListener(); 36 | } 37 | 38 | /** 39 | * 初始化弱监听 40 | * 子类可以覆写这个,添加数据 41 | */ 42 | public initWeekListener():void { 43 | 44 | } 45 | 46 | /** 47 | * 添加事件的处理 48 | * 如果没有对应的的类型在此出现,则改Handle对Event事件到此为止,不再派发,防止造成事件死循环 49 | * @param type MyEvent事件的类型 50 | */ 51 | public addHandleEvent(type:string, funcName:string):void { 52 | if (this.EVENT_DEF.indexOf(type) < 0) { 53 | this.EVENT_DEF.push(type); 54 | this.METHOD_DEF[type] = funcName; 55 | } 56 | } 57 | 58 | /** 59 | * 添加协议处理的Handle,注意,functName的名称,前缀onPacket不包含 60 | * @param msgId packet协议号 61 | * @param func 对应的call back function,不包含onPacket前缀 62 | */ 63 | public addHandlePacket(msgId:number, funcName:string):void { 64 | this.METHOD_DEF[""+msgId] = funcName; 65 | //console.log("BaseHandle ADD METHOD_DEF=" + msgId + ", funcName=" + funcName); 66 | } 67 | 68 | /** 69 | * 接收到服务器的控制信号 70 | * call function的时候,会自动前缀onPacket 71 | * @param packet 72 | */ 73 | public receivePacket(packet:any):void { 74 | //console.log("BaseHandle onPacketData=" + egret.getQualifiedClassName(this) + ", has=" + this.METHOD_DEF.hasOwnProperty("" + packet.header.messageId)); 75 | if (this.METHOD_DEF.hasOwnProperty("" + packet.header.messageId))this["onPacket" + this.METHOD_DEF["" + packet.header.messageId]].call(this, packet); 76 | } 77 | 78 | /** 79 | * 事件派发 80 | * call function的时候,会自动前缀onEvent 81 | * @param event 82 | */ 83 | public receiveEvent(event:MyEvent):void { 84 | if (this.EVENT_DEF.indexOf(event.type) >= 0) { 85 | if (this.METHOD_DEF.hasOwnProperty(event.type)) this["onEvent" + this.METHOD_DEF[event.type]].call(this, event); 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/org/easygame/framework/msghandle/IHandle.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export interface IHandle { 29 | receivePacket(packet:any):void; 30 | receiveEvent(event:MyEvent):void; 31 | } 32 | } -------------------------------------------------------------------------------- /src/org/easygame/framework/msghandle/MessageControler.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class MessageControler { 29 | private static _handles:Array = []; 30 | private static _eventHandles:Array = []; 31 | 32 | /** 33 | * 添加数据处理的Handle 34 | * 逻辑处理模块,需要添加Handle,以便方便的在view刷新前,有限得到数据,预先处理数据 35 | * @param handle 36 | */ 37 | public static addHandle(handle:IHandle):void { 38 | if (handle != null && MessageControler._handles.indexOf(handle) < 0 )MessageControler._handles.push(handle); 39 | } 40 | 41 | /** 42 | * 添加弱事件处理 43 | * 只有注册的时间,当前的view才能收到 44 | * @param eventName 45 | */ 46 | public static addEvent(eventName:string):void { 47 | if (MessageControler._eventHandles.indexOf(eventName) < 0) MessageControler._eventHandles.push(eventName); 48 | } 49 | 50 | /** 51 | * MyEvent事件派发 52 | * @param event 53 | */ 54 | public static receiveEvent(event:MyEvent):void { 55 | //console.log("MessageControl onEventData=" + event.type) 56 | if (MessageControler._eventHandles.indexOf(event.type) >= 0){ 57 | ViewManager.receiveEvent(event); 58 | var i:number = 0; 59 | for (i = 0; i < MessageControler._handles.length; i++) { 60 | MessageControler._handles[i].receiveEvent(event); 61 | } 62 | } 63 | } 64 | 65 | /** 66 | * 协议事件派发 67 | * @param pkt 68 | */ 69 | public static receivePacket(pkt:any):void { 70 | //console.log("MessageHandle onPacketData=" + egret.getQualifiedClassName(pkt)); 71 | //优先处理数据的handle 72 | var i:number = 0; 73 | for (i = 0; i < MessageControler._handles.length; i++) { 74 | MessageControler._handles[i].receivePacket(pkt); 75 | } 76 | //界面刷新 77 | ViewManager.receivePacket(pkt); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /src/org/easygame/guide/GuideChapter.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class GuideChapter { 30 | //ID 31 | public id:string = null; 32 | //名称 33 | public name:string = null; 34 | //类型 35 | public type:string = null; 36 | //起始item 37 | public item:string = null; 38 | 39 | public constructor(){ 40 | } 41 | /** 42 | * 转义特殊的字符 43 | */ 44 | public escapeChars():void { 45 | //name 46 | this.name = StringUtil.replace(this.name, "{~D!}", ","); 47 | this.name = StringUtil.replace(this.name, "{~N!}", "\n"); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/org/easygame/guide/GuideExecuteManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 新手执行管理器 30 | */ 31 | export class GuideExecuteManager { 32 | private _condition:string = "befor";//befor after 33 | private _item:GuideItem = null; 34 | private _currentClz:any = null;//当前窗口类 35 | //剧情结束的时候,需要回调的无参数function 36 | private _completeCallFunc:Function = null;// 37 | private _completeCallFuncThis:any = null;// 38 | public constructor(){ 39 | EventManager.addEventListener(easy.EventType.GUIDE_EVENT_END, this.onMyEventGuideExecuteEnd, this); 40 | } 41 | 42 | /** 43 | * 事件执行完毕 44 | * @param myEvent 45 | */ 46 | private onMyEventGuideExecuteEnd(myEvent:MyEvent):void { 47 | if (this._item && this._item.id == myEvent.getItem("item_id")) { 48 | if (this._condition == "befor"){ 49 | GuideManager.playItem(this._item, this._currentClz, this._completeCallFunc, this._completeCallFuncThis, false) 50 | } else { 51 | GuideManager.currentItem = this._item; 52 | GuideManager._completeCallFunc = this._completeCallFunc; 53 | GuideManager._completeCallFuncThis = this._completeCallFuncThis; 54 | GuideManager.currentClz = this._currentClz; 55 | GuideManager.playNextItem(false); 56 | } 57 | this._item = null; 58 | this._completeCallFunc = null; 59 | this._completeCallFuncThis = null; 60 | this._currentClz = null; 61 | } 62 | } 63 | 64 | /** 65 | * 节点前执行事件 66 | * @returns {boolean} 67 | */ 68 | public executeBefor(item:GuideItem, clz:any = null, completeCallFunc:Function = null, thisFunc:any = null):void { 69 | if (easy.StringUtil.isUsage(item.event_data)){ 70 | this._condition = "befor"; 71 | this._item = item; 72 | this._completeCallFunc = completeCallFunc; 73 | this._completeCallFuncThis = thisFunc; 74 | this._currentClz = clz; 75 | var myEvent:MyEvent = MyEvent.getEvent(easy.EventType.GUIDE_EVENT_EXE); 76 | myEvent.addItem("event_data", item.event_data); 77 | myEvent.addItem("item_id", item.id); 78 | myEvent.send(); 79 | } 80 | } 81 | /** 82 | * 节点后执行事件 83 | * @returns {boolean} 84 | */ 85 | public executeAfter(item:GuideItem, clz:any = null, completeCallFunc:Function = null, thisFunc:any = null):void { 86 | if (easy.StringUtil.isUsage(item.event_data)){ 87 | this._condition = "after"; 88 | this._item = item; 89 | this._completeCallFunc = completeCallFunc; 90 | this._completeCallFuncThis = thisFunc; 91 | this._currentClz = clz; 92 | var myEvent:MyEvent = MyEvent.getEvent(easy.EventType.GUIDE_EVENT_EXE); 93 | myEvent.addItem("event_data", item.event_data); 94 | myEvent.addItem("item_id", item.id); 95 | myEvent.send(); 96 | } 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /src/org/easygame/guide/GuideItem.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class GuideItem { 30 | public static MASK_NONE:string = "none";//无遮罩 31 | public static MASK_NORMAL:string = "guide";//通用遮罩 32 | public static MASK_CROPPING:string = "cropping";//遮幅 33 | //ID编号 34 | public id:string = null; 35 | //节点名称 36 | public name:string = null; 37 | //描述 38 | public desc:string = null; 39 | //节点类型 40 | public type:string = null; 41 | //章节 42 | public chapter:string = null; 43 | //目标 44 | public target:string = null; 45 | //下一帧 46 | public next_frame:string = null; 47 | //下一帧延迟 48 | public next_delay:number = 0; 49 | //对话内容 50 | public text:string = null; 51 | //点击次数 52 | public click_num:number = 0; 53 | //任意点击 54 | public click_stage:number = 1; 55 | //旁白 56 | public aside:boolean = false; 57 | //水平对齐 58 | public h_align:string = null; 59 | //水平偏移量 60 | public h_pos:number = 0; 61 | //竖直对齐 62 | public v_align:string = null; 63 | //竖直偏移量 64 | public v_pos:number = 0; 65 | //肖像id 66 | public icon:string = null; 67 | //icon偏移x 68 | public oxIcon:number = 0; 69 | //icon偏移y 70 | public oyIcon:number = 0; 71 | //win偏移x 72 | public oxWin:number = 0; 73 | //win偏移y 74 | public oyWin:number = 0; 75 | //肖像k=v数据 76 | public data:string = null; 77 | //显示名称 78 | public nick:string = null; 79 | //头像镜像 80 | public mirror:number = 0; 81 | //显示方式 82 | public txt_model:string = null; 83 | //显示速度 84 | public txt_frame:number = 0; 85 | //遮罩方式 86 | public mask:string = null; 87 | //选项 88 | public opts:string = null; 89 | //事件数据 90 | public event_data:string = null; 91 | //事件条件 92 | public event_condition:string = null; 93 | 94 | //新手的句柄 95 | public handle_type:string = null; 96 | public handle_path:string = null; 97 | public handle_data:string = null; 98 | //handle设定 99 | //新手的焦点 100 | public focus_color:string = null; 101 | public focus_stress:number = 0; 102 | public focus_gap:number = 0; 103 | public focus_x:number = 0; 104 | public focus_y:number = 0; 105 | public focus_data:string = null; 106 | 107 | public constructor(){ 108 | } 109 | 110 | /** 111 | * 转义特殊的字符 112 | */ 113 | public escapeChars():void { 114 | //name 115 | this.name = StringUtil.replace(this.name, "{~D!}", ","); 116 | this.name = StringUtil.replace(this.name, "{~N!}", "\n"); 117 | //nick 118 | this.nick = StringUtil.replace(this.nick, "{~D!}", ","); 119 | this.nick = StringUtil.replace(this.nick, "{~N!}", "\n"); 120 | //text 121 | this.text = StringUtil.replace(this.text, "{~D!}", ","); 122 | this.text = StringUtil.replace(this.text, "{~N!}", "\n"); 123 | //focuse 124 | this.focus_color = StringUtil.replace(this.focus_color, "{~D!}", ","); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /src/org/easygame/report/Report.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class Report { 29 | private static _loader:egret.URLLoader = null; 30 | public static _isInit:boolean = false; 31 | /** 32 | * channel 渠道 33 | * ver 版本 34 | * device 设备 35 | * time 时间 36 | * token 随机值 37 | */ 38 | public static _baseInfo:Object = null; 39 | 40 | /** 41 | * 通用统计信息 42 | */ 43 | public static send(data:any, sufixUrl:string = "", token:string = ""):void { 44 | if (!GlobalSetting.REPORT) { 45 | return; 46 | } 47 | if (!Report._isInit){ 48 | console.log("[error]:report not init!") 49 | return; 50 | } 51 | if (Report._baseInfo == null) { 52 | console.log("[error]:report not ready!") 53 | return; 54 | } 55 | if (Report._loader == null){ 56 | Report._loader = new egret.URLLoader(); 57 | Report._loader.dataFormat = egret.URLLoaderDataFormat.BINARY; 58 | } 59 | if (token && token.length > 0){ 60 | Report._baseInfo["tk"] = Math.round(Math.random()*99999999);//随机token 61 | } else { 62 | Report._baseInfo["tk"] = token;//随机token 63 | } 64 | Report._baseInfo["ti"] = Date.now(); 65 | 66 | var varData:egret.URLVariables = new egret.URLVariables(); 67 | varData.variables = {}; 68 | 69 | if(data["getReportData"]) { 70 | data = data.getReportData(); 71 | } 72 | 73 | for (var key in data){ 74 | //console.log(key + "=" + data[key]); 75 | if (key != "__class__") { 76 | varData.variables[key] = data[key]; 77 | } 78 | 79 | } 80 | for (var key in Report._baseInfo){ 81 | //console.log(key + "==" + Report._baseInfo[key]); 82 | if (key != "__class__") { 83 | varData.variables[key] = Report._baseInfo[key]; 84 | } 85 | } 86 | 87 | var req:egret.URLRequest = new egret.URLRequest(); 88 | req.data = varData;// 89 | req.method = egret.URLRequestMethod.POST; 90 | req.url = GlobalSetting.REPORT_URL + sufixUrl; 91 | Report._loader.load(req); 92 | console.log("[repor]:" + JSON.stringify(req.data)); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /src/org/easygame/report/bean/ReportLogin.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class ReportLogin { 29 | public id:number = 0;//编号 30 | public name:string = ""; //名称 31 | public type:string = ""; //类型 32 | public isNew:boolean = false;//新玩家 33 | public constructor() { 34 | } 35 | /** 36 | * 生成统计的form数据 37 | * @param obj 38 | */ 39 | public getReportData():any { 40 | var obj:any = {}; 41 | obj.uid = this.id; //商店编号 42 | obj.un = this.name; //付费点 43 | obj.tp = this.type;//类型 44 | obj.nw = this.isNew;//新玩家 45 | for (var key in this){ 46 | if (key != "id" && key != "name" && key != "type" && key != "getReportData" && key != "__class__") { 47 | obj[key] = this[key]; 48 | } 49 | } 50 | return obj; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/org/easygame/report/bean/ReportShop.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class ReportShop { 29 | public id:number = 0;//商店编号 30 | public orderId:string = "";//订单号,对账 31 | public name:string = ""; //付费点 32 | public rmb:number = 0; //费用 33 | public type:string = ""; //类型 34 | //结果 35 | public state:string = "";//订单状态 36 | public msg:string = "";//订单返回描述 37 | 38 | public ext1:string = "";//备用1 39 | public ext2:string = "";//备用2 40 | 41 | public constructor() { 42 | } 43 | /** 44 | * 生成统计的form数据 45 | * @param obj 46 | */ 47 | public getReportData():any { 48 | var obj:any = {}; 49 | obj.sid = this.id; //商店编号 50 | obj.un = this.name; //付费点 51 | obj.rmb = this.rmb;//人民币 52 | obj.tp = this.type;//类型 53 | 54 | obj.oid = this.orderId;//订单号 55 | obj.st = this.state;//订单状态 56 | obj.msg = this.msg;//订单返回描述 57 | obj.e1 = this.ext1;//备用1 58 | obj.e2 = this.ext2;//备用2 59 | for (var key in this){ 60 | if (key != "id" && key != "name" && key != "rmb" && key != "type" && key != "getReportData" && key != "__class__") { 61 | obj[key] = this[key]; 62 | } 63 | } 64 | return obj; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/RpgSetting.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class RpgSetting { 29 | public static SHOW_OTHER_PLAYER:boolean = true;//显示其他玩家 30 | 31 | public static ACTOR_TYPE_NPC:string = "npc"; 32 | public static ACTOR_TYPE_PLAYER:string = "player"; 33 | public static ACTOR_TYPE_BUILDING:string = "building"; 34 | //public static ACTOR_TYPE_:string = ""; 35 | 36 | 37 | 38 | public static PLAYER_ID:number = 0;//ME ID 39 | 40 | public static ACTOR_STD:string = "std";//人物站立 41 | public static ACTOR_MOV:string = "mov";//人物行走 42 | public static ACTOR_DIE:string = "die";//人物死亡 43 | public static ACTOR_ATK:string = "atk";//人物攻击 44 | public static ACTOR_BAK:string = "bak";//人物被攻击 45 | public static ACTOR_SKL:string = "skl";//人物释放技能 46 | 47 | /** 48 | * 方向定义, valve,保持和动作序列的下标一致 49 | * n 50 | * wn ne 51 | * w e 52 | * sw es 53 | * s 54 | * 55 | * [1] 56 | * [2] [8] 57 | * [3] [7] 58 | * [4] [6] 59 | * [5] 60 | */ 61 | public static DIRECTION_8:number = 8; 62 | public static DIRECTION_7:number = 7; 63 | public static DIRECTION_6:number = 6; 64 | public static DIRECTION_5:number = 5; 65 | public static DIRECTION_4:number = 4; 66 | public static DIRECTION_3:number = 3; 67 | public static DIRECTION_2:number = 2; 68 | public static DIRECTION_1:number = 1; 69 | public static DIRECTION_0:number = 0;//无此方向 70 | 71 | public static DIRECT_NUMBER:number =RpgSetting.DIRECT_2;//角色状态的方向材质数量定义 72 | public static DIRECT_2:number = 2;//2方向,提供3的材质 73 | public static DIRECT_4:number = 4;//4方向,提供2,4的材质 74 | public static DIRECT_6:number = 6;//6,提供2,3,4的材质 75 | public static DIRECT_8:number = 8;//8方向1,2,3,4,5的材质 76 | 77 | public static BUFF_CENTER_FRONT:string = "centre_F";//中前 78 | public static BUFF_CENTER_BACK:string = "centre_B";//中后 79 | public static BUFF_ABOVE:string = "above";//上 80 | public static BUFF_BELOW_BACK:string = "below_B";//下后 81 | public static BUFF_BELOW_FRONT:string = "below_F";//下前 82 | public static EFFECT_MISSILE:string = "missile";//飞行 83 | 84 | //战斗命令类型 85 | /** 86 | * 移动命令 87 | */ 88 | public static FIGHT_ACTION_MOV:number = 0; 89 | /** 90 | * 攻击命令 91 | */ 92 | public static FIGHT_ACTION_SKILL:number = 1; 93 | /** 94 | * 血量变化命令 95 | */ 96 | public static FIGHT_ACTION_CHANGE_HP:number = 2; 97 | /** 98 | * 死亡命令 99 | */ 100 | public static FIGHT_ACTION_DIE:number = 3; 101 | /** 102 | * 战斗结果命令 103 | */ 104 | public static FIGHT_ACTION_TYPE_RESULT:number = 4; 105 | /** 106 | * 傀儡能量值刷新. 107 | */ 108 | public static FIGHT_ACTION_TYPE_ENEYGY:number = 5; 109 | /** 110 | * 战斗角色获得buff通知. 111 | */ 112 | public static FIGHT_ACTION_TYPE_BUFF:number = 6; 113 | 114 | //战斗伤害类型 115 | /** 116 | * 攻击伤害,普通 117 | */ 118 | public static FIGHT_DAMEGE_COMMON:number = 0; 119 | /** 120 | * 攻击伤害,闪避 121 | */ 122 | public static FIGHT_DAMEGE_DODGE:number = 1; 123 | /** 124 | * 攻击伤害,暴击 125 | */ 126 | public static FIGHT_DAMEGE_CRIT:number = 2; 127 | /** 128 | * 攻击伤害,效果 129 | */ 130 | public static FIGHT_DAMEGE_EFFECT:number = 3; 131 | /** 132 | * 攻击伤害,抵抗 133 | */ 134 | public static FIGHT_DAMEGE_RESISTANCE:number = 4; 135 | /** 136 | * 移动同步总帧时 137 | */ 138 | public static MOVE_SYNC_FRAME_COUNT:number = 5; 139 | //任务 任务内容类型 1:杀怪 2:对话 140 | public static TASK_TYPE_DIALOGUE:number = 2; 141 | public static TASK_TYPE_KILL:number = 1; 142 | /** 143 | * 技能类型:通用 144 | */ 145 | public static BATTLE_SKILL_TYPE_COM:number = 0; 146 | /** 147 | * 技能类型:受击 148 | */ 149 | public static BATTLE_SKILL_TYPE_BAK:number = 1; 150 | 151 | 152 | /** 角色的身处场景的状态要求 */ 153 | public static GAME_STATE_FIGHT:string = "fight";//战斗状态 154 | public static GAME_STATE_NORMAL:string = "normal";//正常态 155 | public static GAME_STATE_ALL:string = "all";//全显示 156 | public static GAME_STATE_NONE:string = "none";//全都不显示 157 | } 158 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/animate/AnimateManager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class AnimateManager { 30 | private _isRun:boolean = false; 31 | private _isFrozen:boolean = false; 32 | private _animateList:Array = []; 33 | 34 | private static _instance:AnimateManager = null; 35 | public static getInstance():AnimateManager { 36 | if (AnimateManager._instance == null) AnimateManager._instance = new easy.rpg.AnimateManager(); 37 | return AnimateManager._instance; 38 | } 39 | /** 40 | * 动画控制开始 41 | */ 42 | private start():void { 43 | if (!this._isRun){ 44 | //this._animateList.length = 0; 45 | easy.HeartBeat.addListener(this, this.onHeartBeat); 46 | this._isRun = true; 47 | this._isFrozen = false; 48 | } 49 | } 50 | /** 51 | * 战斗控制结束 52 | */ 53 | public stop():void { 54 | //console.log("AnimateManager Stop") 55 | this._isRun = false; 56 | this._animateList.length = 0; 57 | easy.HeartBeat.removeListener(this, this.onHeartBeat); 58 | } 59 | /** 60 | * 添加动画 61 | */ 62 | public addAnimate(animate:IAnimate):void { 63 | this._animateList.push(animate); 64 | this.start(); 65 | } 66 | /** 67 | * 删除动画 68 | */ 69 | public removeAnimate(animate:IAnimate):void { 70 | for (var i:number = 0; i < this._animateList.length; i++) { 71 | if (this._animateList[i] == animate) { 72 | this._animateList[i].stop(); 73 | this._animateList[i].destroy(); 74 | this._animateList.splice(i, 1); 75 | break; 76 | } 77 | } 78 | if (this._animateList.length == 0) this.stop(); 79 | } 80 | /** 81 | * 清空所有特效操作 82 | */ 83 | public removeAllAnimate():void { 84 | for (var i:number = 0; i < this._animateList.length; i++) { 85 | this._animateList[i].destroy(); 86 | } 87 | this._animateList.length = 0; 88 | } 89 | /** 90 | * 冻结 91 | * @param value 92 | */ 93 | public frozen(value:boolean):void { 94 | if (this._isRun){ 95 | this._isFrozen = value; 96 | for (var i:number = 0; i < this._animateList.length; i++) { 97 | this._animateList[i].frozen = value; 98 | } 99 | } 100 | } 101 | /** 102 | * 暂停播放 103 | */ 104 | public pause():void{ 105 | this.frozen(true); 106 | } 107 | /** 108 | * 继续播放 109 | */ 110 | public replay():void { 111 | this.frozen(false); 112 | } 113 | /** 114 | * 心跳,呼吸, 运动的之类要覆盖该方法,做动作 115 | */ 116 | public onHeartBeat():void { 117 | if (!this._isRun || this._isFrozen) return; 118 | var length1:number = this._animateList.length; 119 | //console.log("Animate onHeartBeat.len=" + length1); 120 | for(var i1:number = 0;i1 < length1;i1++){ 121 | var item:IAnimate = this._animateList[i1]; 122 | item.onHeartBeat(); 123 | //console.log("Animate onHeartBeat item.delay=" + item.delayFrame + ", completed=" + item.completed + ", after=" + item.afterFrame); 124 | if (!item.runing && item.delayFrame <= 0)item.play(); 125 | } 126 | var i:number = 0; 127 | for (i = this._animateList.length - 1; i >= 0; i--) { 128 | if (this._animateList[i].completed && this._animateList[i].afterFrame <= 0){ 129 | this._animateList[i].destroy(); 130 | this._animateList.splice(i, 1); 131 | } 132 | } 133 | //console.log("Animate 111 onHeartBeat.len=" + this._animateList.length); 134 | if (this._animateList.length == 0) this.stop(); 135 | } 136 | 137 | /** 138 | * 根据技能生成动画调度 139 | * @param jsonSkill 140 | */ 141 | public genSkillAnimateQueue(jsonSkill:number):void { 142 | //console.log("genSkillAnimateQueue"); 143 | var effectAnimate:EffectAnimate = ObjectPool.getByClass(EffectAnimate); 144 | effectAnimate.scene = ViewManager.currentView.scene; 145 | effectAnimate.skillId = jsonSkill; 146 | effectAnimate.actorSrc = ViewManager.currentView.scene.cameraFoucs; 147 | effectAnimate.actorDes = ViewManager.currentView.scene.getActorById(10001).actor; 148 | this.addAnimate(effectAnimate); 149 | } 150 | } 151 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/animate/HitAnimate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | /** 29 | * 受击动画 30 | * @author Administrator 31 | * 32 | */ 33 | export class HitAnimate extends BaseAnimate { 34 | public skillId:number = 0;//技能id 35 | public actorSrc:Actor = null;//技能起始人 36 | public actorDes:Actor = null;//技能目标 37 | public constructor(){ 38 | super(); 39 | } 40 | /** 41 | * 播放动画 42 | */ 43 | public play():void { 44 | if (this.skillId > 0 ){ 45 | this._resJsonId = "skill_json_" + this.skillId; 46 | this._resImgId = "skill_img_" + this.skillId; 47 | this.jsonData = RES.getRes(this._resJsonId); 48 | } 49 | super.play();//设置runing标志 50 | this._imgDisplay.x = this.actorDes._ctrl.gameData._screenXY.x; 51 | this._imgDisplay.y = this.actorDes._ctrl.gameData._screenXY.y; 52 | } 53 | // 54 | ///** 55 | // * 心跳,呼吸, 运动的之类要覆盖该方法,做动作 56 | // */ 57 | //public onHeartBeat():void { 58 | // super.onHeartBeat(); 59 | // //if (_effectMovieClip)trace("MovieClip width=" + _effectMovieClip.width + ", height=" + _effectMovieClip.height + ", pivotX=" + this._effectMovieClip.pivotX + ", pivotY=" + this._effectMovieClip.pivotY) 60 | // if((this.runing && this._effectMovieClip && this._effectMovieClip.parent == null) || this._effectMovieClip == null){ 61 | // this.stop(); 62 | // } 63 | //} 64 | /** 65 | * 销毁数据 66 | */ 67 | public destroy():void { 68 | super.destroy(); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/animate/IAnimate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export interface IAnimate { 30 | onHeartBeat():void; 31 | play():void; 32 | stop():void; 33 | destroy():void; 34 | getDisplay():egret.DisplayObject; 35 | runing:boolean; 36 | completed:boolean; 37 | parent:IAnimate; 38 | afterFrame:number; 39 | delayFrame:number; 40 | frozen:boolean; 41 | } 42 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/animate/ParalleQueue.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | /** 30 | *

并行效果

31 | * @date :Jun 18, 2012 32 | * @author:jinyi.lu 33 | */ 34 | export class ParalleQueue extends easy.rpg.BaseAnimate { 35 | private animateList:Array = new Array();//并行动画的列表 36 | 37 | public constructor(){ 38 | super(); 39 | } 40 | /** 41 | * 心跳,呼吸, 运动的之类要覆盖该方法,做动作 42 | */ 43 | public onHeartBeat():void { 44 | super.onHeartBeat(); 45 | if (this.runing){ 46 | if (this.animateList.length > 0) { 47 | for (var i = this.animateList.length - 1; i >= 0; i--) { 48 | if (this.animateList[i].completed && this.animateList[i].afterFrame <= 0) { 49 | this.removeAnimate(this.animateList[i]); 50 | } 51 | } 52 | var item:IAnimate = null; 53 | var length1:number = this.animateList.length; 54 | for (var i = 0; i < length1; i++) { 55 | item = this.animateList[i]; 56 | item.onHeartBeat(); 57 | if (!item.runing && item.delayFrame <= 0)item.play(); 58 | } 59 | } 60 | if (this.animateList.length == 0) this.stop(); 61 | } 62 | } 63 | /** 64 | * 添加一个并行动画 65 | */ 66 | public addAnimate(animate:IAnimate):void { 67 | animate.parent = this; 68 | this.animateList.push(animate); 69 | } 70 | /** 71 | * 删除一个串行动画 72 | */ 73 | public removeAnimate(animate:IAnimate):void { 74 | for (var i = 0; i < this.animateList.length; i++) { 75 | if (this.animateList[i] == animate) { 76 | this.animateList[i].stop(); 77 | this.animateList[i].destroy(); 78 | this.animateList.splice(i, 1); 79 | break; 80 | } 81 | } 82 | } 83 | /** 84 | * 销毁数据 85 | */ 86 | public destroy():void{ 87 | super.destroy(); 88 | for (var i = 0; i < this.animateList.length; i++) { 89 | this.animateList[i].destroy(); 90 | } 91 | this.animateList.length = 0; 92 | } 93 | 94 | public set frozen(value:boolean){ 95 | this._frozen = value; 96 | for (var i = 0; i < this.animateList.length; i++) { 97 | this.animateList[i].frozen = value; 98 | } 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/animate/SequenceQueue.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | /** 29 | *

串行效果

30 | * @date :Jun 18, 2012 31 | * @author:jinyi.lu 32 | */ 33 | export class SequenceQueue extends easy.rpg.BaseAnimate { 34 | private animateList:Array = new Array();//串行动画的列表 35 | public constructor(){ 36 | super(); 37 | } 38 | /** 39 | * 心跳,呼吸, 运动的之类要覆盖该方法,做动作 40 | */ 41 | public onHeartBeat():void { 42 | if (this.runing) { 43 | if (this.animateList.length > 0) { 44 | if (this.animateList[0].completed && this.animateList[i].afterFrame <= 0){ 45 | this.removeAnimate(this.animateList[0]); 46 | } 47 | if (this.animateList.length > 0) { 48 | if (!this.animateList[0].runing && this.animateList[0].delayFrame <= 0)this.animateList[0].play(); 49 | for (var i = 0; i < this.animateList.length; i++) { 50 | if(this.animateList[i].runing) this.animateList[i].onHeartBeat(); 51 | } 52 | } 53 | } 54 | if (this.animateList.length == 0 )this.stop(); 55 | } 56 | } 57 | /** 58 | * 添加一个串行动画 59 | */ 60 | public addAnimate(animate:IAnimate):void { 61 | animate.parent = this; 62 | this.animateList.push(animate); 63 | } 64 | /** 65 | * 删除一个串行动画 66 | */ 67 | public removeAnimate(animate:IAnimate):void { 68 | for (var i = 0; i < this.animateList.length; i++) { 69 | if (this.animateList[i] == animate) { 70 | this.animateList[i].destroy(); 71 | this.animateList.splice(i, 1); 72 | break; 73 | } 74 | } 75 | } 76 | /** 77 | * 销毁数据 78 | */ 79 | public destroy():void{ 80 | super.destroy(); 81 | for (var i = 0; i < this.animateList.length; i++) { 82 | this.animateList[i].destroy(); 83 | } 84 | this.animateList.length = 0; 85 | } 86 | 87 | public set frozen(value:boolean){ 88 | this._frozen = value; 89 | for (var i:number = 0; i < this.animateList.length; i++) { 90 | this.animateList[i].frozen = value; 91 | } 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/astar/AStar.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class AStar { 30 | private _open:BinaryHeap; 31 | private _grid:Grid; 32 | private _endNode:Node; 33 | private _startNode:Node; 34 | public path:Array; 35 | public heuristic:Function; 36 | private _straightCost:number = 1.0; 37 | private _diagCost:number = Math.SQRT2; 38 | private nowversion:number = 1; 39 | 40 | public constructor(){ 41 | this.heuristic = this.euclidian2; 42 | 43 | } 44 | public get grid():Grid{ 45 | return this._grid; 46 | } 47 | private justMin(x:any, y:any):boolean { 48 | return x.f < y.f; 49 | } 50 | 51 | public findPath(grid:Grid):boolean { 52 | this._grid = grid; 53 | this._endNode = this._grid.endNode; 54 | this.nowversion++; 55 | this._startNode = this._grid.startNode; 56 | //_open = []; 57 | this._open = new BinaryHeap(this.justMin); 58 | this._startNode.g = 0; 59 | return this.search(); 60 | } 61 | 62 | public search():boolean { 63 | var node:Node = this._startNode; 64 | node.version = this.nowversion; 65 | while (node != this._endNode){ 66 | var len:number = node.links.length; 67 | for (var i:number = 0; i < len; i++){ 68 | var test:Node = node.links[i].node; 69 | var cost:number = node.links[i].cost; 70 | var g:number = node.g + cost; 71 | var h:number = this.heuristic(test); 72 | var f:number = g + h; 73 | if (test.version == this.nowversion){ 74 | if (test.f > f){ 75 | test.f = f; 76 | test.g = g; 77 | test.h = h; 78 | test.parent = node; 79 | } 80 | } else { 81 | test.f = f; 82 | test.g = g; 83 | test.h = h; 84 | test.parent = node; 85 | this._open.ins(test); 86 | test.version = this.nowversion; 87 | } 88 | 89 | } 90 | if (this._open.a.length == 1){ 91 | return false; 92 | } 93 | node = (this._open.pop()); 94 | } 95 | this.buildPath(); 96 | return true; 97 | } 98 | 99 | private buildPath():void { 100 | this.path = new Array(); 101 | var node:Node = this._endNode; 102 | this.path.push(node); 103 | while (node != this._startNode){ 104 | node = node.parent; 105 | this.path.unshift(node); 106 | } 107 | } 108 | 109 | public manhattan(node:Node):number { 110 | return Math.abs(node.row - this._endNode.row) + Math.abs(node.column - this._endNode.column); 111 | } 112 | 113 | public manhattan2(node:Node):number { 114 | var dx:number = Math.abs(node.row - this._endNode.row); 115 | var dy:number = Math.abs(node.column - this._endNode.column); 116 | return dx + dy + Math.abs(dx - dy) / 1000; 117 | } 118 | 119 | public euclidian(node:Node):number { 120 | var dx:number = node.row - this._endNode.row; 121 | var dy:number = node.column - this._endNode.column; 122 | return Math.sqrt(dx * dx + dy * dy); 123 | } 124 | 125 | private TwoOneTwoZero:number = 2 * Math.cos(Math.PI / 3); 126 | 127 | public chineseCheckersEuclidian2(node:Node):number { 128 | var y:number = node.column / this.TwoOneTwoZero; 129 | var x:number = node.row + node.column / 2; 130 | var dx:number = x - this._endNode.row - this._endNode.column / 2; 131 | var dy:number = y - this._endNode.column / this.TwoOneTwoZero; 132 | return this.sqrt(dx * dx + dy * dy); 133 | } 134 | 135 | private sqrt(x:number):number { 136 | return Math.sqrt(x); 137 | } 138 | 139 | public euclidian2(node:Node):number { 140 | var dx:number = node.row - this._endNode.row; 141 | var dy:number = node.column - this._endNode.column; 142 | return dx * dx + dy * dy; 143 | } 144 | 145 | public diagonal(node:Node):number { 146 | var dx:number = Math.abs(node.row - this._endNode.row); 147 | var dy:number = Math.abs(node.column - this._endNode.column); 148 | var diag:number = Math.min(dx, dy); 149 | var straight:number = dx + dy; 150 | return this._diagCost * diag + this._straightCost * (straight - 2 * diag); 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/astar/BinaryHeap.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class BinaryHeap { 30 | public a:Array = new Array(); 31 | public justMinFun:Function = function(x:any, y:any):boolean { 32 | return this.x < this.y; 33 | }; 34 | 35 | public constructor(justMinFun:Function = null){ 36 | this.a.push(-1); 37 | if (justMinFun != null) 38 | this.justMinFun = justMinFun; 39 | } 40 | 41 | public ins(value:any):void { 42 | var p:number = this.a.length; 43 | this.a[p] = value; 44 | var pp:number = p >> 1; 45 | while (p > 1 && this.justMinFun(this.a[p], this.a[pp])){ 46 | var temp:any = this.a[p]; 47 | this.a[p] = this.a[pp]; 48 | this.a[pp] = temp; 49 | p = pp; 50 | pp = p >> 1; 51 | } 52 | } 53 | 54 | public pop():any { 55 | var min:any = this.a[1]; 56 | this.a[1] = this.a[this.a.length - 1]; 57 | this.a.pop(); 58 | var p:number = 1; 59 | var l:number = this.a.length; 60 | var sp1:number = p << 1; 61 | var sp2:number = sp1 + 1; 62 | while (sp1 < l){ 63 | if (sp2 < l){ 64 | var minp:number = this.justMinFun(this.a[sp2], this.a[sp1]) ? sp2 : sp1; 65 | } else { 66 | minp = sp1; 67 | } 68 | if (this.justMinFun(this.a[minp], this.a[p])){ 69 | var temp:any = this.a[p]; 70 | this.a[p] = this.a[minp]; 71 | this.a[minp] = temp; 72 | p = minp; 73 | sp1 = p << 1; 74 | sp2 = sp1 + 1; 75 | } else { 76 | break; 77 | } 78 | } 79 | return min; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/astar/Grid.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class Grid { 30 | private _startNode:Node = null; 31 | private _endNode:Node = null; 32 | private _nodes:Array> = null; 33 | private _numCols:number = 0; 34 | private _numRows:number = 0; 35 | private _cellSize:number = 20; 36 | 37 | private type:number = 0; 38 | 39 | private _straightCost:number = 1.0; 40 | private _diagCost:number = Math.SQRT2; 41 | 42 | public constructor(gridData:Array, cellSize:number = 0){ 43 | this._numRows = gridData.length; 44 | this._numCols = gridData[0].length; 45 | this._cellSize = cellSize; 46 | this._nodes = new Array>(); 47 | 48 | for (var i:number = 0; i < this._numCols; i++){ 49 | this._nodes[i] = new Array(); 50 | for (var j:number = 0; j < this._numRows; j++){ 51 | this._nodes[i][j] = new Node(i, j, gridData[j][i]); 52 | this._nodes[i][j].point.x = i * this._cellSize + this._cellSize/2; 53 | this._nodes[i][j].point.y = j * this._cellSize + this._cellSize/2; 54 | } 55 | } 56 | } 57 | 58 | public get cellSize():number { 59 | return this._cellSize; 60 | } 61 | 62 | /** 63 | * 64 | * @param type 0四方向 1八方向 2跳棋 65 | */ 66 | public calculateLinks(type:number = 0):void { 67 | this.type = type; 68 | for (var i:number = 0; i < this._numCols; i++){ 69 | for (var j:number = 0; j < this._numRows; j++){ 70 | this.initNodeLink(this._nodes[i][j], type); 71 | } 72 | } 73 | } 74 | 75 | public getType():number { 76 | return this.type; 77 | } 78 | 79 | /** 80 | * 81 | * @param node 82 | * @param type 0八方向 1四方向 2跳棋 83 | */ 84 | private initNodeLink(node:Node, type:number = 0):void { 85 | var startX:number = Math.max(0, node.row - 1); 86 | // var endX:int = Math.min(numCols - 1, node.row); 87 | var endX:number = Math.min(this.numCols - 1, node.row + 1); 88 | 89 | var startY:number = Math.max(0, node.column - 1); 90 | // var endY:int = Math.min(numRows - 1, node.column); 91 | var endY:number = Math.min(this.numRows - 1, node.column + 1); 92 | 93 | node.links = new Array(); 94 | for (var i:number = startX; i <= endX; i++){ 95 | for (var j:number = startY; j <= endY; j++){ 96 | var test:Node = this.getNode(i, j); 97 | if (test == node || !test.walkable){ 98 | continue; 99 | } 100 | if (type != 2 && i != node.row && j != node.column){ 101 | var test2:Node = this.getNode(node.row, j); 102 | if (!test2.walkable){ 103 | continue; 104 | } 105 | test2 = this.getNode(i, node.column); 106 | if (!test2.walkable){ 107 | continue; 108 | } 109 | } 110 | var cost:number = this._straightCost; 111 | if (!((node.row == test.row) || (node.column == test.column))){ 112 | if (type == 1){ 113 | continue; 114 | } 115 | if (type == 2 && (node.row - test.row) * (node.column - test.column) == 1){ 116 | continue; 117 | } 118 | if (type == 2){ 119 | cost = this._straightCost; 120 | } else { 121 | cost = this._diagCost; 122 | } 123 | } 124 | node.links.push(new Link(test, cost)); 125 | } 126 | } 127 | } 128 | 129 | public getNode(x:number, y:number = 0):Node { 130 | return this._nodes[x][y]; 131 | } 132 | 133 | public setEndNode(x:number, y:number = 0):void { 134 | this._endNode = this._nodes[x][y]; 135 | } 136 | 137 | public setStartNode(x:number, y:number = 0):void { 138 | this._startNode = this._nodes[x][y]; 139 | } 140 | 141 | public setWalkable(x:number, y:number, value:boolean):void { 142 | this._nodes[x][y].walkable = value; 143 | } 144 | 145 | public get endNode():Node { 146 | return this._endNode; 147 | } 148 | 149 | public get numCols():number { 150 | return this._numCols; 151 | } 152 | 153 | public get numRows():number { 154 | return this._numRows; 155 | } 156 | 157 | public get startNode():Node { 158 | return this._startNode; 159 | } 160 | } 161 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/astar/Link.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class Link { 30 | public node:Node = null; 31 | public cost:number = 0; 32 | 33 | public constructor(node:Node, cost:number){ 34 | this.node = node; 35 | this.cost = cost; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/astar/Node.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | 29 | export class Node { 30 | public row:number = 0;//行 31 | public column:number = 0;//列 32 | public f:number = 0; 33 | public g:number = 0; 34 | public h:number = 0; 35 | public walkable:boolean = true; 36 | public alpha:number = 1; 37 | public data:number = 0; 38 | public parent:Node = null; 39 | public version:number = 1; 40 | public links:Array; 41 | public point:egret.Point = null; 42 | 43 | public constructor(row:number, column:number, value:number = 0){ 44 | this.row = row; 45 | this.column = column; 46 | this.data = value; 47 | if (this.data == 0) { 48 | this.walkable = false; 49 | } else { 50 | this.walkable = true; 51 | } 52 | this.point = new egret.Point(); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/control/NpcCtrl.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class NpcCtrl extends ActorCtrl{ 29 | public constructor() { 30 | super(null, null); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/control/PlayerCtrl.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class PlayerCtrl extends ActorCtrl{ 29 | public constructor() { 30 | super(null, null); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/data/ActorData.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class ActorData implements IActorData{ 29 | public id:number = 0;//角色id 30 | public name:string = null;//名称 31 | public hp:number = 0;//角色血量 32 | public speed:number = 20;//行走速度 33 | public direciton:Array = [];//技能标号组 34 | public wing:number = 0;//翅膀编号 (使用的时候会后缀自动加方向编号,格式::{编号}_{方向}, 例如:3000_1) 35 | public mount:number = 0;//坐骑编号 (使用的时候会后缀自动加方向编号,格式::{编号}_{方向}, 例如:4000_1) 36 | 37 | public type:string = "npc"; 38 | public constructor() { 39 | } 40 | 41 | /** 42 | * 通过json数据赋值 43 | * 请保证json属性和类属性一致 44 | * @param json 45 | */ 46 | public setJsonData(json:any):void { 47 | for (var key in json){ 48 | console.log("Actor set key=" + key + ", value=" + json[key]); 49 | if (this.hasOwnProperty(key)) this[key] = json[key]; 50 | } 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/data/IActorData.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export interface IActorData { 29 | id:number;//角色id 30 | name:string;//名称 31 | hp:number;//角色血量 32 | speed:number;//行走速度 33 | direciton:Array;//方向 34 | wing:number;//翅膀编号 (使用的时候会后缀自动加方向编号,格式::{编号}_{方向}, 例如:3000_1) 35 | mount:number;//坐骑编号 (使用的时候会后缀自动加方向编号,格式::{编号}_{方向}, 例如:4000_1) 36 | type:string;//数据类型 37 | } 38 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/display/Actor.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class Actor extends easy.Group{ 29 | public hitRect:egret.Rectangle = null;//战斗攻击碰撞使用的矩形 30 | public backGroup:easy.BaseGroup = null;//后置效果容器 31 | public frontGroup:easy.BaseGroup = null;//前置效果容器 32 | 33 | public _bitmapActor:egret.Bitmap = null;//角色的显示 34 | 35 | public _ctrl:ActorCtrl = null; 36 | 37 | private _dotShape:egret.Shape = null; 38 | private _hitShape:egret.Shape = null; 39 | /** 40 | * 构造角色 41 | * @param data 角色的原始数据,这个必须是要设置的,否者没法显示 42 | * @param control 角色的控制器,不给的话,就用默认的内置控制器 43 | */ 44 | public constructor(data:IActorData, control?:ActorCtrl) { 45 | super(); 46 | this._ctrl = control; 47 | if (this._ctrl == null){ 48 | this._ctrl = new easy.rpg.ActorCtrl(this, data); 49 | } 50 | } 51 | /** 52 | * 初始化主场景的组件 53 | * 这个方法在对象new的时候就调用,因为有些ui必须在加入stage之前就准备好 54 | * 子类覆写该方法,添加UI逻辑 55 | */ 56 | public createChildren():void { 57 | super.createChildren(); 58 | this.hitRect = new egret.Rectangle(); 59 | 60 | this.backGroup = new easy.BaseGroup(); 61 | this.frontGroup = new easy.BaseGroup(); 62 | 63 | this._bitmapActor = new egret.Bitmap(); 64 | //this._bitmapActor.anchorX = 0.5; 65 | //this._bitmapActor.anchorY = 0.5; 66 | 67 | //this.addChild(this.backGroup); 68 | this.addChild(this._bitmapActor); 69 | //this.addChild(this.frontGroup); 70 | this.anchorX = 0.5; 71 | this.anchorY = 1; 72 | //this.touchEnabled = true; 73 | 74 | this._hitShape = new egret.Shape(); 75 | this._dotShape = new egret.Shape(); 76 | 77 | //this.addChild(this._hitShape); 78 | //this.addChild(this._dotShape); 79 | this.showBg = false; 80 | 81 | this.hitRect.width = 20; 82 | this.hitRect.height = 80; 83 | this.setSize(100, 100); 84 | 85 | } 86 | 87 | public draw():void { 88 | super.draw(); 89 | var regPoint:egret.Point = this.getRegPoint(); 90 | this.hitRect.x = regPoint.x - this.hitRect.width/2; 91 | this.hitRect.y = regPoint.y - this.hitRect.height; 92 | this._hitShape.graphics.clear(); 93 | this._hitShape.graphics.beginFill(0xfff666); 94 | this._hitShape.graphics.drawRect(this.hitRect.x, this.hitRect.y, this.hitRect.width, this.hitRect.height); 95 | this._hitShape.graphics.endFill(); 96 | this._hitShape.graphics.lineStyle(1, 0x444333); 97 | this._hitShape.graphics.drawRect(this.hitRect.x, this.hitRect.y, this.hitRect.width, this.hitRect.height); 98 | 99 | this._dotShape.x = this.globalToLocal(this.getGlobalXY().x, this.getGlobalXY().y).x; 100 | this._dotShape.y = this.globalToLocal(this.getGlobalXY().x, this.getGlobalXY().y).y; 101 | this._dotShape.graphics.clear(); 102 | this._dotShape.graphics.beginFill(0xff0000); 103 | this._dotShape.graphics.drawRect(0, 0, 4, 4); 104 | this._dotShape.graphics.endFill(); 105 | this._dotShape.x = regPoint.x - 2; 106 | this._dotShape.y = regPoint.y - 2; 107 | } 108 | 109 | public getBounds():egret.Rectangle{ 110 | return this.hitRect; 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/display/Npc.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class Npc extends Actor{ 29 | public constructor() { 30 | super(null,null); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/easygame/rpg/display/Player.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy.rpg { 28 | export class Player extends Actor{ 29 | public constructor() { 30 | super(null, null); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/org/easygame/ui/HGroup.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 水平放置的容器 30 | */ 31 | export class HGroup extends Group{ 32 | public _gap:number = 0; 33 | public _hAlign:string = egret.HorizontalAlign.LEFT; 34 | public _vAlign:string = egret.VerticalAlign.MIDDLE; 35 | 36 | public constructor(drawDelay:boolean = false){ 37 | super(drawDelay); 38 | } 39 | 40 | /** 41 | * 初始化主场景的组件 42 | * 这个方法在对象new的时候就调用,因为有些ui必须在加入stage之前就准备好 43 | * 子类覆写该方法,添加UI逻辑 44 | */ 45 | public createChildren():void { 46 | super.createChildren(); 47 | this.invalidate(); 48 | } 49 | 50 | /** 51 | * 设置或获取参与布局元素间水平像素间隔 52 | */ 53 | public get gap():number{ 54 | return this._gap; 55 | } 56 | 57 | public set gap(value:number){ 58 | if(this._gap != value){ 59 | this._gap = value; 60 | this.invalidate(); 61 | } 62 | } 63 | 64 | /** 65 | * 水平方向布局方式 66 | */ 67 | public get hAlign():string{ 68 | return this._hAlign; 69 | } 70 | 71 | public set hAlign(value:string){ 72 | if(this._hAlign != value){ 73 | this._hAlign = value; 74 | this.invalidate(); 75 | } 76 | } 77 | /** 78 | * 垂直方向布局方式 79 | */ 80 | public get vAlign():string{ 81 | return this._vAlign; 82 | } 83 | 84 | public set vAlign(value:string){ 85 | if(this._vAlign != value){ 86 | this._vAlign = value; 87 | this.invalidate(); 88 | } 89 | } 90 | 91 | /** 92 | * 更新显示组件的各项属性,重新绘制显示 93 | */ 94 | public draw():void{ 95 | if (this._bgImage && this._bgImage.parent) { 96 | this._bgImage.parent.removeChild(this._bgImage); 97 | } 98 | super.draw(); 99 | this.updateLayout(); 100 | if (this._showBg){ 101 | this.addChildAt(this._bgImage, 0) 102 | } 103 | } 104 | //public resetPosition():void{ 105 | // super.resetPosition(); 106 | //} 107 | /** 108 | * 更新容器水平布局 109 | */ 110 | public updateLayout():void{ 111 | var i:number = 0; 112 | var child:egret.DisplayObject = null; 113 | var childLast:egret.DisplayObject = null; 114 | var wElements:number = 0; 115 | //console.log("@@@@@HGroup numChildren=" + this.numChildren); 116 | for(i = 0; i < this.numChildren; i++){ 117 | if (this.getChildAt(i) != this._bgImage){ 118 | wElements += this.getChildAt(i).width; 119 | } 120 | } 121 | //console.log("@@@@@HGroup 000 wElements=" + wElements + ", gap=" + this._gap); 122 | wElements += (this.numChildren - 1) * this._gap; 123 | //console.log("@@@@@HGroup 1111 wElements=" + wElements + ", gap=" + this._gap); 124 | var firstChild:boolean = true; 125 | for(i = 0; i < this.numChildren; i++){ 126 | child = this.getChildAt(i); 127 | if (child == this._bgImage) continue; 128 | if(firstChild){ 129 | firstChild = false; 130 | if(this._hAlign == egret.HorizontalAlign.LEFT){ 131 | child.x = 0; 132 | }else if(this._hAlign == egret.HorizontalAlign.CENTER){ 133 | child.x = (this.width - wElements)/2; 134 | }else if(this._hAlign == egret.HorizontalAlign.RIGHT){ 135 | child.x = this.width - wElements; 136 | } 137 | }else { 138 | childLast = this.getChildAt(i - 1); 139 | child.x = childLast.x + childLast.width + this.gap; 140 | } 141 | if(this._vAlign == egret.VerticalAlign.TOP){ 142 | child.y = 0; 143 | }else if(this._vAlign == egret.VerticalAlign.MIDDLE){ 144 | child.y = (this.height - child.height)/2; 145 | }else if(this._vAlign == egret.VerticalAlign.BOTTOM){ 146 | child.y = this.height - child.height; 147 | } 148 | //console.log("@@@@@HGroup x=" + child.x + ", y=" + child.y); 149 | } 150 | } 151 | } 152 | } -------------------------------------------------------------------------------- /src/org/easygame/ui/Style.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class Style{ 29 | public static TEXT_BACKGROUND:number = 0xFFFFFF; 30 | public static BACKGROUND:number = 0xCCCCCC; 31 | public static BUTTON_FACE:number = 0xFFFFFF; 32 | public static BUTTON_DOWN:number = 0xEEEEEE; 33 | public static INPUT_TEXT:number = 0x333333; 34 | public static LABEL_TEXT:number = 0x000000; 35 | public static BUTTON_TEXT:number = 0x666666; 36 | public static DROPSHADOW:number = 0x000000; 37 | public static PANEL:number = 0xF3F3F3; 38 | public static PROGRESS_BAR:number = 0xFFFFFF; 39 | public static LIST_DEFAULT:number = 0xFFFFFF; 40 | public static LIST_ALTERNATE:number = 0xF3F3F3; 41 | public static LIST_SELECTED:number = 0xCCCCCC; 42 | public static LIST_ROLLOVER:number = 0XDDDDDD; 43 | public static BUTTON_DEFAULT_WIDTH:number = 100; 44 | public static BUTTON_DEFAULT_HEIGHT:number = 32; 45 | public static VIDEO_DEFAULT_WIDTH:number = 320; 46 | public static VIDEO_DEFAULT_HEIGHT:number = 250; 47 | 48 | 49 | 50 | public static embedFonts:boolean = false; 51 | public static fontName:string = null; 52 | public static fontSize:number = 16; 53 | /** 54 | * 是否允许文本加载默认滤镜. 55 | */ 56 | public static allowDefaultLabelFilter:boolean = true; 57 | public static DARK:string = "dark"; 58 | public static LIGHT:string = "light"; 59 | /** 60 | * 是否允许按钮禁用态时的颜色矩阵. 61 | */ 62 | public static allowColorFilterButtonEnabled:boolean = false; 63 | /** 64 | * 是否允许默认按钮点击自动冷却.(在按钮本身设置无冷却的情况下生效.) 65 | */ 66 | public static allowButtonDefaultCoolDown:boolean = false; 67 | /** 68 | * allowButtonDefaultCoolDown == true 情况下生效. 69 | */ 70 | public static defaultCoolDownFrames:number = 2; 71 | 72 | public static TEXTINPUT_HEIGHT:number = 25; 73 | public static TEXTINPUT_WIDTH:number = 100; 74 | public static TEXTINPUT_COLOR:number = 0xffffff; 75 | 76 | public static HORIZONTAL:string = "horizontal"; 77 | public static VERTICAL:string = "vertical"; 78 | 79 | public static SLIDER_WIDTH:number = 300; 80 | public static SLIDER_HEIGHT:number = 17; 81 | 82 | public static SCROLLBAR_WIDTH:number = 300; 83 | public static SCROLLBAR_HEIGHT:number = 17; 84 | 85 | 86 | public constructor(){ 87 | 88 | } 89 | /** 90 | * Applies a preset style as a list of color values. Should be called before creating any components. 91 | */ 92 | public static setStyle(style:string):void{ 93 | switch(style){ 94 | case Style.DARK: 95 | Style.BACKGROUND = 0x444444; 96 | Style.BUTTON_FACE = 0x666666; 97 | Style.BUTTON_DOWN = 0x222222; 98 | Style.INPUT_TEXT = 0xBBBBBB; 99 | Style.LABEL_TEXT = 0xCCCCCC; 100 | Style.PANEL = 0x666666; 101 | Style.PROGRESS_BAR = 0x666666; 102 | Style.TEXT_BACKGROUND = 0x555555; 103 | Style.LIST_DEFAULT = 0x444444; 104 | Style.LIST_ALTERNATE = 0x393939; 105 | Style.LIST_SELECTED = 0x666666; 106 | Style.LIST_ROLLOVER = 0x777777; 107 | break; 108 | case Style.LIGHT: 109 | default: 110 | Style.BACKGROUND = 0xCCCCCC; 111 | Style.BUTTON_FACE = 0xFFFFFF; 112 | Style.BUTTON_DOWN = 0xEEEEEE; 113 | Style.INPUT_TEXT = 0x333333; 114 | Style.LABEL_TEXT = 0x666666; 115 | Style.PANEL = 0xF3F3F3; 116 | Style.PROGRESS_BAR = 0xFFFFFF; 117 | Style.TEXT_BACKGROUND = 0xFFFFFF; 118 | Style.LIST_DEFAULT = 0xFFFFFF; 119 | Style.LIST_ALTERNATE = 0xF3F3F3; 120 | Style.LIST_SELECTED = 0xCCCCCC; 121 | Style.LIST_ROLLOVER = 0xDDDDDD; 122 | break; 123 | } 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/DateUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class DateUtil{ 29 | /** 30 | * 两个时间的差值 31 | * @param startTime 毫秒 32 | * @param endTime 毫秒 33 | * return 返回格式化好的差值,格式化到秒 34 | */ 35 | public static getDateDiff(startTime:number, endTime:number):string { 36 | var difArr:Array = DateUtil.getDateDiffArr(startTime, endTime); 37 | var str:string = ""; 38 | if (difArr[0] > 0) str += difArr[0] + "天"; 39 | if (difArr[1] > 0) str += difArr[1] + "小时"; 40 | if (difArr[2] > 0) str += difArr[2] + "分"; 41 | if (difArr[3] > 0) str += difArr[3] + "秒"; 42 | return str; 43 | } 44 | 45 | /** 46 | * 两个时间的差值 47 | * @param startTime 毫秒 48 | * @param endTime 毫秒 49 | * @returns {number[天,小时,分,秒]} 50 | */ 51 | public static getDateDiffArr(startTime:number, endTime:number):Array { 52 | var diffValue:number = Math.abs(endTime - startTime); 53 | //计算出相差天数 54 | var days=Math.floor(diffValue/(24*3600*1000)); 55 | //console.log("datas=" + days); 56 | 57 | //计算出小时数 58 | var leave1=diffValue%(24*3600*1000); //计算天数后剩余的毫秒数 59 | var hours=Math.floor(leave1/(3600*1000)); 60 | //console.log("leave1=" + leave1); 61 | //console.log("hours=" + hours); 62 | 63 | //计算相差分钟数 64 | var leave2=leave1%(3600*1000); //计算小时数后剩余的毫秒数 65 | var minutes=Math.floor(leave2/(60*1000)); 66 | //console.log("leave2=" + leave2); 67 | //console.log("minutes=" + minutes); 68 | 69 | //计算相差秒数 70 | var leave3=leave2%(60*1000); //计算分钟数后剩余的毫秒数 71 | var seconds=Math.round(leave3/1000); 72 | //console.log("leave3=" + leave3); 73 | //console.log("seconds=" + seconds); 74 | return [days, hours, minutes, seconds]; 75 | } 76 | 77 | 78 | /** 79 | * 格式化时间 80 | * @param timer 81 | * @param formate ":" 00:00 "." 00:00 82 | * @returns {string} 83 | */ 84 | public static formatTime(timer:number, formate:string = ":"):string { 85 | var str:string = ""; 86 | var minute:number = Math.floor(timer/60); 87 | if (minute < 10) { 88 | str = "0" + minute; 89 | } else { 90 | str = "" + minute; 91 | } 92 | str += formate; 93 | var second:number = Math.floor(timer%60); 94 | if (second < 10){ 95 | str += "0" + second; 96 | } else { 97 | str += "" + second; 98 | } 99 | return str; 100 | } 101 | 102 | /** 103 | * 将 Date 转化为指定格式的String 104 | * @param date 105 | * @param fmt "yyyy-M-d h:m:s.S" ==> 2006-7-2 8:9:4.18 "yyyy-MM-dd hh:mm:ss.S" ==> 2006-07-02 08:09:04.423 106 | * @returns {string} 107 | */ 108 | public static dateFormat(date:Date, fmt:string):string { 109 | var o = { 110 | "M+": date.getMonth() + 1, //月份 111 | "d+": date.getDate(), //日 112 | "h+": date.getHours(), //小时 113 | "m+": date.getMinutes(), //分 114 | "s+": date.getSeconds(), //秒 115 | "q+": Math.floor((date.getMonth() + 3) / 3), //季度 116 | "S": date.getMilliseconds() //毫秒 117 | }; 118 | if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); 119 | for (var k in o) 120 | if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 121 | return fmt; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/Debug.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * logger日志记录 30 | * 主要是输出到debugwin窗口中,一边debug信息查看 31 | */ 32 | export class Debug { 33 | /** 34 | * log日志记录 35 | */ 36 | private static _log:string = ""; 37 | 38 | public static callbackFunc:Function = null; 39 | 40 | public static set log(str:string) { 41 | if (GlobalSetting.DEV_MODEL) { 42 | console.log(str); 43 | Debug._log += str + "\n"; 44 | if (Debug.callbackFunc) this.callbackFunc.call(null); 45 | } 46 | } 47 | 48 | public static get log():string { 49 | return this._log; 50 | } 51 | 52 | public static refresh():void { 53 | if (Debug.callbackFunc) this.callbackFunc.call(null); 54 | } 55 | 56 | public static clean():void { 57 | if (GlobalSetting.DEV_MODEL) { 58 | this._log = ""; 59 | if (this.callbackFunc) this.callbackFunc.call(null); 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/HitTestUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class HitTestUtil { 29 | //碰撞检测 30 | public static testHitBitmap(b1:egret.Bitmap, b2:egret.Bitmap):boolean { 31 | var b1Rect:egret.Rectangle = b1.getBounds(); 32 | var b2Rect:egret.Rectangle = b2.getBounds(); 33 | return b1Rect.intersects(b2Rect) || b2Rect.intersects(b1Rect); 34 | } 35 | public static testHitRect(b1Rect:egret.Rectangle, b2Rect:egret.Rectangle):boolean { 36 | return b1Rect.intersects(b2Rect); 37 | } 38 | 39 | private static _shape:egret.Shape = null; 40 | 41 | public static testHit(obj1:egret.DisplayObject, obj2:egret.DisplayObject):boolean { 42 | //console.log("p1=" + obj1.parent + ", p2=" + obj2.parent) 43 | if (!obj1.parent || !obj2.parent) { 44 | return false; 45 | } 46 | var x:number = obj1.x; 47 | var y:number = obj1.y ; 48 | var b1Rect:egret.Rectangle = obj1.getBounds(); 49 | //对象1的数据准备 50 | var tempPoint:egret.Point = new egret.Point(); 51 | obj1.parent.localToGlobal(x, y, tempPoint); 52 | b1Rect.x = tempPoint.x; 53 | b1Rect.y = tempPoint.y; 54 | //console.log("x1=" + x + ", x2=" + tempPoint.x + ", y1=" + y + ", y2=" + tempPoint.y + ", w="+ b1Rect.width + ", h=" + b1Rect.height); 55 | //对象2的数据准备 56 | x = obj2.x; 57 | y = obj2.y ; 58 | //对象1的数据准备 59 | var b2Rect:egret.Rectangle = obj2.getBounds(); 60 | obj2.parent.localToGlobal(x, y, tempPoint); 61 | b2Rect.x = tempPoint.x; 62 | b2Rect.y = tempPoint.y; 63 | return b1Rect.intersects(b2Rect); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/HttpUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class HttpUtil{ 29 | public static postData(url:string, data:string, func:any, thisFunc:any):void { 30 | var request:egret.URLRequest = new egret.URLRequest(url); 31 | var loader:egret.URLLoader = new egret.URLLoader(); 32 | request.method = egret.URLRequestMethod.POST; 33 | if (easy.StringUtil.isUsage(data)) request.data = new egret.URLVariables(data); 34 | loader.addEventListener(egret.Event.COMPLETE, function(event:egret.Event){ 35 | var loader:egret.URLLoader = event.target; 36 | func.call(thisFunc, loader.data); 37 | }, HttpUtil); 38 | loader.load(request); 39 | } 40 | public static getData(url:string, data:string, func:any, thisFunc:any):void { 41 | var request:egret.URLRequest = new egret.URLRequest(url); 42 | var loader:egret.URLLoader = new egret.URLLoader(); 43 | request.method = egret.URLRequestMethod.GET; 44 | if (easy.StringUtil.isUsage(data)) request.data = new egret.URLVariables(data); 45 | loader.addEventListener(egret.Event.COMPLETE, function(event:egret.Event){ 46 | var loader:egret.URLLoader = event.target; 47 | func.call(thisFunc, loader.data); 48 | }, HttpUtil); 49 | loader.load(request); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/LocalStorage.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class LocalStorage { 29 | /** 30 | * 保存数据 31 | * @param key 数据的标示 32 | * @param value 要存储的数据 33 | */ 34 | public static set(key:string, value:string):boolean { 35 | return egret.localStorage.setItem(LocalStorage.getStorageName() + key, value); 36 | } 37 | /** 38 | * 保存number数据 39 | * @param key 数据的标示 40 | * @param value 要存储的数据 41 | */ 42 | public static setNumber(key:string, value:number):void { 43 | LocalStorage.set(key, "" + value); 44 | } 45 | /** 46 | * 保存boolean数据 47 | * @param key 数据的标示 48 | * @param value 要存储的数据 49 | */ 50 | public static setBoolean(key:string, value:boolean):void { 51 | LocalStorage.set(key, value?"1":"0"); 52 | } 53 | /** 54 | * 获取条数据 55 | * @param key 数据的标示 56 | */ 57 | public static get(key:string):string { 58 | return egret.localStorage.getItem(LocalStorage.getStorageName() + key); 59 | } 60 | /** 61 | * 获取number数据 62 | * @param key 数据的标示 63 | */ 64 | public static getNumber(key:string):number { 65 | var value:string = egret.localStorage.getItem(LocalStorage.getStorageName() + key); 66 | if (StringUtil.isUsage(value)){ 67 | var num:number = parseFloat(value); 68 | if (!isNaN(num)) { 69 | return num; 70 | } 71 | } 72 | return 0; 73 | } 74 | /** 75 | * 获取int数据 76 | * @param key 数据的标示 77 | */ 78 | public static getInt(key:string):number { 79 | var value:string = egret.localStorage.getItem(LocalStorage.getStorageName() + key); 80 | if (StringUtil.isUsage(value)){ 81 | var num:number = parseInt(value); 82 | if (!isNaN(num)) { 83 | return num; 84 | } 85 | } 86 | return 0; 87 | } 88 | /** 89 | * 获取boolean数据 90 | * @param key 数据的标示 91 | */ 92 | public static getBoolean(key:string):boolean { 93 | var value:string = egret.localStorage.getItem(LocalStorage.getStorageName() + key); 94 | if (StringUtil.isUsage(value) && (value == "1" || value == "true")){ 95 | return true; 96 | } 97 | return false; 98 | } 99 | /** 100 | * 删除一条数据 101 | * @param moduleName 模块的名称 102 | * @param key 数据的标示 103 | */ 104 | public static remvoe(key:string):void { 105 | egret.localStorage.removeItem(LocalStorage.getStorageName() + key); 106 | } 107 | 108 | private static _storageName:string = ""; 109 | 110 | /** 111 | * 获取存储名称 112 | * @returns {string} 113 | */ 114 | private static getStorageName():string { 115 | if (LocalStorage._storageName == ""){ 116 | LocalStorage._storageName = (ResManager._projectName != ""?ResManager._projectName:GlobalSetting.APP_NAME) + "_"; 117 | } 118 | return LocalStorage._storageName; 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/MathUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class MathUtil { 29 | /** 30 | * 取连直线的相交点 31 | * @param targetPoint0 32 | * @param angle0 33 | * @param targetPoint1 34 | * @param angle1 35 | * @returns {*} 36 | */ 37 | public static getCrossPoint(targetPoint0:egret.Point,angle0:number, targetPoint1:egret.Point,angle1:number):egret.Point { 38 | var k0:number = 0; 39 | var k1:number = 0; 40 | var xValue :number = 0; 41 | var yValue :number = 0; 42 | 43 | var isExtra0:number = angle0 % 180 == 0 ? 1 : angle0 % 90 == 0 ? -1 : 0; 44 | var isExtra1:number = angle1 % 180 == 0 ? 1 : angle1 % 90 == 0 ? -1 : 0; 45 | 46 | (isExtra0 == 0) && (k0 = Math.tan(angle0 * Math.PI / 180) ); 47 | (isExtra1 == 0) && (k1 = Math.tan(angle1 * Math.PI / 180) ); 48 | 49 | var tmp_add:number = Math.abs(angle0) + Math.abs(angle1) ; 50 | if ( (tmp_add == 180 && angle0*angle1 < 0) || Math.floor(angle0) == Math.floor(angle1)) { 51 | return null; 52 | } 53 | if ((isExtra0 == 0) && (isExtra1 == 0)) { 54 | xValue = (( k0 * targetPoint0.x - targetPoint0.y ) - ( k1 * targetPoint1.x - targetPoint1.y ) ) / ( k0 - k1 ); 55 | yValue = (( k0 * targetPoint1.y - targetPoint1.x * k0* k1) - ( k1 * targetPoint0.y - targetPoint0.x * k0* k1) ) / (k0 - k1); 56 | } else if ((isExtra0 == 0) && (isExtra1 == 1)) { 57 | yValue = targetPoint1.y; 58 | xValue = ( yValue - targetPoint0.y ) / k0 + targetPoint0.x; 59 | } else if ((isExtra0 == 0) && (isExtra1 == -1)) { 60 | xValue = targetPoint1.x; 61 | yValue = ( xValue - targetPoint0.x ) * k0 + targetPoint0.y; 62 | } else if ((isExtra0 == 1) && (isExtra1 == 0)) { 63 | yValue = targetPoint0.y; 64 | xValue = ( yValue - targetPoint1.y ) / k1 + targetPoint1.x; 65 | } else if ((isExtra0 == 1) && (isExtra1 == -1)) { 66 | yValue = targetPoint0.y; 67 | xValue = targetPoint1.x; 68 | } else if ((isExtra0 == -1) && (isExtra1 == 0)) { 69 | xValue = targetPoint0.x; 70 | yValue = ( xValue - targetPoint1.x ) * k1 + targetPoint1.y; 71 | } else if ((isExtra0 == -1) && (isExtra1 == 1)) { 72 | xValue = targetPoint0.x; 73 | yValue = targetPoint1.y; 74 | } else { 75 | return null; 76 | //trace($_x, $_y); 77 | } 78 | //trace($angle0, $angle1); 79 | return new egret.Point( (xValue*100)/1000, (yValue*1000)/1000); 80 | } 81 | 82 | /** 83 | * 直线的角度 84 | * @param point0 85 | * @param point1 86 | * @returns {number} 87 | */ 88 | public static getAngle(point0:egret.Point, point1:egret.Point):number { 89 | var tmp_x:number = point1.x - point0.x; 90 | var tmp_y:number = point1.y - point0.y; 91 | var tmp_angle:number = Math.atan2( tmp_y, tmp_x ) * 180 / Math.PI; 92 | return tmp_angle; 93 | } 94 | 95 | public static getPos(point0:egret.Point, point1:egret.Point):number { 96 | var tmp_x:number = point0.x - point1.x; 97 | var tmp_y:number = point0.y - point1.y; 98 | var tmp_s:number= Math.sqrt( tmp_x * tmp_x + tmp_y * tmp_y ); 99 | return tmp_s; 100 | } 101 | 102 | /** 103 | * 直线公式,已知指定的两个点,确定一条直线 104 | * y = k * x + b,此函数即返回k = point.x和b = point.y 105 | * @param p1 一个点对象 106 | * @param p2 另外一个点对象 107 | * @return (Point) 返回直线公式的两个参数,组合成一个Point对象存储 108 | * */ 109 | public static lineFunc(p1:egret.Point, p2:egret.Point):egret.Point{ 110 | if(p1.x != p2.x){ 111 | var k:number = (p1.y - p2.y) / (p1.x - p2.x); 112 | var b:number = p1.y - (p1.y - p2.y) / (p1.x - p2.x) * p1.x; 113 | return new egret.Point(k, b); 114 | }else{ 115 | return null; 116 | } 117 | } 118 | 119 | /** 120 | * 产生一个 a 到 b 之间的随机数(默认是 a 不包括 b的整数): 121 | * @param a 122 | * @param b 123 | * @param isInt 是否是整数 124 | */ 125 | public static random(a:number, b:number, isInt:boolean = true):number { 126 | if(isInt){ 127 | return Math.floor(a + (b - a) * Math.random()); 128 | }else{ 129 | return a + (b - a) * Math.random(); 130 | } 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/ObjectUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | 29 | export class ObjectUtil { 30 | /** 31 | * 拷贝src的属性值->target的属性中 32 | * @param src 属性值来源 33 | * @param target 即将被赋值的对象 34 | */ 35 | public static copyValueToTarget(src:any, target:any):void { 36 | console.log("src=" + egret.getQualifiedClassName(src) + ", target=" + egret.getQualifiedClassName(target)); 37 | 38 | if (src && target) { 39 | for (var key in src){ 40 | //console.log("000key=" + key + ", value=" + src[key]); 41 | if (target.hasOwnProperty(key)) { 42 | target[key] = src[key]; 43 | console.log("1111key=" + key + ", value=" + src[key]); 44 | } 45 | } 46 | } 47 | } 48 | 49 | public static functionExist(thisArg:any, functionName:string):boolean{ 50 | if (thisArg && typeof(thisArg[functionName]) == "function"){ 51 | return true; 52 | } 53 | return false; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/ParabolaUtil.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 抛物线计算公式 30 | */ 31 | export class ParabolaUtil { 32 | private static _instance:ParabolaUtil = null; 33 | 34 | private startPt:egret.Point = null; 35 | private endPt:egret.Point = null; 36 | private vertexPt:egret.Point = null; 37 | private a:number = 0 ; 38 | private b:number = 0 ; 39 | private c:number = 0 ; 40 | public getInstance() { 41 | if (ParabolaUtil._instance == null) ParabolaUtil._instance = new easy.ParabolaUtil(); 42 | return ParabolaUtil._instance; 43 | } 44 | 45 | /** 46 | * 给定两个点和定点高 47 | * @param start 开始点 48 | * @param end 结束点 49 | * @param waveHeight 定点高 50 | */ 51 | public init(start:egret.Point, end:egret.Point, waveHeight:number = 240):void { 52 | this.startPt = start; 53 | this.endPt = end; 54 | this.vertexPt = new egret.Point(this.startPt.x + (this.endPt.x - this.startPt.x) / 2, this.endPt.y - waveHeight); 55 | 56 | var x1:number = this.startPt.x; 57 | var x2:number = this.endPt.x; 58 | var x3:number = this.vertexPt.x; 59 | 60 | var y1:number = this.startPt.y; 61 | var y2:number = this.endPt.y; 62 | var y3:number = this.vertexPt.y; 63 | 64 | this.b = ((y1 - y3) * (x1 * x1 - x2 * x2) - (y1 - y2) * (x1 * x1 - x3 * x3)) / ((x1 - x3) * (x1 * x1 - x2 * x2) - (x1 - x2) * (x1 * x1 - x3 * x3)); 65 | this.a = ((y1 - y2) - this.b * (x1 - x2)) / (x1 * x1 - x2 * x2); 66 | this.c = y1 - this.a * x1 * x1 - this.b * x1; 67 | } 68 | /** 69 | * 抛物线运动(必须要先初始化abc参数) 70 | * 给x轴值,得到Y轴值 71 | */ 72 | public getY(posX:number):number { 73 | return this.a * posX * posX + this.b * posX + this.c; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/ProgressCalculate.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class ProgressCalculate{ 29 | public constructor(totalTime:number = 5,heartBeat:number = 2,arrayNode:Array = [45,75,90,95] ){ 30 | this._totalTime = totalTime; 31 | this._heartBeat = heartBeat; 32 | this._arrayLimitNode = arrayNode; 33 | this._phaseCount = arrayNode.length; 34 | this.reset(); 35 | } 36 | private _totalTime:number = 10; 37 | private _heartBeat:number = 1; 38 | private _phaseCount:number = 4; 39 | private _arrayLimitNode:Array = [50,65,80,95];//递减节点 40 | private _arrayLimitTime:Array = []; 41 | private _frameNumber:number = easy.GlobalSetting.FRAME_RATE; 42 | private _increment:number = 0;//每次的增量 43 | private _decreaseFactor:number = 1.5;//递减因子 44 | private _firstRefresh:boolean = false;//第一次刷新数据 45 | private _arrayIndex:number = 0; 46 | private _timeCount:number = 0; 47 | private _totalCurrentLoad:number = 0; 48 | private _currentLoad:number= 0;//当前的load值 49 | private _unitTime:number = 0;//单位时间 50 | public _progressSpeedUp:boolean = false;//开启加速 51 | public progress():number{ 52 | if(this._progressSpeedUp && !this._speedDataRefresh){ 53 | this.speedUp(); 54 | this._speedDataRefresh = true; 55 | } 56 | this._timeCount ++; 57 | if(this._timeCount > this._arrayLimitTime[this._arrayIndex]){ 58 | this._arrayIndex ++; 59 | this._timeCount = 0; 60 | } 61 | if(this._arrayIndex >= this._arrayLimitTime.length){ 62 | if(this._progressSpeedUp){ 63 | return 100; 64 | }else{ 65 | return 99; 66 | } 67 | } 68 | if(this._arrayIndex > 0){ 69 | this._increment = (this._arrayLimitNode[this._arrayIndex] - this._arrayLimitNode[this._arrayIndex - 1]) * (Math.sin(Math.PI / 2 * (this._timeCount / this._arrayLimitTime[this._arrayIndex])) - 70 | Math.sin(Math.PI / 2 * ((this._timeCount - 1) / this._arrayLimitTime[this._arrayIndex]))); 71 | }else{ 72 | this._increment = this._arrayLimitNode[this._arrayIndex] * (Math.sin(Math.PI / 2 * (this._timeCount / this._arrayLimitTime[this._arrayIndex])) - 73 | Math.sin(Math.PI / 2 * ((this._timeCount - 1) / this._arrayLimitTime[this._arrayIndex]))); 74 | } 75 | this._totalCurrentLoad += this._increment; 76 | this._currentLoad = Math.floor(this._totalCurrentLoad); 77 | //console.log("current=" + this._currentLoad); 78 | if(this._currentLoad >= 95 && !this._openSpeedDown && !this._progressSpeedUp){ 79 | this.speedDown(); 80 | this._openSpeedDown = true; 81 | } 82 | if(this._currentLoad >= 100){ 83 | this._currentLoad = 100; 84 | } 85 | return this._currentLoad; 86 | } 87 | private _speedDataRefresh:boolean = false;//已开启加速 88 | private speedUp():void{ 89 | //Debug.log = "progressCaculte.speedUp()"; 90 | this._timeCount = 0; 91 | this._arrayIndex = this._arrayLimitNode.length - 1; 92 | this._arrayLimitNode[this._arrayIndex - 1] = this._currentLoad; 93 | if(!this._openSpeedDown){ 94 | this._arrayLimitTime[this._arrayIndex] = 2;//easy.GlobalSetting.FRAME_RATE / this._heartBeat; 95 | }else{ 96 | this._arrayLimitTime[this._arrayIndex] = 2;//this._heartBeat; 97 | } 98 | } 99 | private _openSpeedDown:boolean = false;//开启第二阶段减速 100 | private speedDown():void{ 101 | //Debug.log = "progressCaculte.speedDown()"; 102 | this._timeCount = 0; 103 | this._arrayIndex = this._arrayLimitNode.length - 1; 104 | this._arrayLimitNode[this._arrayIndex - 1] = this._currentLoad; 105 | this._arrayLimitNode[this._arrayIndex] = 99; 106 | this._arrayLimitTime[this._arrayIndex] = 8 * easy.GlobalSetting.FRAME_RATE / this._heartBeat; 107 | } 108 | public reset():void{ 109 | //Debug.log = "progressCaculte.reset"; 110 | this._progressSpeedUp = false; 111 | this._openSpeedDown = false; 112 | this._speedDataRefresh = false; 113 | this._firstRefresh = true; 114 | this._timeCount = 0; 115 | this._totalCurrentLoad = 0; 116 | this._currentLoad = 0; 117 | this._increment = 0; 118 | this._unitTime = 0; 119 | this._arrayIndex = 0; 120 | var decrease:number = 0; 121 | var totalTime:number = 0; 122 | this._arrayLimitTime = []; 123 | for(var i:number = 0;i < this._phaseCount;i ++){ 124 | decrease += Math.pow(this._decreaseFactor,i); 125 | } 126 | this._unitTime = Math.floor(this._totalTime * this._frameNumber / decrease / this._heartBeat) ; 127 | for(var j:number = 1;j < this._phaseCount;j ++){ 128 | var stageTime:number = this._unitTime * j ; 129 | totalTime += stageTime; 130 | this._arrayLimitTime.push(stageTime); 131 | } 132 | var remainingTime:number = (this._totalTime * this._frameNumber - totalTime) / this._heartBeat; 133 | this._arrayLimitTime.push(remainingTime); 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/Sound.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class Sound { 29 | private static _soundDict:any = {};//循环播放的文件 30 | /** 31 | * 播放声音 32 | * @param loops 0次循环,表示无限循环,同一个无限循环播放的声音不允许多次播放 33 | * @returns {string} 34 | */ 35 | public static play(name:string, startTime:number = 0, loops:number = 1, completeFunc:any = null, thisObj:any = null):egret.SoundChannel { 36 | //console.log("sound.play=" + name + ", valume.open=" + GlobalSetting.VOLUME_OPEN) 37 | if(GlobalSetting.VOLUME_OPEN && StringUtil.isUsage(name)) { 38 | if (loops == 0 && Sound._soundDict[name]) return Sound._soundDict[name]; 39 | var sound:egret.Sound = RES.getRes(name);//RES.getRes目前egret的声音是单例 40 | if (sound){ 41 | var channel:egret.SoundChannel = sound.play(startTime, loops); 42 | Sound._soundDict[name] = {channel:channel, loops:loops <= 0, num:loops, func:completeFunc, thisObj:thisObj}; 43 | channel.addEventListener(egret.Event.SOUND_COMPLETE, Sound.onSoundComplete, Sound); 44 | if (completeFunc && thisObj) { 45 | channel.addEventListener(egret.Event.SOUND_COMPLETE, completeFunc, thisObj); 46 | } 47 | return channel; 48 | } 49 | } 50 | return null; 51 | } 52 | 53 | /** 54 | * 设置声音 55 | * @param name 56 | * @param value 57 | */ 58 | public static volume(name:string, value:number):void { 59 | if (StringUtil.isUsage(name) && Sound._soundDict[name]) { 60 | var channelConfig:any = Sound._soundDict[name]; 61 | if (channelConfig.channel){ 62 | channelConfig.channel.volume = value; 63 | } 64 | } 65 | } 66 | 67 | /** 68 | * 播放完毕 69 | * @param event 70 | */ 71 | private static onSoundComplete(event:egret.Event):void { 72 | //console.log("Sound onSoundComplete"); 73 | var channel:egret.SoundChannel = event.currentTarget; 74 | var channelConfig:any = null; 75 | for(var key in Sound._soundDict){ 76 | channelConfig = Sound._soundDict[key]; 77 | var myEvent:easy.MyEvent = easy.MyEvent.getEvent(easy.EventType.SOUND_COMPLETE); 78 | myEvent.addItem("name", key); 79 | myEvent.send(); 80 | if (channelConfig.channel == channel) { 81 | if (!channelConfig.loops) { 82 | channelConfig.num --; 83 | if (channelConfig.num == 0 && channel.hasEventListener(egret.Event.SOUND_COMPLETE)){ 84 | channel.removeEventListener(egret.Event.SOUND_COMPLETE, Sound.onSoundComplete, Sound); 85 | delete Sound._soundDict[key]; 86 | if (channelConfig.func && channelConfig.thisObj) { 87 | channel.removeEventListener(egret.Event.SOUND_COMPLETE, channelConfig.func, channelConfig.thisObj); 88 | } 89 | channelConfig.func = null; 90 | channelConfig.thisObj = null; 91 | channelConfig.channel = null; 92 | delete Sound._soundDict[key]; 93 | } 94 | } 95 | break; 96 | } 97 | } 98 | } 99 | 100 | /** 101 | * 停止声音,对循环播放的声音有效 102 | * @param name 103 | */ 104 | public static stop(name:string):void { 105 | if (StringUtil.isUsage(name) && Sound._soundDict[name]) { 106 | var channelConfig:any = Sound._soundDict[name]; 107 | if (channelConfig.channel){ 108 | if (channelConfig.channel.hasEventListener(egret.Event.SOUND_COMPLETE)){ 109 | channelConfig.channel.removeEventListener(egret.Event.SOUND_COMPLETE, Sound.onSoundComplete, Sound); 110 | if (channelConfig.func && channelConfig.thisObj) { 111 | channelConfig.channel.removeEventListener(egret.Event.SOUND_COMPLETE, channelConfig.func, channelConfig.thisObj); 112 | } 113 | } 114 | channelConfig.channel.stop(); 115 | channelConfig.func = null; 116 | channelConfig.thisObj = null; 117 | channelConfig.channel = null; 118 | 119 | var myEvent:easy.MyEvent = easy.MyEvent.getEvent(easy.EventType.SOUND_STOP); 120 | myEvent.addItem("name", name); 121 | myEvent.send(); 122 | delete Sound._soundDict[name]; 123 | } 124 | } 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/SpriteUtils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | /** 29 | * 集中ui操作的一些常用方法 30 | */ 31 | export class SpriteUtils { 32 | 33 | /** 34 | * 用target的图形,在src的图形上镂空/擦除,返回擦除后的材质 35 | * @param src 36 | * @param target 37 | */ 38 | public static earse(src:egret.DisplayObject, target:egret.DisplayObject):egret.Texture{ 39 | var container:egret.DisplayObjectContainer = easy.ObjectPool.getByClass(egret.DisplayObjectContainer); 40 | var targetImg:egret.Bitmap = easy.ObjectPool.getByClass(egret.Bitmap, "earse"); 41 | targetImg.blendMode = egret.BlendMode.ERASE; 42 | var texture1:egret.RenderTexture = easy.ObjectPool.getByClass(egret.RenderTexture); 43 | texture1.drawToTexture(target); 44 | targetImg.texture = texture1; 45 | 46 | container.addChild(src); 47 | container.addChild(targetImg); 48 | 49 | //绘制成材质 50 | var texture2:egret.RenderTexture = new egret.RenderTexture(); 51 | texture2.drawToTexture(container); 52 | 53 | //回收对象 54 | container.removeChildren(); 55 | easy.ObjectPool.recycleClass(container); 56 | 57 | targetImg.blendMode = egret.BlendMode.NORMAL; 58 | targetImg.texture = null; 59 | easy.ObjectPool.recycleClass(targetImg, "earse"); 60 | 61 | return texture2; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/org/easygame/utils/UUID.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014,www.easygame.org 3 | * All rights reserved. 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of the easygame.org nor the 13 | * names of its contributors may be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY EASYEGRET.COM AND CONTRIBUTORS "AS IS" AND ANY 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | * DISCLAIMED. IN NO EVENT SHALL EGRET-LABS.ORG AND CONTRIBUTORS BE LIABLE FOR ANY 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | module easy { 28 | export class UUID { 29 | /** 30 | * 生成一个36位长度的uuid标识 31 | * @returns {string} 32 | */ 33 | public static newUUID():string { 34 | var new4Data = () => { 35 | var max:number = Math.pow(16, 4) - 1; 36 | var newNum:number = Math.floor(Math.random() * max); 37 | var newNumToStr:string = newNum.toString(16); 38 | while (newNumToStr.length < 4) { 39 | newNumToStr = "0" + newNumToStr; 40 | } 41 | return newNumToStr; 42 | }; 43 | 44 | var data1:string = new4Data() + new4Data(); 45 | var data2:string = new4Data(); 46 | var data3:string = new4Data(); 47 | var data4:string = new4Data(); 48 | var data5:string = new4Data() + new4Data() + new4Data(); 49 | 50 | return data1 + "-" + data2 + "-" + data3 + "-" + data4 + "-" + data5; 51 | } 52 | 53 | /** 54 | * 获取url中的参数值 55 | * @param name 56 | * @returns {*} 57 | */ 58 | public static getUrlByName(name:string):string { 59 | var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 60 | if (location) { 61 | var r = location.search.substr(1).match(reg); 62 | if (r != null) { 63 | return decodeURI(decodeURIComponent(decodeURI(r[2]))); 64 | } 65 | } 66 | return ""; 67 | } 68 | } 69 | } --------------------------------------------------------------------------------