写一下我对植物大战僵尸设计模式的理解

今晚,弄到现在,几番想砸键盘以后,却让我做出来了;是什么呢?我看看能不能解释清楚吧;

我们不是建立了一个主游戏层吗?它有多个子层这些之层分散在主游戏层得周围;可以看作周围多个点 围绕着中间一个点;

现在的问题是怎么在这些子层之间建立联系,比如我接下来要讲的 每个葵花植物成熟后金币要加上相应的值,对吧,但是葵花精灵和金币不在同一个层 ,你在葵花所在那个层里面怎么实现金币的运算;

浪费了很长时间,老是错,错的让人心烦;不过在22:30我找到了解决方案:

给大家看下部分代码:完整的代码我明天会写;今晚恐怕写不了了。。好困!

void SunCellLayer::initSunCell(float dt)
{
       this->_sunCellSprite = SunCellSprite::create();
	   this->_sunBatchNode->addChild(this->_sunCellSprite);
	   CCSize winsize = CCDirector::sharedDirector()->getWinSize();
	   this->_sunCellSprite->setPosition(ccp(3*winsize.width/4 * rand()/RAND_MAX + 1*winsize.width/5,winsize.height+this->_sunCellSprite->getContentSize().height));
	   this->SunCellMoveWay();

}

void SunCellLayer::SunCellMoveWay()
{
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	CCFiniteTimeAction* sunCellMove1 = CCMoveTo::create(4.0f,ccp(this->_sunCellSprite->getPosition().x,1* winSize.height/4 *rand()/RAND_MAX + 2*winSize.height/5));
	CCFiniteTimeAction* sunCellMove2 = CCMoveTo::create(0.5f,ccp(2*winSize.width/7, 8*winSize.height/9));
	this->_sunCellSprite->runAction(CCSequence::create(sunCellMove1,sunCellMove2,CCCallFuncN::create(this,callfuncN_selector(SunCellLayer::removeSunCell)),NULL));
}

void SunCellLayer::removeSunCell(CCNode* pSend)
{
	CCSprite* sprite = (CCSprite*) pSend;
	this->_sunBatchNode->removeChild(sprite,true);
	((GameLayer*)this->getParent())->_dollarDisplayLayer->_dollar = ((GameLayer*)this->getParent())->_dollarDisplayLayer->_dollar +25;//就是这里
	
}
先这样吧明天在解释

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值