void CGO_Player::setRunStateSafe (Uint8 state) { if (state == getRunState()) { // no change return; } switch(state) { case XSTAND: setRunState(state); if (getAniState() != SSTAND) { // setAniDirState(SSTAND, direction); // set from move() } break; case XWALK: setRunState(state); if (getAniState() != SWALK) { // setAniDirState(SWALK, direction); // set from move() } break; case XBLOCKED: setRunState(state); // move to full cell setArrayX( getArrayX( getArrayMiddleX())); setArrayY( getArrayY( getArrayMiddleY())); if ( getAniState() != SCORNERHEAD ) { // setAniDirState(SCORNERHEAD, ASOUTH); // set from move() er.report(LOG_INFO, _("%s: setAniDirState(SCORNERHEAD, ASOUTH)\n"), AT); } break; }; }
void StarContainer::SearchDelStar(int index,int type) { int x , y , dx , dy , tIndex; x = getArrayX( index ); y = getArrayY( index ); // left dx = x - 1; tIndex = getArrayIndex( dx , y); if( IsInMap( dx , y ) && IsMatchType( m_pStars[dx][y]->GetType() , type ) && IsNotInList(tIndex) ) openList->push_back( tIndex ); // right dx = x + 1; tIndex = getArrayIndex( dx , y); if( IsInMap( dx , y ) && IsMatchType(m_pStars[dx][y]->GetType() , type ) && IsNotInList(tIndex) ) openList->push_back( tIndex ); // top dy = y - 1; tIndex = getArrayIndex( x , dy); if( IsInMap( x , dy ) && IsMatchType(m_pStars[x][dy]->GetType() , type ) && IsNotInList(tIndex) ) openList->push_back( tIndex ); // buttom dy = y + 1; tIndex = getArrayIndex( x , dy); if( IsInMap( x , dy ) && IsMatchType(m_pStars[x][dy]->GetType() , type) && IsNotInList(tIndex) ) openList->push_back( tIndex ); closeList->push_back( index ); if( openList->size() == 0 ) return; index = openList->back(); openList->pop_back(); SearchDelStar(index,type); }
void StarContainer::ClickStar(::cocos2d::CCPoint point) { int x = (point.x - 20) / GameMap::GetInstance()->cellWidth; int y = ( point.y - 140 ) / GameMap::GetInstance()->cellHeight; // begin search star by type openList->clear(); closeList->clear(); if( !IsInMap(x,y) || GameMap::GetInstance()->GetGameState() == WAIT_START) return; switch (GameMap::GetInstance()->GetGameState()) { case NORMAL: { SearchDelStar( getArrayIndex( x , y ) , m_pStars[x][y]->GetType()); if(closeList->size() <= 1) return; canReturn = true; break; } case Use_Item_Lolly: { closeList->push_back( getArrayIndex( x , y ) ); if(GameItemManager::GetInstance()->UseItem(Item_Lolly)) { if(closeList->size() < 1) return; canReturn = true; } else closeList->clear(); GameMap::GetInstance()->SetGameStage(NORMAL); UIManager::GetInstance()->getUIUseItem()->deactivate(); break; } case Use_Item_Candy: { if(m_pStars[x][y] == NULL) return; if(GameItemManager::GetInstance()->UseItem(Item_Candy)) { GameMap::GetInstance()->getSpriteBatchBode()->removeChild( m_pStars[x][y]->GetAvata(),true ); m_pStars[x][y] = new Star( 7 ); m_pStars[x][y]->SetPosition( m_pStars[x][y]->getPosition( x , y)); GameMap::GetInstance()->getSpriteBatchBode()->addChild(m_pStars[x][y]->GetAvata()); } GameMap::GetInstance()->SetGameStage(NORMAL); UIManager::GetInstance()->getUIUseItem()->deactivate(); return; } case Use_Item_Return: { if(canReturn && GameItemManager::GetInstance()->UseItem(Item_Return)) { canReturn = false; GameMap::GetInstance()->UseReturn(); } GameMap::GetInstance()->SetGameStage(NORMAL); UIManager::GetInstance()->getUIUseItem()->deactivate(); return; } case Use_Item_Refresh: { if(GameItemManager::GetInstance()->UseItem(Item_Refresh)) { canReturn = true; GameMap::GetInstance()->UseRefresh(); } GameMap::GetInstance()->SetGameStage(NORMAL); UIManager::GetInstance()->getUIUseItem()->deactivate(); return; } } SavePreStep(); // play click effect sound std::vector<int>::iterator it = closeList->begin(); for( ; it!= closeList->end(); it++ ) { x = getArrayX( *it ); y = getArrayY( *it ); GameMap::GetInstance()->getSpriteBatchBode()->removeChild( m_pStars[x][y]->GetAvata() , true ); m_pStars[x][y]->Die(); delete m_pStars[x][y]; m_pStars[x][y] = NULL; } GameMap::GetInstance()->PopStarSettle( closeList->size() ); // reset x it = closeList->begin(); for( ; it!= closeList->end(); it++ ) { x = getArrayX( *it ); y = getArrayY( *it ); int startIndex = -1; for( int j = 0 ; j < ROLE_NUM ; j++ ) { if(m_pStars[x][j] == NULL) { startIndex = j; break; } } if(startIndex == -1) continue; for( int j = startIndex + 1; j < ROLE_NUM ; j++ ) { Star* mTemp = m_pStars[x][j-1]; m_pStars[x][j-1] = m_pStars[x][j]; m_pStars[x][j] = mTemp; } } // rest y it = closeList->begin(); for( ; it!= closeList->end(); it++ ) { x = getArrayX( *it ); y = getArrayY( *it ); int startIndex = -1; for( int j = 0 ; j < ROLE_NUM ; j++ ) { if(m_pStars[x][j] == NULL) { startIndex = j; break; } } if(startIndex == -1) continue; for( int j = startIndex + 1; j < ROLE_NUM ; j++ ) { Star* mTemp = m_pStars[x][j-1]; m_pStars[x][j-1] = m_pStars[x][j]; m_pStars[x][j] = mTemp; } } // rest x it = closeList->begin(); for( ; it!= closeList->end(); it++ ) { x = getArrayX( *it ); y = getArrayY( *it ); int nullCount = 0; int startIndex = -1; for( int i = 0 ; i < ROLE_NUM ; i++ ) { nullCount = 0; for( int j = 0 ; j < ROLE_NUM ; j++ ) { if( m_pStars[i][j] == NULL ) { startIndex = i; nullCount++; } } if(nullCount == ROLE_NUM) break; } if(nullCount == ROLE_NUM) { for( int i= startIndex + 1 ; i < ROLE_NUM ; i++ ) { for( int j = 0; j < ROLE_NUM ; j++ ) { Star* mTemp = m_pStars[i-1][j]; m_pStars[i-1][j] = m_pStars[i][j]; m_pStars[i][j] = mTemp; } } } } // rest graph for (int i=0;i<10;i++) { for (int j=0;j<10;j++) { if(m_pStars[i][j] != NULL) { CCSprite* sprite = m_pStars[i][j]->GetAvata(); CCMoveTo* moveTo = CCMoveTo::create( MOVE_TIME , m_pStars[i][j]->getPosition( i , j)); CCEaseBounceOut* easeOut = CCEaseBounceOut::create(moveTo); sprite->runAction(easeOut); } } } bool gameOver = true; // check the is no star to destory for( int i = 0 ; i< ROLE_NUM ; i++ ) { for( int j = 0 ; j < ROLE_NUM ; j++ ) { if( m_pStars[i][j] == NULL ) continue; closeList->clear(); SearchDelStar( getArrayIndex( i , j) , m_pStars[i][j]->GetType() ); if (closeList->size() > 1) { gameOver = false; break; } } } // gameOver next stage if(gameOver) GameMap::GetInstance()->CompleteLevel(); }
Sint8 CGO_Player::setPlayerRelXY (Sint16 x, Sint16 y) { t_field f; /* if( (getArrayMiddleX() + x + BOX_W2) / BOX_W >= GA_W ) er.report(LOG_WARNING, "%s: X+ %d,%d,%d,%d\n", AT, getArrayX(), getArrayMiddleX(), x, (getArrayMiddleX() + x + BOX_W2)/BOX_W ); if( (getArrayMiddleX() + x - BOX_W2) / BOX_W < 0 ) er.report(LOG_WARNING, "%s: X- %d,%d,%d,%d\n", AT, getArrayX(), getArrayMiddleX(), x, (getArrayMiddleX() + x - BOX_W2)/BOX_W ); */ if (x > 0) { //if (getArrayX(getArrayMiddleX()) != getArrayX(getArrayMiddleX() + x + BOX_W2)) { f = ga->getBoardField(getArrayX(getArrayMiddleX() + x + BOX_W2), getArrayY(getArrayMiddleY())); if (f.occupancy != TBLANK || f.bomb == true) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -1; } else { // if ( abs( (getArrayMiddleY() % BOX_H) - BOX_H2 ) >= BOX_H2 - 1 ) // { // setY( getArrayY( getArrayMiddleY() ) * BOX_H ); // return -5; // } // if ( getArrayX( getArrayMiddleX() + BOX_W2 ) != getArrayX( getArrayMiddleX() + x + BOX_W2 ) ) // { // if ( ga->getBoardField( getArrayX( getArrayMiddleX() + x + BOX_W2 ), getArrayY( getArrayMiddleY() ) ).powerup >= 0 ) // { // setPowerup( ga->getBoardField( getArrayX( getArrayMiddleX() + x + BOX_W2 ), getArrayY( getArrayMiddleY() ) ).powerup ); // ga->setFieldValPowerup( getArrayX( getArrayMiddleX() + x + BOX_W2 ), getArrayY( getArrayMiddleY() ), -1 ); // } // } } } } if (x < 0) { //if (getArrayX(getArrayMiddleX()) != getArrayX(getArrayMiddleX() + x - BOX_W2)) { f = ga->getBoardField(getArrayX(getArrayMiddleX() + x - BOX_W2), getArrayY(getArrayMiddleY())); if (f.occupancy != TBLANK || f.bomb == true) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -1; } else { // if ( abs( (getArrayMiddleY() % BOX_H) - BOX_H2 ) >= BOX_H2 - 1 ) // { // setY( getArrayY( getArrayMiddleY() ) * BOX_H ); // return -5; // } // if ( getArrayX( getArrayMiddleX() - BOX_W2 ) != getArrayX( getArrayMiddleX() + x - BOX_W2 ) ) // { // if ( ga->getBoardField( getArrayX( getArrayMiddleX() + x - BOX_W2 ), getArrayY( getArrayMiddleY() ) ).powerup >= 0 ) // { // setPowerup( ga->getBoardField( getArrayX( getArrayMiddleX() + x - BOX_W2 ), getArrayY( getArrayMiddleY() ) ).powerup ); // ga->setFieldValPowerup( getArrayX( getArrayMiddleX() + x - BOX_W2 ), getArrayY( getArrayMiddleY() ), -1 ); // } // } } } } if (y > 0) { //if (getArrayY(getArrayMiddleY()) != getArrayY(getArrayMiddleY() + y + BOX_H2)) { f = ga->getBoardField(getArrayX(getArrayMiddleX()), getArrayY(getArrayMiddleY() + y + BOX_H2)); if (f.occupancy != TBLANK || f.bomb == true) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -1; } else { // if ( abs( (getArrayMiddleX() % BOX_W) - BOX_W2 ) >= BOX_W2 - 1 ) // { // setX( getArrayX( getArrayMiddleX() ) * BOX_W ); // return -5; // } // if ( getArrayY( getArrayMiddleY() + BOX_H2 ) != getArrayY( getArrayMiddleY() + y + BOX_H2 ) ) // { // if ( ga->getBoardField( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y + BOX_H2 ) ).powerup >= 0 ) // { // setPowerup( ga->getBoardField( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y + BOX_H2 ) ).powerup ); // ga->setFieldValPowerup( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y + BOX_H2 ), -1 ); // } // } } } } if (y < 0) { //if (getArrayY(getArrayMiddleY()) != getArrayY(getArrayMiddleY() + y - BOX_H2)) { f = ga->getBoardField(getArrayX(getArrayMiddleX()), getArrayY(getArrayMiddleY() + y - BOX_H2)); if (f.occupancy != TBLANK || f.bomb == true) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -1; } else { // if ( abs( (getArrayMiddleX() % BOX_W) - BOX_W2 ) >= BOX_W2 - 1 ) // { // setX( getArrayX( getArrayMiddleX() ) * BOX_W ); // return -5; // } // if ( getArrayY( getArrayMiddleY() - BOX_H2 ) != getArrayY( getArrayMiddleY() + y - BOX_H2 ) ) // { // if ( ga->getBoardField( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y - BOX_H2 ) ).powerup >= 0 ) // { // setPowerup( ga->getBoardField( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y - BOX_H2 ) ).powerup ); // ga->setFieldValPowerup( getArrayX( getArrayMiddleX() ), getArrayY( getArrayMiddleY() + y - BOX_H2 ), -1 ); // } // } } } } if (moveRel(x, y) != 0) return -1; if (ga->getBoardField(getArrayX(getArrayMiddleX()), getArrayY(getArrayMiddleY())).powerup >= 0) { incPowerup(ga->getBoardField(getArrayX(getArrayMiddleX()), getArrayY(getArrayMiddleY())).powerup); ga->setFieldValPowerup(getArrayX(getArrayMiddleX()), getArrayY(getArrayMiddleY()), -1); /* FIX!!!!!!!! if (ga->getRandomPowerups() <= 0) { render.changeAnimStateRandomPowerups(false); } else { if (ga->getRandomPowerups() == 1) { render.changeAnimStateRandomPowerups(true); } } */ } Sint16 modX, modY; Sint16 rdx, rdy; modX = getArrayMiddleX() % BOX_W; modY = getArrayMiddleY() % BOX_H; rdx = abs((getArrayMiddleX() % BOX_W) - BOX_W2) / getSpeedX(); rdy = abs((getArrayMiddleY() % BOX_H) - BOX_H2) / getSpeedY(); if (x != 0) { // if ( abs( (getArrayMiddleY() % BOX_H) - BOX_H2 ) == BOX_H2 ) // { // setX( getArrayX( getArrayMiddleX() ) * BOX_W ); // return -5; // } // if ( abs( (getArrayMiddleX() % BOX_W) - BOX_W2 ) == BOX_W2 ) // { // setY( getArrayY( getArrayMiddleY() ) * BOX_H ); // return -5; // } if (modY < BOX_H2) { if (getArrayMiddleY() + rdy > BOX_H2) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -4; } else { if (rdy == 0 && (getArrayMiddleY() % BOX_H2) > 0) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -3; } else { return moveRel(0, rdy); } } } else if (modY > BOX_H2) { if (getArrayMiddleY() - rdy < BOX_H2) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -4; } else { if (rdy == 0 && (getArrayMiddleY() % BOX_H2) > 0) { setY(getArrayY(getArrayMiddleY()) * BOX_H); return -3; } else { return moveRel(0, -rdy); } } } } if (y != 0) { // if ( abs( (getArrayMiddleX() % BOX_W) - BOX_W2 ) >= BOX_W2 ) // { // setY( getArrayY( getArrayMiddleY() ) * BOX_H ); // return -5; // } // if ( abs( (getArrayMiddleY() % BOX_H) - BOX_H2 ) >= BOX_H2 ) // { // setX( getArrayX( getArrayMiddleX() ) * BOX_W ); // return -5; // } if (modX < BOX_W2) { if (getArrayMiddleX() + rdx > BOX_W2) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -4; } else { if (rdx == 0 && (getArrayMiddleX() % BOX_W2) > 0) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -3; } else { return moveRel(rdx, 0); } } } else if (modX > BOX_W2) { if (getArrayMiddleX() - rdx < BOX_W2) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -4; } else { if (rdx == 0 && (getArrayMiddleX() % BOX_W2) > 0) { setX(getArrayX(getArrayMiddleX()) * BOX_W); return -3; } else { return moveRel(-rdx, 0); } } } } return -91; // if ( y != 0 ) // { // if ( getX() % 40 != 0 ) // setX( getArrayX() * 40 ); // } // if ( x < 0 ) // setY( getArrayY() * 36 + ( modY - modX ) ); // else // setY( getArrayY() * 36 + ( modY - (18+modX) ) ); }