zoukankan      html  css  js  c++  java
  • [置顶] 写一下我对植物大战僵尸设计模式的理解

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

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

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

    浪费了很长时间,老是错,错的让人心烦;不过在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;//就是这里
    	
    }
    

    先这样吧明天在解释

  • 相关阅读:
    C# 杨辉三角 下
    C# 自动走迷宫 下
    算法练习之1数字填充 下
    动态添加控件并获取其值
    两个ListBox的互动
    VS2005常用快捷键
    GridView内嵌DropDownList操作
    GridView格式化短日期
    获得客户端ID
    Access数据库 Update 语句的怪现象
  • 原文地址:https://www.cnblogs.com/riasky/p/3455475.html
Copyright © 2011-2022 走看看