void World::Kill() { List<Entity*>::const_iterator itEntity; for(itEntity = mEntities.begin(); itEntity != mEntities.end(); itEntity = mEntities.begin()) { Entity* entity = (*itEntity); RemoveEntity(entity); if( entity->GetOwner() == this ) { entity->Kill(); GD_DELETE(entity); } } mWorldInitialized = false; }
bool Engine::Tick() { if(m_window->isOpen()) { sf::Event event; while (m_window->pollEvent(event)) { // if (event.type == sf::Event::Closed) { m_window->close(); } } } else { m_isRunning = false; } // inputs float pos_x, pos_y; size_t block_x, block_y, next_x, next_y = 0; Player* player = GetLocalPlayer(); player->GetPosition(pos_x, pos_y); m_world->GetPixelToBlock(pos_x, pos_y, block_x, block_y); if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { m_world->GetLeftBlock(block_x, block_y, next_x, next_y); if(m_world->IsBlockWalkable(next_x, next_y) && IsEntityWalkable(next_x, next_y)) { m_world->GetBlockToPixel(next_x, next_y, pos_x, pos_y); player->SetTarget(pos_x, pos_y); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { m_world->GetRightBlock(block_x, block_y, next_x, next_y); if(m_world->IsBlockWalkable(next_x, next_y) && IsEntityWalkable(next_x, next_y)) { m_world->GetBlockToPixel(next_x, next_y, pos_x, pos_y); player->SetTarget(pos_x, pos_y); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { m_world->GetUpBlock(block_x, block_y, next_x, next_y); if(m_world->IsBlockWalkable(next_x, next_y) && IsEntityWalkable(next_x, next_y)) { m_world->GetBlockToPixel(next_x, next_y, pos_x, pos_y); player->SetTarget(pos_x, pos_y); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { m_world->GetDownBlock(block_x, block_y, next_x, next_y); if(m_world->IsBlockWalkable(next_x, next_y) && IsEntityWalkable(next_x, next_y)) { m_world->GetBlockToPixel(next_x, next_y, pos_x, pos_y); player->SetTarget(pos_x, pos_y); } } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { // shoot player->SpawnBomb(); } // game loop m_world->Tick(); for(size_t i = 0; i < m_players.size(); ++i) { Player* player = m_players[i]; player->Tick(); } for(entities_t::iterator it = m_entities.begin(); it != m_entities.end(); ++it) { Entity* entity = (*it); entity->Tick(); } // loop for destroy entities_t::iterator it_loop = m_entities.begin(); while(it_loop != m_entities.end()) { Entity* entity = (*it_loop); if(entity->CanDestroy()) { Player* owner = entity->GetOwner(); if(owner) { owner->DecBomb(); } entity->Term(); delete entity; it_loop = m_entities.erase(it_loop); } else { ++it_loop; } } // draw Draw(); return m_isRunning; }