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

时间:2023-02-08 10:50:31


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;

}