Пример #1
0
void UILayer::addTouchableTower(TowerTypes towerType, cocos2d::CCPoint position){
	if (towers->Buy(towerType)){
		Tower *newTower = towers->createTower(towerType, position);
		this->addChild(newTower->getSprite(), 100);

		TouchableSprite *tSprite = new TouchableSprite();
		tSprite->towerType = towerType;
		tSprite->tower = newTower;
		tSprite->spriteType = TOWER_ON_SCENE;
		tSprite->sprite = newTower->getSprite();
		tSprite->cellX = 0;
		tSprite->cellY = 0;

		addTouchableSprite(tSprite);
	}
}
Пример #2
0
Tower* ObjectFactory::createTower(TowerStructDTO* towerStructDTO, b2World* world)
{
    TowerDTO* towerDTO = DataCollector::getInstance()->getTowerDTOByKey(towerStructDTO->id.c_str());
    Tower* tower = NULL;
    if(strcasecmp(towerStructDTO->type.c_str(), "main") == 0)
    {
        tower = MainCrystal::create();
//        CCLOG("main");
    }
    else
    {
        tower = Tower::create();
//        CCLOG("tower");
    }
    
    
    tower->setOriginCharacterData(towerDTO->data);
    
    //Create Animation
    string run = towerDTO->animation;
    string attack = towerDTO->animation;
    string idle = towerDTO->animation;
    string fall = towerDTO->animation;
    string fly = towerDTO->animation;
    string jump = towerDTO->animation;
    string die = towerDTO->animation;
    
    tower->runAnimation = DataCollector::getInstance()->getAnimationObjectByKey(run.append(RUN).c_str());
    tower->attackAnimation = DataCollector::getInstance()->getAnimationObjectByKey(attack.append(ATTACK).c_str());
    tower->jumpAnimation = DataCollector::getInstance()->getAnimationObjectByKey(jump.append(JUMP).c_str());
    tower->idleAnimation = DataCollector::getInstance()->getAnimationObjectByKey(idle.append(IDLE).c_str());
    tower->fallAnimation = DataCollector::getInstance()->getAnimationObjectByKey(fall.append(FALL).c_str());
    tower->flyAnimation = DataCollector::getInstance()->getAnimationObjectByKey(fly.append(FLY).c_str());
    tower->dieAnimation = DataCollector::getInstance()->getAnimationObjectByKey(die.append(DIE).c_str());
    tower->setSoundData(SoundManager::loadCharacterSoundData(towerDTO->soundId.c_str()));
//    if( tower->attackAnimation != NULL)
//    {
//        tower->attackAnimation->getAnimation()->setDelayPerUnit(tower->getOriginCharacterData().getAttackSpeed());
//    }
    
    
    //body
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.angle = ccpToAngle(ccp(0,0));
    bodyDef.fixedRotation=true;
    
    b2Body *body = world->CreateBody(&bodyDef);
    
    gbox2d::GB2ShapeCache *sc =  gbox2d::GB2ShapeCache::sharedGB2ShapeCache();
    sc->addFixturesToBody(body,  towerDTO->body.c_str());
    tower->setSpriteAnchorPoint(sc->anchorPointForShape(towerDTO->body.c_str()));
    tower->getSprite()->setAnchorPoint(sc->anchorPointForShape(towerDTO->body.c_str()));
    tower->setSkin(body, tower->getSprite());
    
    //
    tower->setSensor(towerDTO->towerSensorId.c_str());
    
    tower->setSkill(NORMAL_ATTACK, SkillFactory::createSkill(towerDTO->data.getSkill0().c_str(), world, tower, false, SKILL_0_BTN));
    //    tower->setSkill1(SkillFactory::createSkill(towerDTO->data.getSkill1().c_str(), world, tower, false, SKILL_1_BUTTON));
    //    tower->setSkill2(SkillFactory::createSkill(towerDTO->data.getSkill2().c_str(), world, tower, false, SKILL_2_BUTTON));
    
    tower->setPositionInPixel(ccp(towerStructDTO->positionX,towerStructDTO->positionY));
    tower->setGroup(towerStructDTO->group);
    
    tower->setSoundData(SoundManager::loadCharacterSoundData(towerDTO->soundId.c_str()));
    
    tower->onCreate();
    return tower;
}