您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d-x 捕鱼达人游戏学习教程(6)--添加Weapon类

2013-07-08 10:48 405 查看
Hi,推荐文件给你 "捕鱼达人练习例子(5).zip" http://vdisk.weibo.com/s/J1Xg8
Weapon.h

#include "Cannon.h"
#include "Bullet.h"
#include "FishingNet.h"
USING_NS_CC;
enum
{
    k_Weapon_Status_None = 0,
    k_Weapon_Status_Bullet,
    k_Weapon_Status_FishingNet
};
class Weapon:public CCNode
{
    
public:
    static Weapon* create(CannonType type = k_Cannon_Type_1);
    bool init(CannonType type = k_Cannon_Type_1);
    
    //声明三个对象
    CC_SYNTHESIZE_READONLY(Cannon*, _cannon, Cannon);
    CC_SYNTHESIZE_READONLY(Bullet*, _bullet, Bullet);
    CC_SYNTHESIZE_READONLY(FishingNet*, _fishingNet, FishingNet);
    //获取炮塔的类型留着以后实现
    int getCannonType();
    
};


Weapon.cpp代码如下:

#include "StaticData.h"
USING_NS_CC;

Weapon* Weapon::create(CannonType type)
{
    Weapon* weapon =  new Weapon();
    weapon->init(type);
    weapon->autorelease();
    return weapon;
}

bool Weapon::init(CannonType type)
{
    bool pRet = false;
    do {
        _cannon = Cannon::create();
        this->addChild(_cannon);
        
        _bullet = Bullet::create();
        _bullet->setVisible(false);
        this->addChild(_bullet);
        
        _fishingNet = FishingNet::create();
        _fishingNet->setVisible(false);
        this->addChild(_fishingNet);
        
        pRet = true;
    } while (0);
    return pRet;
    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐