关于Cocos2d-x中根据分数增加游戏难度的方法
2023-09-11 14:21:21 时间
1.GameScene.h中声明一些分数边界值
1 //level提升所需的分数 2 enum LevelUp_Score 3 { 4 Level1Up_Score = 5, 5 Level2Up_Score = 10, 6 Level3Up_Score = 15, 7 Level4Up_Score = 20 8 };
2.在移动的Baby对象类的.cpp文件的update方法中写,每一帧都会执行update方法
1 //让生成的Baby实例对象不断地往左边移动,超出屏幕就消失,好像有了这个就不用再在Block和Star的定义下面写一个用来消失的update函数了 2 void Baby::update(float dt){ 3 //log("wo zai baby update limian1"); 4 m_score=GameScene::sharedGameLayer()->getScore(); 5 //log("wo zai baby update limian2"); 6 //m_score=GameScene::getScore(); 7 //根据到达的分数,设置LEVEL 8 if (m_score > GameScene::LevelUp_Score::Level1Up_Score && m_score < GameScene::LevelUp_Score::Level2Up_Score) 9 { 10 //m_level = LEVEL2; 11 setPositionX(getPositionX() - 6); 12 } 13 else if (m_score > GameScene::LevelUp_Score::Level2Up_Score && m_score < GameScene::LevelUp_Score::Level3Up_Score) 14 { 15 //m_level = LEVEL3; 16 setPositionX(getPositionX() - 8); 17 } 18 else if (m_score > GameScene::LevelUp_Score::Level3Up_Score && m_score < GameScene::LevelUp_Score::Level4Up_Score) 19 { 20 //m_level = LEVEL4; 21 setPositionX(getPositionX() - 10); 22 } 23 else if (m_score > GameScene::LevelUp_Score::Level4Up_Score) 24 { 25 //m_level = LEVEL5; 26 setPositionX(getPositionX() - 12); 27 } 28 else 29 { 30 setPositionX(getPositionX() - 6); 31 //setPositionX(getPositionX() - 6); 32 } 33 34 if (getPositionX()<-this->getContentSize().width) { 35 unscheduleUpdate(); 36 removeFromParent(); 37 } 38 }
相关文章
- 【华为联机对战服务】客户端退出重连或中途进入游戏,新玩家如何补帧?
- 手把手教你Egret引擎一键发布华为快游戏
- BZOJ 1444 [Jsoi2009]有趣的游戏 (AC自动机 + 概率DP + Gauss)
- 《Cocos2d 跨平台游戏开发指南(第2版)》一1.5 添加精灵到场景
- 《Cocos2d 跨平台游戏开发指南(第2版)》一1.9 添加动作到精灵
- 《HTML5游戏编程核心技术与实战》——2.6 其他全局属性
- 再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(7) —— Python版本实现的《2048》游戏的TDL算法
- 再探 游戏 《 2048 》 —— AI方法—— 缘起、缘灭(6) —— Python版本实现的《2048》游戏环境运行性能对比
- 各种素材网站大全【全部倾倒,福利倒计时-JS,HTML,游戏素材,UI,图片素材等
- Linux 上的游戏 Supertuxkart
- 小学生python游戏编程arcade----游戏界面按钮实现事件实现的三种方法
- 《C#零基础入门之百识百例》(六十五)类和结构体的对比 -- 文字对战游戏
- U3D游戏研发-广州深圳(40-60W)
- 关于Cocos2d-x中掉帧导致游戏一卡一卡的网上一些的解决方法