/** * Auf Kollisionen untersuchen: Hat die uebergebene Figur dieselbe * Koordinate wie Pacman? Dann wird bei dieser Figur die * Kollisionsbehandlung ausgeloest und Pacman uebergeben. * @param figure Zu untersuchende Figur. */ void GameController::handleCollisionWithPacman(Figure* figure) { // Wurde eine andere Figur als Pacman bewegt? if (figure != pacman) { if (pacman->isCollisionWith(figure)) { figure->handleCollisionWith(pacman); } } // Pacman wurde bewegt. else { for (std::vector<Figure*>::iterator iter = this->figures.begin(); iter != this->figures.end(); ++iter ) { Figure* figure = (*iter); if ((figure != pacman) && figure->getState() == Alive) { handleCollisionWithPacman(figure); } } } }
//------------------------------------------------------------------------------------------ //-- void TileManager::refresh() { for (unsigned int y = 1; y < board_size.y; ++y) { //------------------------------ //-- проверям вся линия занята unsigned int busy_tiles = 0; for (unsigned int x = 1; x < board_size.x - 1; ++x) { unsigned int tile_index = (y * board_size.x) + x; const Tile &tile = tile_objects[tile_index]; if (tile.state == TS_BUSY) { Figure *figure = FigureManager::getSingleton()->getFigure(tile.object_id); if (figure && figure->getState() == Figure::FS_WAIT) { ++busy_tiles; } } } //------------------------------ //-- срезаем линию if (busy_tiles == board_size.x - 2) { scores += board_size.x; //------------------------------------------------ //-- сначала проходимся по фигурам которые срезаем //-- и выставляем позиции для срезаных блоков for (unsigned int x = 1; x < board_size.x - 1; ++x) { unsigned int tile_index = (y * board_size.x) + x; const Tile &tile = tile_objects[tile_index]; if (tile.state == TS_BUSY && tile.block_index != 0xFFFFFFFF) { FigureManager::getSingleton()->eraseFigureBlock(tile.block_index, tile.object_id); } } //------------------------------------------------ //-- теперь делаем тайлы пустыми и опускаем все //-- что выше Y на тайл ниже clearAllTiles(); for (unsigned int x = 1; x < board_size.x - 1; ++x) { for (unsigned int new_y = y; new_y < board_size.y; ++new_y) { unsigned int tile_index = (new_y * board_size.x) + x; const Tile &tile = tile_objects[tile_index]; FigureManager::getSingleton()->moveDownFigure(tile.position); } } FigureManager::getSingleton()->rebuildAllFigures(); } } }
/** * Zeitablauf: Alle Figuren bewegen. */ void GameController::nextTick() { if(this->state == Starting) { this->ticks--; if(this->ticks == 0) this->setState(Playing); } else if(this->state == LevelOver) { this->ticks--; if(this->ticks == 0) { if(this->field->nextLevel()) { this->setState(Starting); } else { this->setState(GameOver); } } } else if(this->state == Playing) { if (ghostStateHarmless) { if (--ghostHarmlessTicks <= 0) { ghostStateHarmless = false; } } for (std::vector<Figure*>::iterator iter = this->figures.begin(); iter != this->figures.end(); ++iter ) { // Die Figur darf noch nicht tot sein. Figure* figure = *iter; if (figure->getState() != Dead) { figure->nextTick(); handleCollisionWithPacman(figure); } } if(this->foodCount == 0) { this->setState(LevelOver); } if(pacman->getState() == Dead) { if(--this->lives == 0) { this->state = GameOver; } else { for (std::vector<Figure*>::iterator iter = this->figures.begin(); iter != this->figures.end(); ++iter ) { // Die Figur darf noch nicht tot sein. Figure* figure = *iter; if (figure->getState() != Dead) { figure->reset(); } } pacman->reset(); this->setState(Starting); } } } }