void GameLayer::UpdateBullet(float dt) { // m_heroBulletList; for (auto it = m_heroBulletList.begin(); it != m_heroBulletList.end(); /*++it*/) { for (auto enemy = m_enemyList.begin(); enemy != m_enemyList.end(); ++enemy) { if (!(*enemy)->IsDeath() || !IsInMap(**it)) { if ((*it)->HitTest(*enemy, dt)) { break; } } } // (*it)->Update(dt); ++it; } for (auto it = m_heroBulletList.begin(); it != m_heroBulletList.end(); /*++it*/) { if ((*it)->IsDeath() || !IsInMap(**it)) { (*it)->removeFromParent(); m_heroBulletList.erase(it++); } else { (*it)->Update(dt); ++it; } } // m_enemyBulletList; for (auto it = m_enemyBulletList.begin(); it != m_enemyBulletList.end(); ++it) { (*it)->HitTest(m_pHero, dt); } for (auto it = m_enemyBulletList.begin(); it != m_enemyBulletList.end(); /*++it*/) { if ((*it)->IsDeath() || !IsInMap (**it)) { (*it)->removeFromParent(); m_enemyBulletList.erase(it++); } else { // (*it)->HitTest(m_pHero, dt); (*it)->Update(dt); ++it; } } }
bool GameObject::isVisibleForInState(Player const* u, bool inVisibleList) const { // Not in world if(!IsInWorld() || !u->IsInWorld()) return false; // Transport always visible at this step implementation if(IsTransport() && IsInMap(u)) return true; // quick check visibility false cases for non-GM-mode if(!u->isGameMaster()) { // despawned and then not visible for non-GM in GM-mode if(!isSpawned()) return false; // special invisibility cases /* TODO: implement trap stealth, take look at spell 2836 if(GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && GetGOInfo()->trap.stealthed && u->IsHostileTo(GetOwner())) { if(check stuff here) return false; }*/ // Smuggled Mana Cell required 10 invisibility type detection/state if(GetEntry()==187039 && ((u->m_detectInvisibilityMask | u->m_invisibilityMask) & (1<<10))==0) return false; } // check distance return IsWithinDistInMap(u,World::GetMaxVisibleDistanceForObject() + (inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false); }
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 GameLayer::UpdateEnemy(float dt) { for (auto it = m_enemyList.begin(); it != m_enemyList.end(); /*++it*/) { if ((*it)->IsDeath() || !IsInMap(**it)) { (*it)->removeFromParent(); m_enemyList.erase(it++); } else { (*it)->Update(dt); ++it; } } }
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(); }
void CRole::Update(float dt) { m_oldPos = m_pos; CMoveableObj::Update(dt); /* m_mapPosX = (int)(m_pos.x/m_pMap->m_tileWidth); m_mapPosY = (int)(m_pos.y/m_pMap->m_tileHeight); if(m_mapPosX < 0 || m_mapPosY < 0 || m_pos.x < 0 || m_pos.y < 0 || m_mapPosX >= m_pMap->m_col || m_mapPosY >= m_pMap->m_row) {//阻止角色离开地图 m_pos = m_oldPos; SetStop(); } if(m_pos==m_dst) { if(m_bSwt) { m_dst = m_fdst; ComputeDir(); m_bSwt = false; } else if(m_bBeginFindPath) { Pos next; if(GetNextPos(&next, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) { m_dst = next; if(next.x != m_pos.x && next.y != m_pos.y)//转折点 { ComputeDir(); m_bBeginFindPath = false; m_bSwt = true;//打开转折开关 ClearPath(); } }else { Stop(); m_bBeginFindPath = false; } }else { Stop(); m_bBeginFindPath = false; } } else { if(!m_pAni[m_dir]->IsPlaying()) { m_pAni[m_dir]->Play(); m_pAni[m_dir]->SetFrame(1); } m_bMoving = true; } if(CollideMap() && !m_bBeginFindPath && m_bMoving && !m_bSwt) { m_bBeginFindPath = true; //m_bSwt = false; m_pos = m_oldPos; int t=timeGetTime(); //计算寻路时间 FindPath(&m_pos, &m_fdst); printf("寻路消耗时间: %d\n",timeGetTime()-t); // if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) ComputeDir(); else { m_bBeginFindPath = false; SetStop(); } }*/ //test if(m_pos==m_dst) { if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) { ComputeDir(); }else { Stop(); m_bBeginFindPath = false; } } else { if(!m_pAni[m_dir]->IsPlaying()) { m_pAni[m_dir]->Play(); m_pAni[m_dir]->SetFrame(1); } m_bMoving = true; } m_rect.x1 = m_pos.x - m_pMap->m_tileWidth/2.f +1; m_rect.y1 = m_pos.y - m_pMap->m_tileHeight/2.f +1; m_rect.x2 = m_pos.x + m_pMap->m_tileWidth/2.f-1; m_rect.y2 = m_pos.y + m_pMap->m_tileHeight/2.f -1; x1 = (int)(m_rect.x1/m_pMap->m_tileWidth); y1 = (int)(m_rect.y1/m_pMap->m_tileHeight); x2 = (int)(m_rect.x2/m_pMap->m_tileWidth); y2 = (int)(m_rect.y1/m_pMap->m_tileHeight); x3 = (int)(m_rect.x1/m_pMap->m_tileWidth); y3 = (int)(m_rect.y2/m_pMap->m_tileHeight); x4 = (int)(m_rect.x2/m_pMap->m_tileWidth); y4 = (int)(m_rect.y2/m_pMap->m_tileHeight); if(IsInMap(x1,y1)) m_mapTile[INDEX(x1,y1)] = false; if(IsInMap(x2,y2)) m_mapTile[INDEX(x2,y2)] = false; if(IsInMap(x3,y3)) m_mapTile[INDEX(x3,y3)] = false; if(IsInMap(x4,y4)) m_mapTile[INDEX(x4,y4)] = false; for(MOBJ_ITR itr = m_mobjs->begin(); itr != m_mobjs->end();itr ++) { hgeRect* rct = (*itr)->GetRect(); if(m_rect.Intersect(rct)) { if((*itr)->GetID() != m_uID) { //m_pos = m_oldPos; //Stop(); //x1 = (int)(m_rect.x1/m_pMap->m_tileWidth); //y1 = (int)(m_rect.y1/m_pMap->m_tileHeight); //x2 = (int)(m_rect.x2/m_pMap->m_tileWidth); //y2 = (int)(m_rect.y1/m_pMap->m_tileHeight); //x3 = (int)(m_rect.x1/m_pMap->m_tileWidth); //y3 = (int)(m_rect.y2/m_pMap->m_tileHeight); //x4 = (int)(m_rect.x2/m_pMap->m_tileWidth); //y4 = (int)(m_rect.y2/m_pMap->m_tileHeight); //if(IsInMap(x1,y1)) // point1 = m_mapTile[INDEX(x1,y1)]; //if(IsInMap(x2,y2)) // point2 = m_mapTile[INDEX(x2,y2)]; //if(IsInMap(x3,y3)) // point3 = m_mapTile[INDEX(x3,y3)]; //if(IsInMap(x4,y4)) // point4 = m_mapTile[INDEX(x4,y4)]; //if(IsInMap(x1,y1)) // m_mapTile[INDEX(x1,y1)] = false; //if(IsInMap(x2,y2)) // m_mapTile[INDEX(x2,y2)] = false; //if(IsInMap(x3,y3)) // m_mapTile[INDEX(x3,y3)] = false; //if(IsInMap(x4,y4)) // m_mapTile[INDEX(x4,y4)] = false; // ////m_bBeginFindPath = true; FindPath(&m_pos, &m_fdst); if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) ComputeDir(); else { //m_bBeginFindPath = false; SetStop(); } //if(IsInMap(x1,y1)) // m_mapTile[INDEX(x1,y1)] = point1; //if(IsInMap(x2,y2)) // m_mapTile[INDEX(x2,y2)] = point2; //if(IsInMap(x3,y3)) // m_mapTile[INDEX(x3,y3)] = point3; //if(IsInMap(x4,y4)) // m_mapTile[INDEX(x4,y4)] = point4; // break; } } } m_pAni[m_dir]->Update(dt); }
bool GameObject::isVisibleForInState(Player const* u, bool inVisibleList) const { return IsInWorld() && u->IsInWorld() && ( IsTransport() && IsInMap(u) || isSpawned() && IsWithinDistInMap(u,World::GetMaxVisibleDistanceForObject()+(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f)) ); }