Ejemplo n.º 1
0
void GameLayer::resetMapNode(CCNode *node)
{
    // window size
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCLOG("winSize %f %f random %f %f", winSize.width, winSize.height, CCRANDOM_0_1(), CCRANDOM_MINUS1_1());
    // get batchnode
    CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)node->getChildByTag(MapBatchNodeTag);
    
    // reset monster position
    float positionX = kGameMapFirstRoad + (rand()%3) * kGameMapRoadSpace;
    CCSprite *monsterSprite = (CCSprite *)batchNode->getChildByTag(MapMonsterTag);
    monsterSprite->setPosition(ccp(positionX, CCRANDOM_0_1() * winSize.height));

    // reset river position
    CCSprite *riverSprite = (CCSprite *)batchNode->getChildByTag(MapRiverTag);
    float iptr = winSize.height;
    float positionY = modff((CCRANDOM_0_1() * 100 + 50 + monsterSprite->getPosition().y), &iptr);
    riverSprite->setPosition(ccp(winSize.width/2.f, positionY));
    
    // reset coins position
    positionX = kGameMapFirstRoad + (rand()%3) * kGameMapRoadSpace;
    float startPositionY = CCRANDOM_0_1() * winSize.height;
    for (int i = 0; i < kGameCoinCount; i ++) {
        CCSprite *coinSprite = (CCSprite *)batchNode->getChildByTag(MapCoinStartTag + i);
        iptr = winSize.height;
        positionY = modff(startPositionY + 60 * i, &iptr);
        coinSprite->setPosition(ccp(positionX, positionY));
        coinSprite->setVisible(true);
    }
}
Ejemplo n.º 2
0
void GameLayer::_resetPlatform()
{
    if(platformCount >= K_MAX_PLATFORMS_IN_GAME) {
    
        isGameOver = true;
    }
    
    if(currentPlatformY < 0)
        currentPlatformY = 30.0f;
    else
    {
        currentPlatformY += CCRANDOM_0_1() * (int)(currentMaxPlatformStep - K_MIN_PLATFORM_STEP) + K_MIN_PLATFORM_STEP;
        if(currentMaxPlatformStep < K_MAX_PLATFORM_STEP)
            currentMaxPlatformStep += 0.5f;
    }
    
    CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager));
    CCSprite* platform = dynamic_cast<CCSprite*>(batchNode->getChildByTag(currentPlatformTag));
    
    if(CCRANDOM_0_1() * 2 == 1)
        platform->setScaleX(-1.0f);
    
    float x;
    
    CCSize size = platform->getContentSize();
    
    if(currentPlatformY == 30.0f)
        x = SCREEN_WIDTH * 0.5f;
    else
        x = CCRANDOM_0_1() * (SCREEN_WIDTH - (int) size.width) + size.width * 0.5f;
    
    platform->setPosition(ccp(x, currentPlatformY));
    platformCount++;
    
    if(platformCount == currentBonusPlatformIndex && platformCount != K_MAX_PLATFORMS_IN_GAME)
    {
        CCSprite* bonus = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBonusStartTag + currentBonusType));
        bonus->setPosition(ccp(x, currentPlatformY + 30));
        bonus->setVisible(true);
    }
    
    // TODO: If the platform count reaches K_MAX_PLATFORMS, Add the "Exit" icon onto the platform.
    if (platformCount == K_MAX_PLATFORMS_IN_GAME)
    {
        // Add the "Exit" icon onto the platform.
        CCSprite* exit = dynamic_cast<CCSprite*>(getChildByTag(kExit));
        exit->setPosition(ccp(x, currentPlatformY + 48));
        exit->setVisible(true);
    }
}
Ejemplo n.º 3
0
void GameLayer::resetBarrierNode(CCNode *node, int nodeTag)
{
    // window size
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    // get batchnode
    CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)node->getChildByTag(MapBatchNodeTag);
    
    CCNode *mapNode = this->getChildByTag(nodeTag - MapBarrierStartTag + MapStartTag);
    CCSpriteBatchNode *mapBatchNode = (CCSpriteBatchNode *)mapNode->getChildByTag(MapBatchNodeTag);
    CCSprite *riverSprite = (CCSprite *)mapBatchNode->getChildByTag(MapRiverTag);
    
    // reset barrier position
    CCSprite *barrierSprite = (CCSprite *)batchNode->getChildByTag(MapBarrierTag);
    float iptr = winSize.height;
    float positionY = modff((CCRANDOM_0_1() * 100 + 50 + riverSprite->getPosition().y), &iptr);
    barrierSprite->setPosition(ccp(winSize.width/2.f, positionY));
}
Ejemplo n.º 4
0
void GameLayer::_resetBonus()
{
    CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager));
    CCSprite* bonus = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBonusStartTag + currentBonusType));
    bonus->setVisible(false);
    
    currentBonusPlatformIndex += CCRANDOM_0_1() * (K_MAX_BONUS_STEP - K_MIN_BONUS_STEP) + K_MIN_BONUS_STEP;
    
    if(score < 10000)
        currentBonusType = 0;
    else if(score < 50000)
        currentBonusType = CCRANDOM_0_1() * 2;
    else if(score < 100000)
        currentBonusType = CCRANDOM_0_1() * 3;
    else
        currentBonusType = CCRANDOM_0_1() * 2 + 2;
    
}
Ejemplo n.º 5
0
// bird logic
void GameLayer::_resetBird()
{
    CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager));
    CCSprite* bird = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBird));
    
    bird_position.x = SCREEN_WIDTH * 0.5f;
    bird_position.y = SCREEN_WIDTH * 0.5f;
    bird->setPosition(bird_position);
    
    bird_velocity.x = 0;
    bird_velocity.y = 0;
    
    bird_acceleration.x = 0;
    bird_acceleration.y = -550.0f;
    
    birdLookingRight = true;
    bird->setScaleX(1.0f);
}
Ejemplo n.º 6
0
void GameLayer::update(float dt)
{
    if(gameSuspended)
        return;
    
    // MainLayer shows the background with clouds that does just scrolls but does not interact
    MainLayer::update(dt);
    
    CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager));
    CCSprite* bird = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBird));
    
    bird_position.x += bird_velocity.x * dt;
    // birdLookingRight/Left is used to flip the bird in the right direction i.e. direction of the velocity
    // so the bird does not travel backwards
    if(bird_velocity.x < -30.0f && birdLookingRight)
    {
        birdLookingRight = false;
        
        // what is the point of setting scaleX?
        bird->setScaleX(-1.0f);
    }
    else if(bird_velocity.x > 30.0f && !birdLookingRight)
    {
        birdLookingRight = true;
        bird->setScaleX(1.0f);
    }
    
    CCSize bird_size = bird->getContentSize();
    float max_x = SCREEN_WIDTH + bird_size.width * 0.5f;
    float min_x = -bird_size.width * 0.5f;
    
    if(bird_position.x > max_x)
        bird_position.x = min_x;
    
    if(bird_position.x < min_x)
        bird_position.x = max_x;
    
    bird_velocity.y += bird_acceleration.y * dt;
    bird_position.y += bird_velocity.y * dt;
    
  
    // TODO: (fix this hack) - just set it so that every 20 frames, we decrease the percentage by 1
    // when the percentage goes below zero, the healthbar is finished and finish the game
    // We should show some animation that the health is over.
    fuelInTank--;
    if (fuelInTank%20 == 0)
    {
        pHealthBar->setPercentage(pHealthBar->getPercentage()-1.0);
        if (pHealthBar->getPercentage() <= 0)
        {
            _showHighScores();
        }
    }
    
    
    CCSprite* bonus = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBonusStartTag + currentBonusType));
    
    // check if the bonus node is visible
    if(bonus->isVisible())
    {
        // check if the bird and the bonus are colliding, if so, give the bird the bonus
        CCPoint bonus_position = bonus->getPosition();
        float range = 20.0f;
        if(bird_position.x > bonus_position.x - range &&
           bird_position.x < bonus_position.x + range &&
           bird_position.y > bonus_position.y - range &&
           bird_position.y < bonus_position.y + range)
        {
            // TODO: Our bonuses should be more rocket fuel or additional lives
            switch(currentBonusType)
            {
                case kBonus5:
                    score += 5000;
                    break;
                case kBonus10:
                    score += 10000;
                    break;
                case kBonus50:
                    score += 50000;
                    break;
                case kBonus100:
                    score += 100000;
                    break;
            }
            
            CCString* scoreStr = CCString::createWithFormat("%d", score);
            CCLabelBMFont* scoreLabel = dynamic_cast<CCLabelBMFont*>(getChildByTag(kScoreLabel));
            scoreLabel->setString(scoreStr->getCString());
            
            CCScaleTo* action1 = CCScaleTo::create(0.2f, 1.5f, 0.8f);
            CCScaleTo* action2 = CCScaleTo::create(0.2f, 1.0f, 1.0f);
            
            // What are CCScaleTo and CCSequence.. what do these actions do?
            // Likely, this just makes the bird move up very fast without it having to collide with anything
            CCSequence* action3 = CCSequence::create(action1, action2, action1, action2, action1, action2, NULL);
            scoreLabel->runAction(action3);

            // what does resetBonus do?
            _resetBonus();
            
            _superJump();
            
        }
    }
    
    int cloudTag;
    int platformTag;
    
    // bird collisions with platforms are detected only when the bird is falling down
    if(bird_velocity.y < 0)
    {
        for(platformTag = kPlatformsStartTag; platformTag < kPlatformsStartTag + K_NUM_PLATFORMS; platformTag++)
        {
            CCSprite* platform = dynamic_cast<CCSprite*>(batchNode->getChildByTag(platformTag));
            CCSize platform_size = platform->getContentSize();
            CCPoint platform_position = platform->getPosition();
            
            max_x = platform_position.x - platform_size.width * 0.5f - 10;
            min_x = platform_position.x + platform_size.width * 0.5f + 10;
            float min_y = platform_position.y + (platform_size.height + bird_size.height) * 0.5f - K_PLATFORM_TOP_PADDING;
            
            // check if the bird and the platform is colliding, if so, make the bird jump
            if(bird_position.x > max_x && bird_position.x < min_x &&
               bird_position.y > platform_position.y && bird_position.y < min_y)
                _jump();
        }
        
        // The game is endless in the original version.. when the bird falls down and is longer on the screen, call the game done and
        // show the high score screen
        if(bird_position.y < - bird_size.height)
            _showHighScores();
        
    }
    else if(bird_position.y > SCREEN_HEIGHT * 0.5f)
    {
        float delta = bird_position.y - SCREEN_HEIGHT * 0.5f;
        bird_position.y = SCREEN_HEIGHT * 0.5f;
        currentPlatformY -= delta;
        
        for(cloudTag = kCloudsStartTag; cloudTag < kCloudsStartTag + K_NUM_CLOUDS; cloudTag++)
        {
            CCSprite* cloud = dynamic_cast<CCSprite*>(batchNode->getChildByTag(cloudTag));
            CCPoint position = cloud->getPosition();
            position.y -= delta * cloud->getScaleY() * 0.8f;
            
            // assuming that the clouds in the background, when they have scrolled off the screen
            // reset them so that they will scroll in from the bottom
            if(position.y < -cloud->getContentSize().height * 0.5f)
            {
                currentCloudTag = cloudTag;
                resetCloud();
            }
            else
            {
                cloud->setPosition(position);
            }
        }
        

        for(platformTag = kPlatformsStartTag; platformTag < kPlatformsStartTag + K_NUM_PLATFORMS; platformTag++)
        {
            CCSprite* platform = dynamic_cast<CCSprite*>(batchNode->getChildByTag(platformTag));
            CCPoint position = platform->getPosition();
            position = ccp(position.x, position.y - delta);
            
            // If the platform just became invisible, reset it to just above the screen
            if(position.y < -platform->getContentSize().height * 0.5f)
            {
                currentPlatformTag = platformTag;
                _resetPlatform();
            }
            else
            {
                // If the platform is still visible, decrease its Y coordinates so it looks like the scene is scrolling
                platform->setPosition(position);
            }
        }

        
        CCSprite* exit = dynamic_cast<CCSprite*>(getChildByTag(kExit));
        if(exit->isVisible())
        {
            CCPoint position = exit->getPosition();
            // check if the bird and the exit are colliding, if so, finish the game
            float range = 20.0f;
            if(bird_position.x > position.x - range &&
               bird_position.x < position.x + range &&
               bird_position.y > position.y - range &&
               bird_position.y < position.y + range)
            {
                // TODO: (would be nice to show an animation when exiting)
                _showHighScores();
            }
            
            position.y -= delta;
            if(position.y < -exit->getContentSize().height*0.5)
            {
              // the exit just passed out of the screen... you should show a "Game Over... you lose" kind of thing here
               // TODO: show an animation or something like... you lose!!
                _showHighScores();
            }
            
            exit->setPosition(position);
            
        }
        
        // if the bonus was visible and is going to become invisible, reset it.
        if(bonus->isVisible())
        {
            CCPoint position = bonus->getPosition();
            position.y -= delta;
            if(position.y < -bonus->getContentSize().height * 0.5f)
            {
                _resetBonus();
            }
            else
            {
                bonus->setPosition(position);
            }
        }
        
        score += (int) delta;
        CCString* scoreStr = CCString::createWithFormat("%d", score);
        CCLabelBMFont* scoreLabel = dynamic_cast<CCLabelBMFont*>(getChildByTag(kScoreLabel));
        scoreLabel->setString(scoreStr->getCString());
    }
    
    // draw the bird at its new position
    bird->setPosition(bird_position);
}
Ejemplo n.º 7
0
void GameLayer::update(float dt)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag);
    
    CCPoint currentPos = playerSprite->getPosition();
    // update run distance
    runDistance += (currentPos.y - prevPos.y);
    
    // stay the player at specified position
    if (currentPos.y > kPlayerStayAtScreenPosY) {
        CCPoint newPos = ccp(currentPos.x, kPlayerStayAtScreenPosY);
        CCPoint diff = ccpSub(newPos, currentPos);
        
        // move the player and map
        playerSprite->setPosition(newPos);
        
        // move map nodes
        for (int i = 0; i < kGameMapCount; i ++) {
            CCNode *mapNode = this->getChildByTag(MapStartTag + i);
            CCPoint mapPos = ccpAdd(mapNode->getPosition(), diff);
            mapNode->setPosition(mapPos);
            // if map get out of scene
            if (mapPos.y <= -winSize.height) {
                mapPos = ccp(mapPos.x, (kGameMapCount - 1) * winSize.height);
                mapNode->setPosition(mapPos);
                this->resetMapNode(mapNode);
            }
        }
        
        // move map barrier node
        for (int i = 0; i < kGameMapCount; i ++) {
            CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i);
            CCPoint barrierPos = ccpAdd(barrierNode->getPosition(), diff);
            barrierNode->setPosition(barrierPos);
            // if map get out of scene
            if (barrierPos.y <= -winSize.height) {
                barrierPos = ccp(barrierPos.x, (kGameMapCount - 1) * winSize.height);
                barrierNode->setPosition(barrierPos);
                this->resetBarrierNode(barrierNode, MapBarrierStartTag + i);
            }
        }
    }
    // save current pos
    prevPos = playerSprite->getPosition();
    
    // collision detection
    for (int i = 0; i < kGameMapCount; i ++) {
        CCNode *mapNode = this->getChildByTag(MapStartTag + i);
        CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)mapNode->getChildByTag(MapBatchNodeTag);
        
        CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition()));
        CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height);
        
        CCSprite *monsterSprite = (CCSprite *)batchNode->getChildByTag(MapMonsterTag);
        if (playerBox.intersectsRect(monsterSprite->boundingBox())) {
            // game over
            this->gameOver();
        }
        
        CCSprite *riverSprite = (CCSprite *)batchNode->getChildByTag(MapRiverTag);
        if (playerBox.intersectsRect(riverSprite->boundingBox())) {
            // not in jumpping
            if (!isJumpping) {
                // game over
                this->gameOver();
            }
        }
        
        for (int i = 0; i < kGameCoinCount; i ++) {
            CCSprite *coinSprite = (CCSprite *)batchNode->getChildByTag(MapCoinStartTag + i);
            if (playerBox.intersectsRect(coinSprite->boundingBox())) {
                coinSprite->setVisible(false);
                coinCount ++;
            }
        }
    }
    
    for (int i = 0; i < kGameMapCount; i ++) {
        CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i);
        CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)barrierNode->getChildByTag(MapBatchNodeTag);
        
        CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition()));
        CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height);
        
        CCSprite *barrierSprite = (CCSprite *)batchNode->getChildByTag(MapBarrierTag);
        if (playerBox.intersectsRect(barrierSprite->boundingBox())) {
            if (!isSliding) {
                // game over
                this->gameOver();
            }
        }
    }
    
    // update score label
    CCLabelTTF *scoreLabel = (CCLabelTTF *)this->getChildByTag(ScoreLabelTag);
    int totalScore = runDistance + coinCount;
    scoreLabel->setString(CCString::createWithFormat("score: %d", totalScore)->getCString());
}
Ejemplo n.º 8
0
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);
}
Ejemplo n.º 9
0
void StoryWorld::characterPasterSwitchCase(int code) {
  CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102);
  CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1);
  CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2);
  
  switch (dialog[0]) {
    case '0': {   //无人
      char b[10]="me_ .png";
      b[3] = dialog[1]+1;
      myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
      
    case '1': {   //ME
      char b[10]="me_ .png";
      b[3] = dialog[1]+1;
      myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '2': {   //子轩
      char b[10]="zx_ .png";
      b[3] = dialog[1]+1;
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '3': {   //少杰
      char b[10]="sj_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '4': {   //建国
      char b[10]="jg_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '5': {
      char b[10]="la_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '6': {
      char b[10]="lb_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '7': {
      char b[10]="lc_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '8': {
      char b[10]="yy_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
    case '9': {
      char b[10]="jj_ .png";
      b[3] = dialog[1];
      myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
    }
      break;
      
    default:
      break;
  }
}
Ejemplo n.º 10
0
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]={"","穆婧1:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};

	myName->setString(theName[dialog[0]-48]);
    //任务立绘切换
    switch (dialog[0]) {
        case '0': {   //无人
            char b[10]="me_ .png";
            b[3] = dialog[1]+1;
            myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '1': {   //ME
            char b[10]="me_ .png";
            b[3] = dialog[1]+1;
            myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '2': {   //子轩
            char b[10]="zx_ .png";
            b[3] = dialog[1]+1;
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '3': {   //少杰
            char b[10]="sj_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '4': {   //建国
            char b[10]="jg_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '5': {  
            char b[10]="la_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '6': { 
            char b[10]="lb_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '7': {
            char b[10]="lc_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '8': { 
            char b[10]="yy_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        case '9': { 
            char b[10]="jj_ .png";
            b[3] = dialog[1];
            myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b));
        }
            break;
        default:
            break;
    }

    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::makeAChoice));
                    CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::makeAChoice));
                    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': {
                    //创建CCMenu
                    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::makeAChoice));
                    CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::makeAChoice));
                    CCMenuItemLabel *thirdChoice = CCMenuItemLabel::create(Label3, this, menu_selector(StoryWorld::makeAChoice));
                    
                    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': {
            CCScene *combatScene = Combat::scene();
            CCDirector::sharedDirector()->pushScene(combatScene);
        }
            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;
    }
    
    // 剧本切换及完结及特效
    switch (dialog[3]) {
        case '1':{    // 保存进度
            current+=1;
			CCEGLView::sharedOpenGLView()->setDesignResolutionSize(672, 448, kResolutionExactFit);
            CCDirector::sharedDirector()->popScene();
            // TODO: POP OUT
        }
            break;
        case '2':{    // wanjie
			CCSprite* staff_bg = CCSprite::create(STAFFBG_IMG_PATH);
			staff_bg->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2 + CCDirector::sharedDirector()->getVisibleOrigin().x, CCDirector::sharedDirector()->getVisibleSize().height/2 + CCDirector::sharedDirector()->getVisibleOrigin().y));
			addChild(staff_bg, 4);

			CCSprite* staff = CCSprite::create(STAFF_IMG_PATH );
			staff->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, -CCDirector::sharedDirector()->getVisibleSize().height/2));
			addChild(staff, 5);

			CCActionInterval * moveTo = CCMoveTo::create(20,ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height*3/2));
			CCFiniteTimeAction*  sequneceAction = CCSequence::create(
				moveTo,
				CCCallFunc::create(this, callfunc_selector(StoryWorld::over)),
				NULL);

			staff->runAction(sequneceAction);
        }
            break;
        case '3':{
            CCSprite *black = CCSprite::create(BLACK_IMG_PATH);
            black->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2));
            black->setOpacity(0);
            addChild(black, 4);
            black->runAction(CCSequence::create(CCFadeIn::create(0.5), CCFadeOut::create(0.5), NULL));
        }
            break;
        default:
            break;
    }
    
    //音效
    switch (dialog[4]) {
        case '1': case '2': case '3': case '4': case '5':
        case '6':{
            char musicName[7] = " .mp3";
            musicName[0] = dialog[4];
            if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) {
                CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
            }
            CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathForFilename(musicName).c_str());
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathForFilename(musicName).c_str(), true);
        }
            break;
        case '7': {
            CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
        }
            break;
        case '8': case '9': case 'A': case 'B': case 'C': case 'D':
        case 'G':{
            char effectName[7] = " .wav";
            effectName[0] = dialog[4];
            
            CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str());
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str());
        }
            break;
        case 'E': case 'F': 
        case 'H':{
            char effectName[7] = " .mp3";
            effectName[0] = dialog[4];
            
            CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str());
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str());
        }
            break;
        default:
            break;
    }
    
    // 背景
    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(CCTextureCache::sharedTextureCache()->addImage(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]="img/story/bg_000.jpg";
                sprintf(bg_name, "img/story/bg_%s.jpg", bg_num);
                Background->setTexture(CCTextureCache::sharedTextureCache()->addImage(bg_name));
            }
        }
    }
    myDialog->setString(dialog+5);
}