文章目录

  • 游戏二维码
    • 微信平台
    • 4399平台

1.List工具篇
2.工具篇 Dictionary
3.工具篇 读取Json文件保存数据
4.资源管理ResourceManager
5.界面层级管理 LayerManager
6.界面管理 UIManager
7.事件监听篇 EventBus
8.枚举篇 枚举管理
9.游戏总管 Mir
10游戏入口 Main
11.声音管理器
12首页界面
13.游戏界面
14.01 背景
15.02主角(与游戏界面交互)
16.03添加怪物来袭
17.04添加障碍物
18.05 添加障碍物排列
19.06添加奖励物品
20.07奖励物质排列数据
21.从零开始-Cocos跑酷游戏——游戏结束界面
22.最后的补充

游戏中少不了障碍物添加
操作流程与怪物添加没有差别
只是多了一个障碍物排列的配置
在下一个章节可以看到

配置表

[{"ID": 5001,"name":"DZ","path": "DZ","attck": 4001},{"ID": 5002,"name":"barrier1","path": "barrier1","attck": 4002}]

障碍物配置信息数据转换成对象数据

function BarrierCfgVo()
{this.id;this.name;this.path;this.attck;
}
BarrierCfgVo.prototype.SetValue=function(mData)
{this.id=mData.ID;this.name=mData.Name;this.path=mData.path;this.attck=mData.attck;
}
module.exports=BarrierCfgVo;

障碍物配置数据保存

var BarrierCfgData=
{dataList:null,filePath:null,init:function(){this.dataList=new window.dictionary();this.filePath=window.Constant.RootPath.CONFIG_ROOT_PATH+"Barrier";this.dataDic=window.data.ButtleData.dataDiction;window.cc.loader.loadRes(this.filePath,(function(err,array){if(err){console.log("错误信息:"+err);return;}var arrs=array.json;for(var i=0;i<arrs.length;i++){var mData=arrs[i];var mVoData=new window.BarrierCfgVo();mVoData.SetValue(mData);this.dataList.add(mVoData.id,mVoData);}}).bind(this));},GetBarrierCfgData:function(){return this.dataList;}
}
module.exports=BarrierCfgData;

游戏中需要用到的数据对象处理

这里需要提到的一个点是,配置数据跟游戏数据是不一样的

配置数据通过配置读取之后,是一个定值,只能通过配置表来进行修改。

而游戏数据是会在游戏运行中会动态变化的。

function BarrierVoData()
{this.id;this.name;this.BarrierID;this.posArray;
}
BarrierVoData.prototype.SetValue=function(mData)
{this.id=mData.id;this.BarrierID=mData.BarrierID;this.name=mData.name;this.posArray=mData.posArray;
}
module.exports=BarrierVoData;

障碍物数据处理与管理

var BarrierData=
{dataList:null, //dataAndPefabDic:null,  // key 对应的预制体dataDictiony:null,     //数据 对应的对象池prefab:cc.Prefab,loadPath:null,initCount:30,// 初始化个数count:0,BarrierCfgData:null,manager:null,init:function(){this.dataList=new window.List();this.dataDictiony=new window.dictionary();this.dataAndPefabDic=new window.dictionary();this.loadPath=window.Constant.RootPath.Barrier;this.BarrierCfgData=window.cfg.BarrierCfgData.GetBarrierCfgData();var len=this.BarrierCfgData.count;for(var i=0;i<len;i++){var data=this.BarrierCfgData.values[i];if(data==null){console.log("未取得配置文件索引:"+i);return;}       this.LoadPrefab(data);     }},//加载预制体LoadPrefab:function(data){console.log("开始加载预制体");var path=this.loadPath+data.path;window.ResourceManager.LoadPrefab(path,function(err, prefab){if(err!=null){console.log("错误信息:"+err);return;}this.dataAndPefabDic.add(data.id,prefab);}.bind(this)); },initStarPool:function(){  var len=this.dataAndPefabDic.count;for(var k=0;k<len;k++){var pool=new cc.NodePool();var key=this.dataAndPefabDic.keys[k];for(var i=0;i<this.initCount;i++){              var prefab=this.dataAndPefabDic.get(key);         var objNode=cc.instantiate(prefab);//添加脚本可以根据key值进行改变,也可以在RewardHandler中判断Key编写不一样的逻辑objNode.addComponent("BarrierHandler");     pool.put(objNode);}this.dataDictiony.add(key,pool);}           },GetRewardItemFromPool:function(parent,id,pos,manager){    this.manager=manager;   var nodeObj;var pool=this.dataDictiony.get(id);if(pool==null){console.log("id:"+id+"对象池为空");return;}if(pool.size()>0){nodeObj=pool.get(); }     else{var prefab=this.dataAndPefabDic.get(id);          nodeObj=cc.instantiate(prefab);nodeObj.addComponent("BarrierHandler");}nodeObj.getComponent("BarrierHandler").SetData(id,manager);nodeObj.setParent(parent);nodeObj.setPosition(pos);return nodeObj;},RemoveItem:function(objNode){var id=objNode.getComponent("BarrierHandler").id;this.PutItemToPool(objNode,id);},   PutItemToPool:function(objNode,id){    var pool=this.dataDictiony.get(id);pool.put(objNode);},  RemoveAllItem(){if(!this.manager){return;}var barrierPos1=cc.find("barrierPos",this.manager.ground1);var barrierPos2=cc.find("barrierPos",this.manager.ground2);var barrierPos3=cc.find("barrierPos",this.manager.ground3);this.RemoveChild(barrierPos1);this.RemoveChild(barrierPos2);this.RemoveChild(barrierPos3);},RemoveChild(parent){var childs=parent.children;var len=childs.length;for(var i=len-1;i>=0;i--){this.RemoveItem(childs[i]);}}
}
module.exports=BarrierData;

挂载在障碍物上的脚本

cc.Class({extends: cc.Component,Data:null,gameManager:null,barrierPos:null,id:0,onLoad () {this.initComponent();},onDisable(){var sprite=this.node.getComponent(cc.Sprite);var name=sprite.spriteFrame.nameif(name=="DZ2"){this.ChangeUIData();}},initComponent(){},  SetData(id,gameManager){this.gameManager=gameManager;var dataList=window.cfg.BarrierCfgData.GetBarrierCfgData();this.id=id;var data=dataList.get(id);this.Data=data;},onCollisionEnter:function(other,self){if(other.tag==50){window.data.BarrierData.RemoveItem(this.node);      }if(this.id==window.Constant.BarrierType.WoodBarrier){return;}if(other.tag==1){var playerControll=other.node.getComponent("PlayerControll"); if(playerControll.invincible){console.log("无敌状态");return;}           if(playerControll.prePlayerType==window.Constant.PlayerType.SteelBall){console.log("免疫伤害");this.node.getComponent(cc.Animation).play();return;}    window.data.BarrierData.RemoveItem(this.node);   this.gameManager.player.getComponent("PlayerControll").PlayerDie("撞到地上野怪");}},ChangeUIData:function(){var path="barrier/DZ1";var spriteObj=this.node.getComponent(cc.Sprite);window.ResourceManager.LoadSpriteFrameByName(spriteObj,path);},});

游戏二维码

微信平台

4399平台

4399游戏链接:http://www.4399.com/flash/203652.htm

17.Cocos跑酷游戏——04添加障碍物相关推荐

  1. 2.Cocos跑酷游戏——工具篇 Dictionary

    1.List工具篇 2.工具篇 Dictionary 3.工具篇 读取Json文件保存数据 4.资源管理ResourceManager 5.界面层级管理 LayerManager 6.界面管理 UIM ...

  2. 1.Cocos跑酷游戏——List工具篇

    1.List工具篇 2.工具篇 Dictionary 3.工具篇 读取Json文件保存数据 4.资源管理ResourceManager 5.界面层级管理 LayerManager 6.界面管理 UIM ...

  3. Unity3d 跑酷游戏(急速变色龙)

    U3D跑酷游戏 赛道(障碍物)生成 主角奔跑逻辑 赛道(障碍物)生成 我们在做跑酷游戏的时候要明白这几点: 赛道的生成以及消失 障碍物的生成以及消失 我们先来讲赛道的生成,什么时候生成?又什么时候消失 ...

  4. Cocos Creator游戏开发教程 学习笔记

    学完提问几个问题吧: position的锚点位置数值原点在哪里? 因为position是相对坐标,所以原点是父节点的锚点 .所以Canvas下面的直属节点原点就是世界坐标系的原点Canvas的锚点. ...

  5. Unity入门——实现一个简单的跑酷游戏(资源预制)

    Unity入门--实现一个简单的跑酷游戏 资源预制 一款跑酷游戏,需要大量重复的场景资源,比如道路.障碍物等,无论是从游戏体验的角度还是运行效率的角度考虑,都不应该全部事先摆好,而是应该由代码随机生成 ...

  6. 纯HTML+JS实现跑酷游戏

    今天翻了翻以前的项目文件夹,发现了当初刚学前端的时候写的一个"小游戏",遂决定整理到博客. 0.前言 写这个"游戏"是在三年前刚接触HTML+JS还不到三天的时 ...

  7. [教程] 使用3D Infinite Runner Toolkit打造僵尸跑酷游戏

    使用3D Infinite Runner Toolkit打造僵尸跑酷游戏 3D Infinite Runner Toolkit是一款风格特异的3D版跑酷游戏开发包,其优点是容易使用与修改场景内的所有组 ...

  8. Unity跑酷游戏中的路点生成算法

    最近做了一个小的跑酷游戏,今天就我前几天写的 游戏玩家跟随在跑道上的路点行走的简单逻辑进行一下梳理,希望大家和我自己都能够有一定的进步. 下面我先说一下该款游戏的一些有必要知道的前提.跑道是动态生成的 ...

  9. oracle 883355,unity3d跑酷游戏DEMO源码

    [实例简介] unity3d跑酷游戏DEMO源码,可以用来入门学习. 有障碍物,可以跳跃. [实例截图] [核心代码] RunningDemo └── RunningDemo ├── Assets │ ...

最新文章

  1. 第十一周总结CoreIDRAW
  2. 【Linux系统编程】进程概述和进程号
  3. 负载均衡算法 — 轮询
  4. Spark MLlib学习笔记之二——Spark Mllib矩阵向量
  5. 深度学习(18)神经网络与全连接层一: 数据加载
  6. 咱也开始玩z-blog了
  7. 软件开发管理(产品经理客户和程序员互撕解决方案)
  8. 关于javaScript注册事件传递参数的浅析
  9. 动网论坛新手详尽教程
  10. 数学分析笔记—python基础语法
  11. Linux内核源码总体介绍—1
  12. 直播背后的视频云大战
  13. IMDB电影评论文本的神经网络分类
  14. App自动化测试之企微打卡、快手刷金币
  15. Electron环境搭建-Mac以及URL Schemes启动
  16. GET和POST两种基本请求方法的区别 1
  17. attempt_load() got an unexpected keyword argument ‘map_location‘
  18. UNITY物体上下漂浮工具
  19. [JVM]了断局: Class文件结构梳理
  20. ffmpeg切割音频文件

热门文章

  1. 《贫穷不是正义,懦弱亦非善良-雾满拦江》
  2. Java 涂鸦跳跃,涂鸦跳跃java版
  3. 通达信股票接口的开源性及兼容性好吗?
  4. javplayer 使用教程_药物设计软件Sybyl教程(五):绘制分子对接后对接表面
  5. Epic、Feature、Story和Task的关系
  6. unity入门——实现一个简单的跑酷游戏(人物控制)
  7. office移动端_微软office三合一与wps office对比测评:谁才是移动办公王者?
  8. 【究极详细版】Ubuntu安装配置MySQL
  9. 史上最细,Charles抓包工具的基本配置、查找接口的方法、爬取中国大学Mooc整门课程
  10. Vue项目打包部署后首页空白的问题