PlayScene::PlayScene(sf::Vector2i touchedPosition, float playerBubbleSize) : BubbleScript("script_playscene"), m_bubbleLoadTimer(sGame->GetClock().getElapsedTime().asMilliseconds()), m_playerBubbleSizeOnEnd(PlayerBubbleDefault::MinSize), m_bubbleLoaded(false), m_touchPlayerCoordDiff(nullvec2f), m_ptrSoundSprite(nullptr), m_soundEnabled(true), m_scorePanel(nullptr) { m_status = Status::Process; const float playerBubbleRadius = playerBubbleSize / 2; // Set player bubble to center const sf::Vector2f centerPlayerCoord(touchedPosition.x - playerBubbleRadius, touchedPosition.y - playerBubbleRadius); // Add player bubbles for (uint16 i = 0; i < PlaySceneDefault::PlayerBubbleCount; ++i) { // Increment coord sf::Vector2f incCoord = (sf::Vector2f)centerPlayerCoord; incCoord.x += (i * 2 * playerBubbleSize); m_bubbles.push_back(new PlayerBubble(playerBubbleRadius, incCoord)); } sf::Texture const& soundTexture = *GET_TEXTURE(eResources::Img_Sound); m_ptrSoundSprite = new sf::Sprite(soundTexture); m_ptrSoundSprite->setPosition(10, 10); m_drawables.push_back(m_ptrSoundSprite); m_scorePanel = new ScorePanel; m_drawables.push_back(m_scorePanel); // Set scores m_scorePanel->SetValue(eScores::PLAYER, (uint32)playerBubbleSize); m_scorePanel->SetValue(eScores::GOOD_BUBBLES, PlaySceneDefault::GoodBubbleCount); }
void StoryWorld::avgGame(void) { CCLabelTTF* myDialog = (CCLabelTTF *)getChildByTag(100); CCLabelTTF* myName = (CCLabelTTF *)getChildByTag(101); CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102); CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1); CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2); strcpy(dialog, reader.GetNextDialog().c_str()); char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"}; myName->setString(theName[dialog[0]-48]); characterPasterSwitchCase(dialog[0]); switch (dialog[2]) { case '1': { setTouchEnabled(false); CCSprite *back = CCSprite::create(LANDSCAPE_IMG_PATH); back->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); back->setOpacity(150); back->setTag(3); addChild(back, 3); switch (current) { case '3': { CCLabelTTF *Label1 = CCLabelTTF::create("Yes", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("No", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::leafletChoiceHandler)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::leafletChoiceHandler)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; case '9': { CCLabelTTF *Label1 = CCLabelTTF::create("子轩", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("少杰", "Heiti SC", 40); CCLabelTTF *Label3 = CCLabelTTF::create("建国", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::theFinalChoiceHandler)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::theFinalChoiceHandler)); CCMenuItemLabel *thirdChoice = CCMenuItemLabel::create(Label3, this, menu_selector(StoryWorld::theFinalChoiceHandler)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); thirdChoice->setTag(tChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); thirdChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 1.8)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, thirdChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; default: break; } } break; case '2': { } break; case '3': { if (myLeftSprite->getOpacity() == 0) myLeftSprite->setOpacity(255); else myLeftSprite->runAction(CCFadeOut::create(1)); } break; case '4': { if (myRightSprite->getOpacity() == 0) myRightSprite->setOpacity(255); else myRightSprite->runAction(CCFadeOut::create(1)); } break; case '5': { if (myRightSprite->getOpacity()==0 && myLeftSprite->getOpacity()==0) { myLeftSprite->setOpacity(255); myRightSprite->setOpacity(255); } else if (myRightSprite->getOpacity()!=0 && myLeftSprite->getOpacity()!=0) { myLeftSprite->runAction(CCFadeOut::create(1)); myRightSprite->runAction(CCFadeOut::create(1)); } } break; default: break; } specialPartSwitchCase(dialog[3]); audioSwitchCase(dialog[4]); char all_bg[8][4] = {"010", "030", "204", "701", "717", "725", "732"}; char bg_num[4]="000"; int curLine = reader.getCurLine(); sprintf(bg_num, "%c%02d", current, curLine); if (curLine == 0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]=BGNAME_IMG_PATH; bg_name[BGNAME_PATH_LEN] = current; Background->setTexture(GET_TEXTURE(bg_name)); } else { for (int i =0; i<8; i++) { if (strcmp(all_bg[i], bg_num)==0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]=""; sprintf(bg_name, BGNAME_IMG_PATH, bg_num); Background->setTexture(GET_TEXTURE(bg_name)); } } } myDialog->setString(dialog+5); }
bool StoryWorld::init() { if ( !CCLayer::init() ) { return false; } char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"}; char play[20] = SCRIPT_PATH; current=sGlobal->mapState->storyCnt+'0'; play[SCRIPT_PATH_LEN] = current; reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play)); this->setTouchEnabled(true); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); char bg_name[30] = "" ; char bg_num[4]=""; sprintf(bg_num, "%c00", current); sprintf(bg_name, BGNAME_IMG_PATH, bg_num); CCSprite *pBackground = CCSprite::createWithTexture(GET_TEXTURE(bg_name)); //CCSprite* pBackground = CCSprite::create(bg_name); pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); pBackground->setScale(1); pBackground->setTag(108); addChild(pBackground, 0); CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH); dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2)); dialogBox->setOpacity(220); addChild(dialogBox,1); CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40); pName->setTag(101); pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height)); pName->setAnchorPoint(CCPointZero); addChild(pName, 1); CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40); pLabel->setTag(100); pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height)); pLabel->setAnchorPoint(CCPointZero); pLabel->setDimensions(CCSizeMake(1100, 0)); pLabel->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(pLabel, 1); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH); CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::createWithTexture(GET_TEXTURE(VDRAWING_IMG_PATH)); spriteBatch->setTag(102); addChild(spriteBatch, 0); spriteBatch->setPosition(CCPointZero); CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png"); leftSprite->setScale(0.8); leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.6, leftSprite->getContentSize().height/2 *0.8)); leftSprite->setTag(1); leftSprite->setOpacity(0); spriteBatch->addChild(leftSprite, 0); CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png"); //rightSprite->setScale(0.8); rightSprite->setPosition(ccp(800, 130)); rightSprite->setTag(2); rightSprite->setOpacity(0); spriteBatch->addChild(rightSprite, 0); avgGame(); return true; }