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 ); }