void World::buildScene() { for ( std::size_t i=0; i<LayerCount; i++ ) { // TODO: replace it with more readable construct Category::Type category = (i == LowerAir) ? Category::SceneAirLayer : Category::None; SceneNode::Ptr layer( new SceneNode( category ) ); mSceneLayers[i] = layer.get(); mSceneGraph.AttachChild( std::move( layer ) ); } // Prepare the tiled background // Wrap up it into a private method later sf::Texture& jungleTexture = mTextures.get( Textures::Jungle ); jungleTexture.setRepeated( true ); float viewHeight = mWorldView.getSize().y; sf::IntRect textureRect( mWorldBounds ); textureRect.height += static_cast<int>( viewHeight ); // Add the background sprite to the scene std::unique_ptr<SpriteNode> jungleSprite( new SpriteNode( jungleTexture, textureRect ) ); jungleSprite->setPosition( mWorldBounds.left, mWorldBounds.top ); mSceneLayers[Background]->AttachChild( std::move( jungleSprite ) ); // Add the finsh line to the scene sf::Texture& finishTexture = mTextures.get( Textures::FinishLine ); std::unique_ptr<SpriteNode> finishSprite( new SpriteNode( finishTexture ) ); finishSprite->setPosition( 0.0f, -76.0f ); mFinishSprite = finishSprite.get(); mSceneLayers[Background]->AttachChild( std::move( finishSprite ) ); // Add particle node to the scene std::unique_ptr<ParticleNode> smokeNode( new ParticleNode( Particle::Smoke, mTextures ) ); mSceneLayers[LowerAir]->AttachChild( std::move( smokeNode ) ); // Add propellant particle node to scene std::unique_ptr<ParticleNode> propellantNode( new ParticleNode( Particle::Propellant, mTextures ) ); mSceneLayers[LowerAir]->AttachChild( std::move( propellantNode ) ); // Add sound effect node std::unique_ptr<SoundNode> soundNode( new SoundNode( mSounds ) ); mSceneGraph.AttachChild( std::move( soundNode ) ); // Add network node, if necessary if ( mNetworkedWorld ) { std::unique_ptr<NetworkNode> networkNode( new NetworkNode() ); mNetworkNode = networkNode.get(); mSceneGraph.AttachChild( std::move( networkNode ) ); } addEnemies(); }
void World::Impl::BuildScene() { for ( std::size_t i = 0; i < LayerCount; ++i ) { Category::Type category = ( i == LowerAir ) ? Category::SceneAirLayer : Category::None; SceneNode::SceneNodePtr layer( new SceneNode( category ) ); mSceneLayers[ i ] = layer.get(); mSceneGraph.AttachChild( std::move( layer ) ); } sf::Texture & texture = mTextures.Get( Texture::Jungle ); texture.setRepeated( true ); float viewHeight = mWorldView.getSize().y; sf::IntRect textureRect( mWorldBounds ); textureRect.height += static_cast<int>( viewHeight ); std::unique_ptr< SpriteNode > backgroundSprite( new SpriteNode( texture, textureRect ) ); backgroundSprite->setPosition( mWorldBounds.left, mWorldBounds.top - viewHeight ); mSceneLayers[ Background ]->AttachChild( std::move( backgroundSprite ) ); // Add particle node to the scene std::unique_ptr<ParticleNode> smokeNode( new ParticleNode( Particle::Type::Smoke, mTextures ) ); mSceneLayers[ LowerAir ]->AttachChild( std::move( smokeNode ) ); // Add propellant particle node to the scene std::unique_ptr<ParticleNode> propellantNode( new ParticleNode( Particle::Type::Propellant, mTextures ) ); mSceneLayers[ LowerAir ]->AttachChild( std::move( propellantNode ) ); // Add sound effect node std::unique_ptr< SoundNode > soundNode( new SoundNode( mSounds ) ); mSceneGraph.AttachChild( std::move( soundNode ) ); // Add network node, if necessary if ( mNetworkedWorld ) { std::unique_ptr<NetworkNode> networkNode( new NetworkNode() ); mNetworkNode = networkNode.get(); mSceneGraph.AttachChild( std::move( networkNode ) ); } b2BodyDef BodyDef; BodyDef.position = b2Vec2( 100.f / 2 / PhysicsNode::Scale, 16.f / 2 / PhysicsNode::Scale ); BodyDef.type = b2_staticBody; b2Body* Body = mPhysics.CreateBody( &BodyDef ); b2PolygonShape Shape; Shape.SetAsBox( ( 100.f / 2 ) / PhysicsNode::Scale, ( 16.f / 2 ) / PhysicsNode::Scale ); b2FixtureDef FixtureDef; FixtureDef.density = 0.f; FixtureDef.shape = &Shape; Body->CreateFixture( &FixtureDef ); }
void World::buildScene() { // Initialize the different layers for (std::size_t i = 0; i < LayerCount; ++i) { Category::Type category = (i == LowerAir) ? Category::SceneAirLayer : Category::None; SceneNode::Ptr layer(new SceneNode(category)); mSceneLayers[i] = layer.get(); mSceneGraph.attachChild(std::move(layer)); } // Prepare the tiled background sf::Texture& jungleTexture = mTextures.get(Textures::Jungle); jungleTexture.setRepeated(true); float viewHeight = mWorldView.getSize().y; sf::IntRect textureRect(mWorldBounds); textureRect.height += static_cast<int>(viewHeight); // Add the background sprite to the scene std::unique_ptr<SpriteNode> jungleSprite(new SpriteNode(jungleTexture, textureRect)); jungleSprite->setPosition(mWorldBounds.left, mWorldBounds.top - viewHeight); mSceneLayers[Background]->attachChild(std::move(jungleSprite)); // Add the finish line to the scene sf::Texture& finishTexture = mTextures.get(Textures::FinishLine); std::unique_ptr<SpriteNode> finishSprite(new SpriteNode(finishTexture)); finishSprite->setPosition(0.f, -76.f); mSceneLayers[Background]->attachChild(std::move(finishSprite)); // Add particle node to the scene std::unique_ptr<ParticleNode> smokeNode(new ParticleNode(Particle::Smoke, mTextures)); mSceneLayers[LowerAir]->attachChild(std::move(smokeNode)); // Add propellant particle node to the scene std::unique_ptr<ParticleNode> propellantNode(new ParticleNode(Particle::Propellant, mTextures)); mSceneLayers[LowerAir]->attachChild(std::move(propellantNode)); // Add sound effect node std::unique_ptr<SoundNode> soundNode(new SoundNode(mSounds)); mSceneGraph.attachChild(std::move(soundNode)); // Add player's aircraft std::unique_ptr<Aircraft> player(new Aircraft(Aircraft::Eagle, mTextures, mFonts)); mPlayerAircraft = player.get(); mPlayerAircraft->setPosition(mSpawnPosition); mSceneLayers[UpperAir]->attachChild(std::move(player)); // Add enemy aircraft addEnemies(); }
void World::buildScene(const std::string& level) { // Init layers for(std::size_t i = 0; i < LayerCount; ++i) { Category::Type category = (i == Foreground) ? Category::UpperScene : Category::None; SceneNode::Ptr layer(new SceneNode(category)); m_sceneLayers[i] = layer.get(); m_sceneGraph.attachChild(std::move(layer)); } // SoundNode std::unique_ptr<SoundNode> soundNode(new SoundNode(m_sounds)); m_sceneGraph.attachChild(std::move(soundNode)); // TODO créer une class Level et gérer lesniveaux comme des ressources ml.Load(level); const std::vector<tmx::MapLayer>& layers = ml.GetLayers(); for (const auto& l : layers) { if (l.name == "Static") //static bodies which make up the map geometry createGeometry(l); if (l.name == "Turrets") createTurrets(l); if (l.name == "End") { for (const auto& o : l.objects) { std::cout << "Creating end zone" << std::endl; std::unique_ptr<EndZone> endzone(new EndZone(m_textures, m_fonts, o.GetAABB().width, o.GetAABB().height, tmx::BodyCreator::Add(o, m_physicWorld))); endzone->setPosition(o.GetCentre()); m_sceneLayers[Layer::Background]->attachChild(std::move(endzone)); } } if (l.name == "Spawn") { for (const auto& o : l.objects) { std::cout << "Creating player" << std::endl; std::unique_ptr<Actor> player(new Actor(Actor::Hero, m_textures, m_fonts, m_physicWorld)); m_player = player.get(); player->setPosition(o.GetCentre()); m_sceneLayers[Layer::PlayerLayer]->attachChild(std::move(player)); } } } }