西游黄金矿工

西游黄金矿工是一款以黄金矿工玩法为基础,西游题材为背景的HTML5游戏,玩家需要在规定的时间内抓取宝物,同时需要达到过关分值方可过关。

页面效果

游戏起始页面

游戏场景选择页面

游戏页面

赢了后展示的页面

输了后展示的页面

2、游戏ui代码

/***存放设置游戏Ui的代码*///添加地图
var addMap = function(self, fileName)
{map = new cc.TMXTiledMap("res/tmx/" + fileName + indexLevel + ".tmx");self.addChild(map);var group = map.getObjectGroup("logic");var arrayObjects = group.getObjects();var dict;for (var i = 0, len = arrayObjects.length; i < len; i++){dict = arrayObjects[i];var x = dict["x"]var y = dict["y"];var width = dict["width"];var height = dict["height"];var type = dict["type"];var mineral = new cc.Sprite("res/tmx/goods_" + type + ".png");mineral.anchorX = 0;mineral.anchorY = 0;mineral.x = x;mineral.y = y;mineral.type = type;map.addChild(mineral);vecMineral.push(mineral);}
}//添加暂停按钮
var addButton = function(self)
{var buttonPause = new ccui.Button();buttonPause.setTouchEnabled(true);buttonPause.loadTextures(res.zanting1_png, res.zanting2_png, "");buttonPause.x = width - 100;buttonPause.y = height - 100;moveNode(buttonPause, cc.p(50, 50));buttonPause.addTouchEventListener(openPauseDialog);self.addChild(buttonPause);
}//加载使用CocosStudio搭建好的Ui
var loadCocosStudio = function(self)
{timeDialog = ccs.load(res.progressTime_json);timeDialog.node.anchorX = 0.5;timeDialog.node.anchorY = 0.5;timeDialog.node.x = 70;timeDialog.node.y = height - 60;moveNode(timeDialog.node, cc.p(-30, 18));self.addChild(timeDialog.node);layerColor = new cc.LayerColor(cc.color(0, 0, 0, 200), width, height);layerColor.visible = false;layerColor.setLocalZOrder(10);self.addChild(layerColor);pauseDialog = ccs.load(res.pauseDialog_json);pauseDialog.node.anchorX = 0.5;pauseDialog.node.anchorY = 0.5;pauseDialog.node.x = width / 2;pauseDialog.node.y = height / 2;pauseDialog.node.setLocalZOrder(10);pauseDialog.node.visible = false;self.addChild(pauseDialog.node);helpDialog = ccs.load(res.HelpDialog_json);helpDialog.node.anchorX = 0.5;helpDialog.node.anchorY = 0.5;helpDialog.node.x = 60;helpDialog.node.y = 450;helpDialog.node.setLocalZOrder(10);helpDialog.node.visible = false;self.addChild(helpDialog.node);failGameDialog = ccs.load(res.failGameDialog_json);failGameDialog.node.anchorX = 0.5;failGameDialog.node.anchorY = 0.5;failGameDialog.node.x = width / 2;failGameDialog.node.y = height / 2 + 20;failGameDialog.node.setLocalZOrder(10);failGameDialog.node.scale = 0;failGameDialog.node.opacity = 0;self.addChild(failGameDialog.node);successGameDialog = ccs.load(res.successGameDialog_json);successGameDialog.node.anchorX = 0.5;successGameDialog.node.anchorY = 0.5;successGameDialog.node.x = width / 2;successGameDialog.node.y = height / 2 + 20;successGameDialog.node.setLocalZOrder(10);successGameDialog.node.scale = 0;successGameDialog.node.opacity = 0;self.addChild(successGameDialog.node);
}//获得节点的信息
var getNodeInfo = function(self)
{labelTime = timeDialog.node.getChildByName("labelTime");progressScore = timeDialog.node.getChildByName("progressScore");labelLevel = timeDialog.node.getChildByName("labelLevel");labelScore = timeDialog.node.getChildByName("labelScore");var buttonContinue = pauseDialog.node.getChildByName("buttonContinue");buttonContinue.addTouchEventListener(continueGame);var buttonReplay = pauseDialog.node.getChildByName("buttonReplay");buttonReplay.addTouchEventListener(self.replayGame);var buttonMenu = pauseDialog.node.getChildByName("buttonMenu");buttonMenu.addTouchEventListener(intoSceneMenu);var buttonHelp = pauseDialog.node.getChildByName("buttonHelp");buttonHelp.addTouchEventListener(openHelpDialog);var buttonCloseHelpDialog = helpDialog.node.getChildByName("closeHelpDialog");buttonCloseHelpDialog.addTouchEventListener(closeHelpDialog);buttonPageLeft = helpDialog.node.getChildByName("pageLeft");buttonPageLeft.addTouchEventListener(pageLeft);buttonPageRight = helpDialog.node.getChildByName("pageRight");buttonPageRight.addTouchEventListener(pageRight);spriteInfo = helpDialog.node.getChildByName("spriteInfo");var buttonReplay1 = failGameDialog.node.getChildByName("buttonReplay");buttonReplay1.addTouchEventListener(self.replayGame);var buttonMenu1 = failGameDialog.node.getChildByName("buttonMenu");buttonMenu1.addTouchEventListener(intoSceneMenu);var buttonMenu2 = successGameDialog.node.getChildByName("buttonMenu");buttonMenu2.addTouchEventListener(intoSceneMenu);var buttonStart = successGameDialog.node.getChildByName("buttonStart");buttonStart.addTouchEventListener(self.replayGame);var buttonLevel = successGameDialog.node.getChildByName("buttonLevel");buttonLevel.addTouchEventListener(intoNextLevel);
}//设置游戏中用到的一些数据
var setData = function()
{labelTime.setString(numTime);progressScore.setPercent(0);labelLevel.setString(indexSceneGame + " - " + indexLevel);labelScore.setString(numScore + " / " + airmScore);
}//添加游戏角色
var addPlayer = function(self, fileName, pt)
{player = new cc.Sprite(spriteFrameCache.getSpriteFrame(fileName));player.x = pt.x;player.y = pt.y;self.addChild(player);
}//添加栅栏
var addGunLun = function(self, pt)
{var gunlun = new cc.Sprite(res.gunlun_png);gunlun.x = pt.x;gunlun.y = pt.y;self.addChild(gunlun);
}//场景裁剪节点
var createClipNode = function(self)
{var masking = new cc.Sprite(res.masking_png);masking.anchorX = 0.5;masking.anchorY = 0;masking.x = width / 2;masking.y = height - 100;moveNode(masking, cc.p(0, -18));clipNode = new cc.ClippingNode();clipNode.setStencil(masking);clipNode.setInverted(true);clipNode.setAlphaThreshold(0.5);clipNode.anchorX = 0;clipNode.anchorY =0;clipNode.x = 0;clipNode.y = 0;self.addChild(clipNode);
}//添加绳子
var addShengZi = function(pt)
{//创建绳子shengzi = new cc.Sprite(res.shengzi_png);shengzi.anchorX = anchorX;shengzi.anchorY = anchorY;shengzi.x = pt.x;shengzi.y = pt.y;shengzi.rotation = shengziAngle;clipNode.addChild(shengzi);//创建钩子gouzi = new cc.Sprite(res.gouzi_png);gouzi.anchorX = 0.5;gouzi.anchorY = 1;moveNode(gouzi, cc.p(3, 0));shengzi.addChild(gouzi);//获得绳子的长度shengziLength = shengzi.getContentSize().height;
}//继续游戏
continueGame = function(sender, type)
{switch (type){case  ccui.Widget.TOUCH_BEGAN:{if (effVolume){cc.audioEngine.playEffect(res.sound010_mp3);}isClick = true;isTouch = true;layerColor.visible = false;pauseDialog.node.visible = false;cc.director.resume();}break;default:break;}
}//打开帮助对话框
openHelpDialog = function(sender, type)
{switch (type){case  ccui.Widget.TOUCH_BEGAN:{if (effVolume){cc.audioEngine.playEffect(res.sound010_mp3);}pauseDialog.node.visible = false;helpDialog.node.visible = true;indexPage = 0;updatePageData();}break;default:break;}
}//关闭帮助对话框
var closeHelpDialog = function(sender, type)
{switch (type){case ccui.Widget.TOUCH_ENDED:{if (effVolume){//播放按钮音效cc.audioEngine.playEffect(res.sound010_mp3);}pauseDialog.node.visible = true;helpDialog.node.visible = false;}break;default:break;}
}//向左翻页
var pageLeft = function(sender, type)
{switch (type){case ccui.Widget.TOUCH_ENDED:{if (effVolume){cc.audioEngine.playEffect(res.sound010_mp3);}indexPage--;updatePageData();}break;default:break;}
}//向右翻页
var pageRight = function(sender, type)
{switch (type){case ccui.Widget.TOUCH_ENDED:{if (effVolume){cc.audioEngine.playEffect(res.sound010_mp3);}indexPage++;updatePageData();}break;default:break;}
}//进入菜单场景
intoSceneMenu = function(sender, type)
{switch (type){case  ccui.Widget.TOUCH_BEGAN:{if (effVolume){//播放按钮音效cc.audioEngine.playEffect(res.sound010_mp3);}indexLevel = 1;cc.audioEngine.stopMusic(res.sound002_mp3);cc.director.resume();cc.director.runScene(new SceneMenu());}break;default:break;}
}//进入下一关
intoNextLevel = function(sender, type)
{switch (type){case ccui.Widget.TOUCH_ENDED:{if (effVolume){//播放按钮音效cc.audioEngine.playEffect(res.sound010_mp3);}indexLevel += 1;//进入宝象国if (indexSceneGame == 1){if (indexLevel > 12){indexLevel = 1;}cc.audioEngine.stopMusic(res.sound002_mp3);cc.director.runScene(new SceneBaoXiangGuo());}//进入通天河else if (indexSceneGame == 2){if (indexLevel > 11){indexLevel = 1;}cc.audioEngine.stopMusic(res.sound003_mp3);cc.director.runScene(new SceneTongTianHe());}//进入女儿国else if (indexSceneGame == 3){if (indexLevel > 11){indexLevel = 1;}cc.audioEngine.stopMusic(res.sound004_mp3);cc.director.runScene(new SceneNvErGuo());}//进入火焰山else if (indexSceneGame == 4){if (indexLevel > 11){indexLevel = 1;}cc.audioEngine.stopMusic(res.sound005_mp3);cc.director.runScene(new SceneHuoYanShan());}//进入灵山else if (indexSceneGame == 5){if (indexLevel > 10){indexLevel = 1;}cc.audioEngine.stopMusic(res.sound006_mp3);cc.director.runScene(new SceneLingShan());}}break;default:break;}
}//打开暂停对话框
openPauseDialog = function (sender, type)
{switch (type){case ccui.Widget.TOUCH_BEGAN:{//如果不能点击返回按钮if (!isClick){return;}if (effVolume){//播放按钮音效cc.audioEngine.playEffect(res.sound010_mp3);}//标记不能再点击暂停按钮isClick = false;//标记不能触摸屏幕isTouch = false;layerColor.visible = true;pauseDialog.node.visible = true;cc.director.pause();}break;default :break;}
}var addBackground = function(self, fileImage)
{var bg = new cc.Sprite(fileImage);bg.anchorX = 0;bg.anchorY = 0;bg.x = 0;bg.y = 0;self.addChild(bg);
}

《黄金矿工》挖矿游戏 前端高阶版本,Cocos2d-js,附项目源码相关推荐

  1. JavaScript实现跳跃游戏的贪婪方法的算法(附完整源码)

    JavaScript实现跳跃游戏的贪婪方法的算法(附完整源码) greedyJumpGame.js完整源代码 greedyJumpGame.test.js完整源代码 greedyJumpGame.js ...

  2. 微信小程序开发【前端+后端(Java)】附完整源码,拿来接私活简直不要太香

    一.前言 现在微信小程序越来越火了,相信不少人都通过各种途径学习过微信小程序或者尝试开发,作者就是曾经由于兴趣了解开发过微信小程序,所以现在用这篇博客记录我之前开发的一些经验和一些心得吧. 二.主要内 ...

  3. 基于springboot和vue的MOBA类游戏攻略分享平台【附项目源码】

    基于springboot和vue的MOBA类游戏攻略分享平台 开发语言:Java 框架:springboot JDK版本:JDK1.8 服务器:tomcat7 数据库:mysql 5.7 数据库工具: ...

  4. 基于springboot和vue的MOBA类游戏攻略分享平台【附项目源码】分享

    基于springboot和vue的MOBA类游戏攻略分享平台 开发语言:Java 框架:springboot JDK版本:JDK1.8 服务器:tomcat7 数据库:mysql 5.7 数据库工具: ...

  5. 高仿人人网客户端Android版项目源码

    高仿人人网客户端,有兴趣的盆友可以研究下,里面主要包含的一些UI设计与交互.(注:项目中有少许问题,apk能运行,希望开发者可以参考代码研究一下.) 源码下载:http://code.662p.com ...

  6. Redis高阶使用之Redisson分布式锁源码解析

    一.何为分布式锁 1.锁synchronized lock 单机锁 2.我们的一些互斥资源 不能并行执行 需要一个东西来保证是串行执行的 锁synchronized 3.分布式锁:这个锁存储一定是独立 ...

  7. 基于Python的数独游戏设计与实现 课程文档+任务书+项目源码

    目录 数独游戏 1 需求分析 1 解题思路 2 生成数独 2 每行单元格包含整数1到9,且每个数恰好出现一次. 2 每列单元格包含整数1到9,且每个数恰好出现一次. 2 每个3×3的宫包含整数1到9, ...

  8. HTML小游戏8 —— 小霸王游戏机网页版(附完整源码)

  9. 基于SSM的旅游景点门票管理系统,高质量毕业论文范例(可直接使用),附送源码和数据库脚本,项目导入运行视频教程,论文撰写教程

    目录 1.项目技术栈 2.适合对象 3.适合课题 4.项目功能概述 4.1 功能汇总 4.2 功能介绍 5.高质量论文范例 6.毕业设计撰写视频教程 7.部分运行截图 1.项目技术栈 前端必学三个基础 ...

最新文章

  1. 用模板实现单例模式(线程安全)、模板方式实现动态创建对象
  2. 微信10个实用技巧,值得收藏!
  3. Windows端口被占用处理方法
  4. Oracle/mysql查询语句的执行过程
  5. 10年 | 写了10年的代码,我最怕写Mybatis这些配置,现在有详解了
  6. 【Flink】Flink CDH6.3.2 下的yarn per job模式 savepoint和checkpoint,卡住,没有保存成功文件
  7. oracle 中update select 和连接字符串配合使用
  8. 还在家隔离呢?没事写写这些程序吧!
  9. libiconv字符集转换库在C#中的使用
  10. AbiWord 中Piece Table 数据结构的实现----AbiWord Documentation
  11. python判断线程结束_判断Threading.start新线程是否执行完毕的实例
  12. Chrome扩展开发指南(
  13. c语言有趣代码,实用有趣的C语言程序
  14. android模拟鼠标键盘,有关通过Happy Android模拟器的鼠标和键盘操作进行手机游戏的详细设置的图形教程...
  15. c语言控制单片机38译码器,单片机+38译码器控制的数码管怎么点亮?
  16. ad采样做按键开关_基于ad采样电路的多路开关量采集装置及其采集方法
  17. 联想交换机服务器型号,ThinkSystem DB610s光纤交换机
  18. threejs炫酷金属样式龙卷风js特效
  19. 云计算和云服务区别是什么
  20. jcp jsr_Oracle提交了第三次JCP改革JSR,以提高透明度

热门文章

  1. 文末赠书 | 计算机AI视觉第一人?何恺明的学术成就够得上了吗?
  2. 一寸照片变换背景色操控变形
  3. 【更新中】苹果自家的as汇编器的特色风格(与微软masm汇编器语言风格的不同)
  4. Kali Linux侦听蓝牙设备
  5. 推荐几个好用的API测试工具?我保证你一定会喜欢的
  6. iOS开发 转屏控制 (shouldAutorotate/supportedInterfaceOrientations)不起作用
  7. Python数据分析入门书籍推荐
  8. 数据中心linux运维学习_云计算时代数据中心运维三大要点
  9. 为什么夜晚拍照时照片里有不规则光晕?(转载)
  10. 基坑计算理论m法弹性支点法_基坑支护结构弹塑性计算方法与m法的对比分析