cocos2d-x游戏开发系列教程-超级玛丽09-怪物激活与移动
在游戏中,很多怪物本身是会移动的,这里主要有蘑菇怪,乌龟等。
说起怪物的移动,首先在游戏里先要考虑怪物的抽象和设计。
在CMMonster.h中,有个类CMMonsterBasic,这个类抽象了所有的怪物,具体的怪物都是它的派生类,比如CMMonsterMushrooms蘑菇怪。
CMMonsterBasic继承自CCNode和CMSender,所以怪物都是渲染对象,并且有消息发送功能。
怪物基本类的接口:
virtual bool init(CCPoint ptMonsterPos,CMMario *pMario,CMGameMap *pGameMap,CMReceiver *pReceiver); 初始化
virtual bool OnCollisionMario() = 0; 与马里奥相撞处理
virtual void Dead(enMonsterDeadType DeadType); 怪物死亡
virtual bool OnCallPerFrame(float fT); 帧刷新定时调用
void MonsterTurn(); 怪物转向,比如蘑菇怪遇到阻挡它的墙时,它会转向
怪物类的基本数据
CMMario *m_pMario; 马里奥对象
CMGameMap *m_pGameMap; 地图对象
enMoveDirection m_MoveDirection; 移动方向
bool m_bIsActivation; 是否激活
float m_fDropSpeedPlus; 掉落加速度
bool m_bIsTouched; 是否相撞
怪物的创建:
当游戏开始时,根据tmx地图中的标记,创建怪物对象并放置到响应位置,具体代码在CMGameMap的init函数中
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3UAAAGfCAIAAAB3LGy6AAAgAElEQVR4nO3d3ZHzuLKlYTlRVoyT24WxoeNcj4mci9rNg0JmLiR++Kv3iY4vJAgEQJASV5Ml6rNd5H/+53+u6vpkn/98xqpFC+7lomX3JV2YHGdzeGPVAADAa1x27H9NvswkubE68/ny85+P/c/WybQW/TdQDQAAvFvHgf///N//9/tfszDjHfmyeUawyljNtKdbrsoz5y+bXUSjbXZEagQAAK5sRCgT5P7YLUz6hnzpFroPbAyNWoteqpotA6JtU/frjmHmrCRJFACAr0K+HDcQLjcvX27yJGKVFJNNNa99u+lT5MvmmoqL41wiBwDgq/RdH9/iHEm+jAqjqNdMim4LUZQUhfaMph7GkvOXBEoAAL7W7N9f7i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P5UtRvIl8+HRETAAC4OH+JQeRLAADgIl9iEPkSAAC41P2JbMRMFmaQL5+OfAkAAFz8fg8G8fs9AADARb4EAADASuRLAAAArES+BAAAwErkSwAAAKxEvgQAAMBK5Et8qfLL7//8/Oz/Yp6dT241AABfJXt/9S2+1eXYLTDJlyh9ClGhrTDT3f44GS7/+fn5/a96/Aju4JuF7uJu4/aprUzEBIDvoe6vXpXox+RLDKsyZbJwVY/5k5dVGlsykmTXS3rZO7IPokL7avMl8iUAYNnvQ/YiX+KXGzuiLLL85GUX8mXUcnIMREwA+BIL8iW/D4kZS/Kle+ncveYuGtlFV4qjfFnVFDFUX5V2a4reu650l6cVb5UvCZ0A8D6z+ZLr45g0ny/1lXS7SCbQiOCVjGjJk4Wbl89EzeGTnbfNlwCA91l2fZx8iTFvzZdRUzpNltXcU5jNkUfIlwCA05AvcbGD8uX27/XxfOOlg/KlW5JJnNGCvdfHt78Zl3wJADgC+RLXG/v++Mw3zTN/gmkfT+bLJdfH9bCFsXyZTMwZhEsA+B7q/kQ2YiYLM8iXKOkv6FRPxZ0ybcnYKUz3/F+VL6uX9FO3zao7dwBiSHnRuUwx+Mw5UduacOg9AQAAt8Lv9+CdoovmunA3c6YQlpht8iUAvA/5Eq8lzl9qw6cJAQDARr4EAADAWuRLAAAArES+BAAAwErkSwAAAKxEvkSfsW/MAACA75G9v/rm3epyLxm4BSb58rnIlwAAQFD3V69K7GP3h3ySyJfPRb4EAADC1O9DipIm8uVzkS8BAIBAvkQ38iUAABAW5MuBcLmRLx+OiAkAACLkS3QjXAIAAIF8iW7kSwAAIJAv0Y18CQAABHV/Ipsj3ftcki+/DfkSAAAI/H4P+vD7PQAAQCNfAgAAYCXyJQAAAFYiXwIAAGCl/w+JtiD/8GnsMgAAAABJRU5ErkJggg==" alt="" />
创建完怪物之后,将其加入到数组中,这些怪物刚刚创建时候,都是不激活的,也就是不会动的
怪物的激活和移动:
触发怪物的激活的原理在于判断怪物是不是已经进入视图,如果没有进入视图,那么怪物不需要动。但是判断是否进入视图还是很麻烦的,所以在马里奥程序里,是用马里奥和怪物的距离,来触发怪物的激活的。
怪物的激活和移动都是在virtual bool OnCallPerFrame(float fT); 函数中,这个函数是CMGameMap的帧更新函数调用过来的,也就是说每次帧更新,每个怪物都会响应这个函数。在这个函数里,负责激活和移动,以及判断怪物和马里奥的碰撞。
下面我们以蘑菇怪的帧更新函数来学习怪物帧更新处理。
bool CMMonsterMushrooms::OnCallPerFrame( float fT )
{
do
{
//是否激活
if (m_bIsActivation==true)
{
//移动与碰撞
if (m_MoveDirection == enMoveLeft)
{
//用怪物左方的2个瓦片来判断移动碰撞
CCSprite* pTileSpriteLeftTop = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX(),getPositionY()+getContentSize().height));
CCSprite* pTileSpriteLeftMid = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX(),getPositionY()+getContentSize().height/2));
if (pTileSpriteLeftTop!=NULL || pTileSpriteLeftMid!=NULL)
{
m_MoveDirection = enMoveRight;
}
else
{
setPositionX(getPositionX()-1);
}
}
else if(m_MoveDirection == enMoveRight)
{
//用怪物右方的2个瓦片来判断移动碰撞
CCSprite* pTileSpriteRightTop = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX()+getContentSize().width,getPositionY()+getContentSize().height));
CCSprite* pTileSpriteRightMid = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX()+getContentSize().width,getPositionY()+getContentSize().height/2));
if (pTileSpriteRightTop!=NULL || pTileSpriteRightMid!=NULL)
{
m_MoveDirection = enMoveLeft;
}
else
{
setPositionX(getPositionX()+1);
}
} //用怪物下方的三个瓦片来判断掉落碰撞
CCSprite* pTileSpriteBottomMid = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX()+boundingBox().size.width/2,getPositionY()));
CCSprite* pTileSpriteBottomLeft = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX()+COLLISION_POS_ADJUSTMENT,getPositionY()));
CCSprite* pTileSpriteBottomRight = m_pGameMap->TileMapLayerPosToTileSprite(ccp(getPositionX()+boundingBox().size.width-COLLISION_POS_ADJUSTMENT,getPositionY()));
if (pTileSpriteBottomLeft!=NULL || pTileSpriteBottomMid!=NULL || pTileSpriteBottomRight!=NULL)
{
//掉落速度归零
m_fDropSpeedPlus = 0;
}
else
{
setPositionY(getPositionY()-m_fDropSpeedPlus);
//掉落加速度
m_fDropSpeedPlus += DROP_SPEED_PLUS;
}
} return (CMMonsterBasic::OnCallPerFrame(fT)||OnCollisionMario());
} while (false); CCLog("fun CMMonsterMushrooms::OnCallPerFrame Error!"); return false;
}
首先判断是否激活了,如果激活了那么则判断它的移动,它不需要按键驱动,按照时间移动它即可,遇到障碍物则返回。如果蘑菇怪在天上,则自然降落。
最后调用基类的定时刷新函数和马里奥的冲突函数。基类的定时刷新函数做什么呢
bool CMMonsterBasic::OnCallPerFrame(float fT)
{
do
{
//判断当怪物离开地图则发消息删除自己
if (getPositionX()<0 || getPositionY()<0)
{
TCmd_Remove_Monster* pData = new TCmd_Remove_Monster;
pData->pMonster = this;
SendMsg(enMsgMonsterDisappear,pData,sizeof(pData));
return true;//需要删除自己
} CC_BREAK_IF(m_pMario==NULL); //判断马里奥与当前怪物的距离,用以激活。
if (abs(m_pMario->getPositionX() - getPositionX())<MONSTER_ACTIVE_DISTANCE)
{
m_bIsActivation = true;
} return false;//不需要删除自己
} while (false);
CCLog("fun CMMonsterBasic::OnCallPerFrame Error!");
return false;
}
基类的函数主要要做的事情是:
1)如果怪物离开地图,则自杀。自杀是通过发送消息给地图类,让地图类杀掉本对象
2)如果怪物与马里奥的距离小于某个值,则激活,激活的意思就是这个怪物开始运动了
cocos2d-x游戏开发系列教程-超级玛丽09-怪物激活与移动的更多相关文章
- cocos2d-x游戏开发系列教程-超级玛丽10-怪物与马里奥冲突检测
在超级玛丽游戏中,马里奥在移动,怪物也在移动,当他们遇见时,需要判断是马里奥身亡还是怪物身亡. 这个判断的代码在怪物类的检测函数实现中. 比如蘑菇怪的冲突检测函数: bool CMMonsterMus ...
- cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap
背景 在上一篇博客中,我们提到CMGameScene,但是CMGameScene只是个框架,实际担任游戏逻辑的是CMGameMap类,这个博文就来了解下CMGameMap 头文件 class CMGa ...
- cocos2d-x游戏开发系列教程-超级玛丽06-CMGameScene
背景 在CMMenuScene中,当用户点击开始游戏时,导演让场景进入到CMGameScene 头文件 class CMGameScene : public cocos2d::CCLayer,publ ...
- cocos2d-x游戏开发系列教程-超级玛丽08-消息机制
在超级玛丽游戏里,地图类CMGameMap负责所有的程序逻辑,它包含了背景地图,包含了游戏元素精灵,当游戏中的精灵之间发生碰撞时,比如马里奥撞上砖头这种事情发生时,马里奥对象本身不知道怎么处理这个逻辑 ...
- cocos2d-x游戏开发系列教程-超级玛丽05-CMMenuScene
代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn 背景 上一篇博文提到appDelegate,在该类 ...
- cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(五)-地图卷动
马里奥在平移的过程中,涉及到地图的卷动问题. 在这个游戏里,地图比窗口大,窗口只是显示了地图的一部分,因此马里奥在移动的时候,移动到一定位置之后要卷动地图,否则马里奥移动到窗口右边之后......那结 ...
- cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(三)-按键处理
在地图初始化好了之后,就开始移动马里奥吧,我在windows下,是使用键盘来移动马里奥的 w是跳,d是前进,a是后退,那么在程序里是怎么来获取这个按键的呢? 普通的windows程序,在按键之后,会有 ...
- cocos2d-x游戏开发系列教程-超级玛丽04-AppDelegate
代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn 背景 上一篇博文提到在CCApplication: ...
- cocos2d-x游戏开发系列教程-超级玛丽02-代码结构
代码下载链接 http://download.csdn.net/detail/yincheng01/6864893 解压密码:c.itcast.cn 前景回顾 上一篇博文提到超级马里奥的游戏效果,大家 ...
随机推荐
- java之Set源代码浅析
Set的接口和实现类是最简单的,说它简单原因是由于它的实现都是基于实际的map实现的. 如 hashSet 基于hashMap,TreeSet 基于TreeMap,CopyOnWriteArraySe ...
- [Codecademy] HTML&CSS 第三课:HTML Basic II
本文出自 http://blog.csdn.net/shuangde800 [Codecademy] HTML && CSS课程学习目录 --------------------- ...
- Unity cg vertex and fragment shaders(二)
着色器的一般结构: Shader "MyShader/MyShaderName" { Properties { // ... properties here ... } SubSh ...
- 小猪猪C++笔记基础篇(五)表达式、语句
小猪猪C++笔记基础篇(五) 关键词:表达式.语句 本章的内容比较简单,基本上没有什么理解上的困难,都是知识上的问题.先开始想要不要写呢,本来是不准备写的,但是既然读了书就要做笔记,还是写一写,毕竟还 ...
- 浅谈Servlet读取Html参数
1首先:webApp名称为cookieAndsession.html文件一般放在WebRoot文件夹下:/cookieAndsession/WebRoot/OrderForm.html,那么外界要访问 ...
- beanUtils操作bean的属性
beanUtils操纵bean属性: 需要jar包commons-beanutils-x.x.x.jar 同时commons-beanutils-x.x.x.jar需要commons-loggi ...
- 10247 - Complete Tree Labeling(递推高精度)
Problem B Complete Tree Labeling! Input: standard input Output: standard output Time Limit: 45 secon ...
- Latex调整行距
修改行间距的方法: \usepackage{setspace}%使用间距宏包 \begin{document} \begin{spacing}{2.0}%%行间距变为double-space 双倍行距 ...
- phome_ecms_news 数据表字段解释(新闻系统模型-主表)
http://www.phome.net/doc/manual/extend/html/dbdoc/index.html 字段名 类型 解释 附加说明 id int(11) 信息ID classi ...
- [C++ Basic]C++与Java的主要区别
1.编译运行 java是解释性语言,java程序在运行时类加载器从类路经中加载相关的类,然后java虚拟机读取该类文件的字节,执行相应操作.而C++编译的 时候将程序编译成本地机器码.一般来说java ...