Loading entities from the map file

If you recall from the section of this chapter that dealt with the issue of creating a map class, we haven't finished implementing the loading method fully, because we had no entities yet. With that no longer being the case, let's take a look at extending it:

} else if(type == "PLAYER"){ if (playerId != -1){ continue; } // Set up the player position here. playerId = entityMgr->Add(EntityType::Player); if (playerId < 0){ continue; } float playerX = 0; float playerY = 0; keystream >> playerX >> playerY; entityMgr->Find(playerId)->SetPosition(playerX,playerY); m_playerStart = sf::Vector2f(playerX, playerY); } else if(type == "ENEMY"){ std::string enemyName; keystream >> enemyName; int enemyId = entityMgr->Add(EntityType::Enemy, ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.