基于cocos2dx 3.0的卡牌游戏战斗环节探究二
2014-11-07 14:16
316 查看
好了,让我们继续;
在上一篇的onAttack方法内,我们看到了这两个定时操作:
if(_relation==good){
this->schedule(schedule_selector(Role::attackFromPlayer),2);
}
else{
this->schedule(schedule_selector(Role::attackFromMonster),3);}
没错,这就是角色的攻击动作,这里写的动作非常简单,可以分解为:
auto rotateLeft=RotateTo::create(0.1, -30);
auto rotateRight=RotateTo::create(0.1,30);
auto rotateBack=RotateTo::create(0.1,0);
auto attackCall=CallFunc::create([&](){
if(_relation==good){
CCNotificationCenter::sharedNotificationCenter()->postNotification("player give a hit",NULL);
}
});
auto seq=Sequence::create(rotateLeft,rotateRight,rotateBack,attackCall,NULL);
this->runAction(seq);
每次攻击出去的动作做出来后,使用回调发出一个指令给到GameLayer,由GameLayer通知对手类,更改对方的状态:
_monster->_fsm->doEvent("doBeHit");
GameLayer就担任调度中心的任务。
下面是补充一些细节:
(1)血量条的扣减:
onBeHit内,刷新血量:
_health=_health-400;
_blood->setPercentage((_health/1000)*100);
如果血量为0,判定角色死亡,否则自动攻击:
if(_health>0){
this->_fsm->doEvent("doAttack");
}else{
log("signa, h1");
_fsm->doEvent("doDead");
}
(2)死亡的消息(汗!)
onDead方法内,角色通知调度层GameLayer,由GameLayer停止这个场景(这里做了简单处理,将另一方也置为dead状态,停止动作,汗)
auto onDead=[&](){
this->unscheduleAllSelectors();
this->stopAllActions();
log("i am dead");
CCNotificationCenter::sharedNotificationCenter()->postNotification("someone is killed",NULL);
};
void GameLayer::func3(CCObject* pSender){
if(_player->_fsm->getStatus()!="dead"){
_player->_fsm->doEvent("doDead");
}
}
好的,更多细节就请看代码吧
https://github.com/frank1982/rpg-combat-scene-demo-of-cocos2dx
在上一篇的onAttack方法内,我们看到了这两个定时操作:
if(_relation==good){
this->schedule(schedule_selector(Role::attackFromPlayer),2);
}
else{
this->schedule(schedule_selector(Role::attackFromMonster),3);}
没错,这就是角色的攻击动作,这里写的动作非常简单,可以分解为:
auto rotateLeft=RotateTo::create(0.1, -30);
auto rotateRight=RotateTo::create(0.1,30);
auto rotateBack=RotateTo::create(0.1,0);
auto attackCall=CallFunc::create([&](){
if(_relation==good){
CCNotificationCenter::sharedNotificationCenter()->postNotification("player give a hit",NULL);
}
});
auto seq=Sequence::create(rotateLeft,rotateRight,rotateBack,attackCall,NULL);
this->runAction(seq);
每次攻击出去的动作做出来后,使用回调发出一个指令给到GameLayer,由GameLayer通知对手类,更改对方的状态:
_monster->_fsm->doEvent("doBeHit");
GameLayer就担任调度中心的任务。
下面是补充一些细节:
(1)血量条的扣减:
onBeHit内,刷新血量:
_health=_health-400;
_blood->setPercentage((_health/1000)*100);
如果血量为0,判定角色死亡,否则自动攻击:
if(_health>0){
this->_fsm->doEvent("doAttack");
}else{
log("signa, h1");
_fsm->doEvent("doDead");
}
(2)死亡的消息(汗!)
onDead方法内,角色通知调度层GameLayer,由GameLayer停止这个场景(这里做了简单处理,将另一方也置为dead状态,停止动作,汗)
auto onDead=[&](){
this->unscheduleAllSelectors();
this->stopAllActions();
log("i am dead");
CCNotificationCenter::sharedNotificationCenter()->postNotification("someone is killed",NULL);
};
void GameLayer::func3(CCObject* pSender){
if(_player->_fsm->getStatus()!="dead"){
_player->_fsm->doEvent("doDead");
}
}
好的,更多细节就请看代码吧
https://github.com/frank1982/rpg-combat-scene-demo-of-cocos2dx
相关文章推荐
- 基于cocos2dx 3.0的卡牌游戏战斗环节探究一
- cocos2dx 3D战斗类游戏制作:【三】——基于数据库的3D精灵动画1
- 基于Cocos2dx开发卡牌游戏Demo_放开那三国 2.0
- cocos2dx shader实现的简单滤镜 基于3.0版本
- Blue Path(基于cocos2dx 3.0)
- 基于Cocos2dx开发卡牌游戏_松开,这三个国家
- Blue Path(基于cocos2dx 3.0)
- 基于Cocos2dx开发卡牌游戏_松开,这三个国家
- 基于Cocos2dx 3.0beta2小游戏《砸鸡蛋》,仿韩国综艺
- 基于Cocos2dx开发卡牌游戏Demo_放开那三国 2.0
- 如何使用cocos2dx3.0制作基于tilemap的游戏:第一部分
- 如何使用cocos2dx3.0制作基于tilemap的游戏:第二部分
- 如何使用cocos2dx3.0制作基于tilemap的游戏:第三部分·完
- 基于Cocos2dx开发卡牌游戏_放开那三国
- cocos2dx 3D战斗类游戏制作:【三】——基于数据库的3D精灵动画2
- 缓存初解(三)---Spring3.0基于注解的缓存配置+Ehcache和OScache
- cocos2dx 3D战斗类游戏制作:【二】——3D运动模式小准备之二
- 基于spring3.0的cxf发布webservice+client的源码
- 【opencv学习】lucas金字塔光流算法的实现——基于opencv3.0+vs2013+windows10
- 基于Mono跨平台移动应用开发框架发布Xamarin 3.0