Popstar小游戏1(Popstar的POP精灵的创建)

.h文件,声明函数

#include "cocos2d.h"
USING_NS_CC;
class PopSprite : public Sprite{
public:
    //初始化游戏的数值,宽度,高度,X轴,Y轴
    static PopSprite* createPopSprite(int numbers,int width,int height,float popSpriteX,float popSpriteY);
    virtual bool init();
    CREATE_FUNC(PopSprite);
    //获取数字
    int getNumber();
    //设置数字
    void setNumber(int num);
    //获取色块的坐标
    Point getColorBGPoint();
    //获取PopSprite的位置
    int popX,popY;
    //获取X Y;
    int getPOPX();
    int getPOPY();
    //设置X Y;
    void setPOPX(int x);
    void setPOPY(int y);
private:
    //显示的颜色
    int number;
    void enemyInit(int numbers,int width,int height,float popSpriteX,float popSpriteY);
    //显示的背景
    LayerColor* layerColorBG;
};

.cpp文件,实现各函数

#include "PopSprite.h"
PopSprite*  PopSprite::createPopSprite(int numbers,int width,int height,float popSpriteX,float popSpriteY){
    PopSprite* enemy = new PopSprite();
    if(enemy && enemy->init()){
        enemy->autorelease();
        enemy->enemyInit(numbers,width,height,popSpriteX,popSpriteY);
        return enemy;
    }
    CC_SAFE_DELETE(enemy);
    return NULL;
}
bool PopSprite::init(){
    if(!Sprite::init()){
        return false;
    }
    return true;
}
void PopSprite::enemyInit(int numbers,int width,int height,float popSpriteX,float popSpriteY){
    //设置初始化的值
    number = numbers;
    popX = 0;
    popY = 0;
    //设置游戏每个PopSprite的背景颜色
    layerColorBG = LayerColor::create(Color4B(200,190,180,255),width - 5,height - 5);
    layerColorBG->setPosition(Vec2(popSpriteX, popSpriteY));
    this->addChild(layerColorBG);
}
Point PopSprite::getColorBGPoint(){
    return layerColorBG->getPosition();
}
int PopSprite::getNumber(){
    return number;
}
void PopSprite::setNumber(int num){
    number = num;
    //判断数字来调整颜色
    if(number == -1){
        layerColorBG->setColor(Color3B(200,190,180));
    }
    if(number == 0){
        layerColorBG->setColor(Color3B(250,230,40));
    }
    if(number == 1){
        layerColorBG->setColor(Color3B(40,180,250));
    }
    if(number == 2){
        layerColorBG->setColor(Color3B(130,220,110));
    }
    if(number == 3){
        layerColorBG->setColor(Color3B(250,80,130));
    }
    if(number == 4){
        layerColorBG->setColor(Color3B(180,50,250));
    }
}
int PopSprite::getPOPX(){
    return popX;
}
int PopSprite::getPOPY(){
    return popY;
}
void PopSprite::setPOPX(int x){
    popX = x;
}
void PopSprite::setPOPY(int y){
    popY = y;
}


你可能感兴趣的:(Popstar小游戏1(Popstar的POP精灵的创建))