コード例 #1
0
Tile::Tile(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mExplosion(textures.get(Textures::Explosion))
, mDropPickupCommand()
, mShowExplosion(false)
, mSpawnedPickup(false)
, mPickupsEnabled(true)
{
	mExplosion.setFrameSize(sf::Vector2i(256, 256));
	mExplosion.setNumFrames(16);
	mExplosion.setDuration(sf::seconds(1));

	centerOrigin(mSprite);
	centerOrigin(mExplosion);

	mDropPickupCommand.category = Category::SceneFieldLayer;
	mDropPickupCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
	{
		createPickup(node, textures);
	};


}
コード例 #2
0
Aircraft::Aircraft(Type type, const TextureHolder& textures, const FontHolder& fonts)
: Entity(Table[type].hitpoints)
, mType(type)
, mFireCommand()
, mMissileCommand()
, mFireCountdown(sf::Time::Zero)
, mIsFiring(false)
, mIsLaunchingMissile(false)
, mShowExplosion(true)
, mSpawnedPickup(false)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mExplosion(textures.get(Textures::Explosion))
, mFireRateLevel(1)
, mSpreadLevel(1)
, mMissileAmmo(2)
, mDropPickupCommand()
, mTravelledDistance(0.f)
, mDirectionIndex(0)
, mMissileDisplay(nullptr)
{
	mExplosion.setFrameSize(sf::Vector2i(256, 256));
	mExplosion.setNumFrames(16);
	mExplosion.setDuration(sf::seconds(1));

	centerOrigin(mSprite);
	centerOrigin(mExplosion);

	mFireCommand.category = Category::SceneAirLayer;
	mFireCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
	{
		createBullets(node, textures);
	};

	mMissileCommand.category = Category::SceneAirLayer;
	mMissileCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
	{
		createProjectile(node, Projectile::Missile, 0.f, 0.5f, textures);
	};

	mDropPickupCommand.category = Category::SceneAirLayer;
	mDropPickupCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
	{
		createPickup(node, textures);
	};

	std::unique_ptr<TextNode> healthDisplay(new TextNode(fonts, ""));
	mHealthDisplay = healthDisplay.get();
	attachChild(std::move(healthDisplay));

	if (getCategory() == Category::PlayerAircraft)
	{
		std::unique_ptr<TextNode> missileDisplay(new TextNode(fonts, ""));
		missileDisplay->setPosition(0, 70);
		mMissileDisplay = missileDisplay.get();
		attachChild(std::move(missileDisplay));
	}

	updateTexts();
}
コード例 #3
0
PickupNode::PickupNode(const TextureHolder& textures)
	:spread_sprite(textures.get(Textures::FireSpread), Table[Pickup::FireSpread].texture_rect)
	,rate_sprite(textures.get(Textures::FireRate), Table[Pickup::FireRate].texture_rect)
{
	spread_sprite.setOrigin(spread_sprite.getGlobalBounds().width / 2.f, spread_sprite.getGlobalBounds().width / 2.f);
	rate_sprite.setOrigin(rate_sprite.getGlobalBounds().width / 2.f, rate_sprite.getGlobalBounds().width / 2.f);
	rate_sprite.setPosition(spread_sprite.getPosition().x + 20.f, spread_sprite.getPosition().y);
	spread_sprite.setScale(0.5f, 0.5);
	rate_sprite.setScale(0.5f, 0.5);
}
コード例 #4
0
   Button::Button(const FontHolder& fonts, const TextureHolder& textures)
   : mCallback(),
   mNormalTexture(textures.get(Textures::ButtonNormal)),
   mSelectedTexture(textures.get(Textures::ButtonSelected)),
   mPressedTexture(textures.get(Textures::ButtonPressed)),
   mSprite(),
   mText("", fonts.get(Fonts::Main), 16),
   mIsToggle(false) {

      mSprite.setTexture(mNormalTexture);
      centerOrigin(mSprite);

      mText.setPosition(0, 0);
   }
コード例 #5
0
ファイル: Button.cpp プロジェクト: aaronistheman/Tanks
Button::Button(const FontHolder& fonts, const TextureHolder& textures)
: mCallback()
, mNormalTexture(textures.get(Textures::ButtonNormal))
, mSelectedTexture(textures.get(Textures::ButtonSelected))
, mPressedTexture(textures.get(Textures::ButtonPressed))
, mSprite()
, mText("", fonts.get(Fonts::Main), 16)
, mIsToggle(false)
{
	mSprite.setTexture(mNormalTexture);

	sf::FloatRect bounds = mSprite.getLocalBounds();
	mText.setPosition(bounds.width / 2.f, bounds.height / 2.f);
}
コード例 #6
0
ファイル: Aircraft.cpp プロジェクト: kevin5396/Hellfire
Aircraft::Aircraft(Type type, const TextureHolder& textures, const FontHolder& fonts)
: Entity(Table[type].hitpoints)
, mType(type), mSprite(textures.get(Table[mType].texture), Table[mType].textRect),mHealthDisplay(nullptr)
, mTravelledDistance(0.f), mDirectionIndex(0), mIsFiring(false), mFireCountdown(sf::Time::Zero)
, mFireRateLevel(1), mFireCommand(), mSpreadLevel(1), mIsMarkedForRemoval(false)
, mMissileCommand(), mIsLaunchMissile(false), mMissileAmmo(2), mDropPickupCommand()
{
    if (!isAllied())
        mFireRateLevel = 0;
    centerOrigin(mSprite);
    
    std::unique_ptr<TextNode>   healthDisplay(new TextNode(fonts, ""));
    mHealthDisplay = healthDisplay.get();
    
    attachChild(std::move(healthDisplay));
    
    mFireCommand.category = Category::Scene;
    mFireCommand.action = [this, &textures](SceneNode& node, sf::Time)
    {
        createBullet(node, textures);
    };
    mMissileCommand.category = Category::Scene;
    mMissileCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
    {
        createProjectile(node, Projectile::Missile, 0.f, 0.5f, textures);
    };
    
    mDropPickupCommand.category = Category::Scene;
    mDropPickupCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
    {
        createPickup(node, textures);
    };
}
コード例 #7
0
ファイル: helpnode.cpp プロジェクト: Lo-X/ludumdare31
HelpNode::HelpNode(TextureHolder &textures) :
    SceneNode(Category::None),
    mFakePosition(152.f, -2.f)
{
    mSprite.setTexture(textures.get(Textures::Help));
    mSprite.setPosition(150.f, 55.f);
}
コード例 #8
0
Asteroid::Asteroid(const TextureHolder& textures, b2World& world):
    Entity(createBody(world))
{
    AsteroidGenerator::makeRandomAsteroid(*this);
    m_shape.setTexture(&textures.get(Textures::Asteroid));

    int pointsCount = m_shape.getPointCount();

    b2Vec2 vertices[pointsCount];
    int j = pointsCount - 1;
    for(int i = 0; i < pointsCount; ++i) // CCW
    {
        vertices[j].Set(m_shape.getPoint(i).x / SCALE, m_shape.getPoint(i).y / SCALE);
        j--;
    }

    b2FixtureDef AsteroidFixtureDef;
    b2PolygonShape AsteroidShape;
    AsteroidShape.Set(vertices, pointsCount);
    AsteroidFixtureDef.shape = &AsteroidShape;
    AsteroidFixtureDef.density = 1.0f;
    AsteroidFixtureDef.userData = this;
    m_body->CreateFixture(&AsteroidFixtureDef);

    m_shape.setOrigin(m_body->GetWorldCenter().x, m_body->GetWorldCenter().y);
}
コード例 #9
0
ファイル: Aircraft.cpp プロジェクト: RiordanIX/SFML-Learning
Aircraft::Aircraft(Type type, const TextureHolder& textures)
: m_Type(type)
, m_Sprite(textures.get(toTextureID(type)))
{
	sf::FloatRect bounds = m_Sprite.getLocalBounds();
	m_Sprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
}
コード例 #10
0
Projectile::Projectile(Type type, const TextureHolder& textures) 
	: Entity(1) //1 HP - so it's not detected as destroyed and not drawn
	, type(type)
	, sprite(textures.get(Table[type].texture))
{
	centerOrigin(sprite);
}
コード例 #11
0
ファイル: Pickup.cpp プロジェクト: danielsega/Defender
Pickup::Pickup(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
{
	centerOrigin(mSprite);
}
コード例 #12
0
ファイル: Person.cpp プロジェクト: lberezy/GameTest
Person::Person(Type type, const TextureHolder& textures)
: mType(type)
, mSprite(textures.get(toTextureID(type)))
{
    sf::FloatRect bounds = mSprite.getLocalBounds();
    mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
}
コード例 #13
0
ParticleNode::ParticleNode(Particle::Type type, const TextureHolder& textures)
	: mParticles()
	, mTexture(textures.get(Textures::Particle))
	, mType(type)
	, mVertexArray(sf::Quads)
	, mNeedsVertexUpdate(true)
{
}
コード例 #14
0
ファイル: Projectile.cpp プロジェクト: grnnn/CS146-Project2
Projectile::Projectile(const TextureHolder& textures)
: mType(AlliedBullet)
{
    sf::Sprite spr(textures.get(Textures::Projectile));
    centerOrigin(spr);
    setSprite(spr);
    setID(1);
}
コード例 #15
0
ファイル: Projectile.cpp プロジェクト: lolobster/LobsterBall
Projectile::Projectile(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mTargetDirection()
{
	centerOrigin(mSprite);
}
コード例 #16
0
void Player::loadTexture(const TextureHolder& textures)
{
	mAnimation.setTexture(textures.get(Textures::Player));

	setOrigin(0,mSpriteSize.y);


}
コード例 #17
0
ファイル: Paddle.cpp プロジェクト: devilswin/PongGit
Paddle::Paddle(const TextureHolder& textures, const bool isPlayer) 
        :   mPlayer(isPlayer)
         , mSprite(textures.get(Textures::Paddle))
      
        
{
        centerOrigin(mSprite);
        
}
コード例 #18
0
ファイル: particlenode.cpp プロジェクト: Lo-X/ludumdare31
ParticleNode::ParticleNode(Particle::Type type, const TextureHolder &textures) :
    SceneNode(Category::ParticleSystem),
    mParticles(),
    mAffectors(),
    mTexture(textures.get(Textures::Particle)),
    mType(type),
    mVertexArray(sf::Quads),
    mNeedsVertexUpdate(false)
{
}
コード例 #19
0
//The constructor for the game class.
Game::Game()
	: mWindow(sf::VideoMode(1366, 768), "Top Down Shooter")
	, mTexture()
	, mPlayer()
{
	TextureHolder textures;
	textures.load(Textures::Airplane, "res/sprite.png");

	mPlayer.setTexture(textures.get(Textures::Airplane));
	mPlayer.setPosition(100, 100);
}
コード例 #20
0
ファイル: Aircraft.cpp プロジェクト: vsrz/sfml-tutorial
Aircraft::Aircraft(Type type, const TextureHolder& textures) 
	: mType(type)
	, mSprite(textures.get(toTextureID(type)))
{
	if (type == Textures::Eagle)
	{
		mSprite.setScale(0.2f, 0.2f);
	}
	// Align the origin for this object
	sf::FloatRect bounds = mSprite.getLocalBounds();
	mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);

}
コード例 #21
0
ファイル: Button.cpp プロジェクト: jimmybeer/TAGEngine
 Button::Button(const TextureHolder& textures)
 : mCallback()
 , mSprite(textures.get(TagDefaults::Textures::Buttons))
 , mText("", getGUISettings().fonts->get(getGUISettings().buttonFont), 16)
 , mIsToggle(false)
 {
     mButtonWidth = mSprite.getTexture()->getSize().x;
     mButtonHeight = (mSprite.getTexture()->getSize().y/3);
     
     changeTexture(Normal);
     
     sf::FloatRect bounds = mSprite.getLocalBounds();
     mText.setPosition(bounds.width / 2.f, bounds.height / 2.f);
 }
コード例 #22
0
ファイル: Planet.cpp プロジェクト: AlexDontsov2008/spacecrash
Planet::Planet(Planet::Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texutre))
, mSattelites()
, mTextures(textures)
, mIsMarkedForRemoval(false)
, mDirectionIndex(0)
{
	centerOrigin(mSprite);
	
	if (mType == Earth || mType == Pluton)
		initialSattelites();
}
コード例 #23
0
ファイル: PlayerGoal.cpp プロジェクト: lolobster/LobsterBall
PlayerGoal::PlayerGoal(Type type, const TextureHolder& textures, const FontHolder& fonts)
	: Entity(Table[type].hitpoints)
	, mType(type)
	, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
	, mExplosion(textures.get(Textures::Explosion))
	, mShowExplosion(false)
	, mExplosionBegan(false)
	, mDirectionIndex(0)
	, mIdentifier(0)
{
	mExplosion.setFrameSize(sf::Vector2i(256, 256));
	mExplosion.setNumFrames(16);
	mExplosion.setDuration(sf::seconds(1));

	centerOrigin(mSprite);
	centerOrigin(mExplosion);

	std::unique_ptr<TextNode> healthDisplay(new TextNode(fonts, ""));
	mHealthDisplay = healthDisplay.get();
	attachChild(std::move(healthDisplay));

	updateTexts();
}
コード例 #24
0
ファイル: Button.cpp プロジェクト: eggtart93/LuckyDraw
    Button::Button(ButtonStyle style, const FontHolder& fonts, const TextureHolder& textures)
    : mStyle(style),
      mFonts(fonts),
      mTextures(textures),
      mIsFocusable(true),
      mIsFixedSize(true),
      mCallback(),
      p_mShape(nullptr),
      p_mSprite(nullptr),
      p_mText(nullptr),
      mColor(COLOR_ON_RELEASED),
      mTextColor(TEXT_COLOR_DEFAULT),
      mScale(1.f, 1.f),
      mState(State::OnReleased)
    {
        if (mStyle == Button::Sprite)
        {
            std::unique_ptr<sf::Sprite> p_sprite(new sf::Sprite());
            p_sprite->setTexture(textures.get(Textures::Button));
            Graphics::centerOrigin(*p_sprite);
            p_mSprite = std::move(p_sprite);
            setText("");
        }
        else
        {
            std::unique_ptr<sf::RectangleShape> p_rect(
                new sf::RectangleShape(sf::Vector2f(BUTTON_WIDTH, BUTTON_HEIGHT)));
            Graphics::centerOrigin(*p_rect);
            p_mShape = std::move(p_rect);

            if (mStyle == ButtonStyle::Text)
            {
                std::unique_ptr<sf::Text> p_text(new sf::Text());
                p_text->setFont(fonts.get(Fonts::Chinese));
                //p_text->setCharacterSize(30);
                p_text->setColor(mTextColor);
                p_text->setString("Button");
                Graphics::centerOrigin(*p_text);
                
                p_mShape->setFillColor(TEXT_BG_COLOR_RELEASED);
                p_mShape->setOutlineThickness(OUT_LINE_THICKNESS);
                p_mShape->setOutlineColor(mTextColor);

                p_mText = std::move(p_text);
            }

            setText("");
        }
    }
コード例 #25
0
ファイル: Character.cpp プロジェクト: gabrieljt/SFML-Minimal
Character::Character(Type type, const TextureHolder& textures, const FontHolder& fonts)
: Entity(Table[type].hitpoints)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mTravelledDistance(0.f)
, mDirectionIndex(0)
, mHealthDisplay(nullptr)
{
	centerOrigin(mSprite);

	std::unique_ptr<TextNode> healthDisplay(new TextNode(fonts, ""));
	mHealthDisplay = healthDisplay.get();
	attachChild(std::move(healthDisplay));

	updateTexts();
}
コード例 #26
0
ファイル: platform.cpp プロジェクト: Lo-X/ld32
Platform::Platform(Platform::Type type, TextureHolder& textures) : Entity(1)
{
    mSprite.setTexture(textures.get(Textures::Platforms));

    switch(type)
    {
        case Small:
            mSprite.setTextureRect(sf::IntRect(0,0,174,45));
            break;

        case Medium:
            mSprite.setTextureRect(sf::IntRect(0,45,376,45));
            break;

        case Ground:
            mSprite.setTextureRect(sf::IntRect(0,90,1280,45));
    }
}
コード例 #27
0
Projectile::Projectile(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mTargetDirection()
{
	centerOrigin(mSprite);
    
    // Add particle system for missiles
    if (isGuided())
    {
        std::unique_ptr<EmitterNode> smoke(new EmitterNode(Particle::Smoke));
        smoke->setPosition(0.f, getBoundingRect().height / 2.f);
        attachChild(std::move(smoke));
        
        std::unique_ptr<EmitterNode> propellant(new EmitterNode(Particle::Propellant));
        propellant->setPosition(0.f, getBoundingRect().height / 2.f);
        attachChild(std::move(propellant));
        
    }
}
コード例 #28
0
ファイル: Ship.cpp プロジェクト: Tompsa/asteroidit
Ship::Ship(Type type, const TextureHolder& textures)
	: Entity(Table[type].hitpoints)
	, _type(type)
	, _sprite(textures.get(Table[type].texture))
    , _fireCommand()
    , _fireCountdown(sf::Time::Zero)
    , _isFiring(false)
    , _isMarkedForRemoval(false)
    , _travelledDistance(0.f)
    , _directionIndex(0)
    , _invisTimer()
    , _godmode(0)
{
	centerOrigin(_sprite);
    
    _fireCommand.category = Category::Scene;
	_fireCommand.action   = [this, &textures] (SceneNode& node, sf::Time)
	{
		createBullets(node, textures);
	};
}
コード例 #29
0
ファイル: creature.cpp プロジェクト: Lo-X/hammer
Creature::Creature(TextureHolder &textures, FontHolder& fonts, Type type, AIController& ctrl) :
    Entity(textures, type),
    mFonts(fonts),
    mAIController(ctrl),
    mEmitter(nullptr),
    mDestroyedSince(sf::Time::Zero)
{
    mSprite.setOrigin(sf::Vector2f(16.f, 32.f));

    mKnockedAnimation.setTexture(textures.get(Textures::Knocked));
    mKnockedAnimation.setFrameSize(sf::Vector2i(32,32));
    mKnockedAnimation.setNumFrames(4);
    mKnockedAnimation.setDuration(sf::seconds(0.5f));
    mKnockedAnimation.setRepeating(true);
    mKnockedAnimation.setOrigin(sf::Vector2f(16.f, 32.f));

    switch(type)
    {
        case Rabbit:
        {
            sf::Vector2f scale = sf::Vector2f(2.f, 2.f);
            textures.get(Textures::RabbitLeft).setSmooth(false);
            mKnockedAnimation.setPosition(sf::Vector2f(0, -32.f*(scale.y+0.5f)));
            mSprite.setTexture(textures.get(Textures::RabbitLeft));
            mSprite.setTextureRect(sf::IntRect(0,0,32,32));
            mSprite.setScale(scale);
            mAnimations[Left].setTexture(textures.get(Textures::RabbitLeft));
            mAnimations[Left].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Left].setNumFrames(4);
            mAnimations[Left].setDuration(sf::seconds(0.7f));
            mAnimations[Left].setRepeating(true);
            mAnimations[Left].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Left].setScale(scale);

            textures.get(Textures::RabbitRight).setSmooth(false);
            mAnimations[Right].setTexture(textures.get(Textures::RabbitRight));
            mAnimations[Right].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Right].setNumFrames(4);
            mAnimations[Right].setDuration(sf::seconds(0.7f));
            mAnimations[Right].setRepeating(true);
            mAnimations[Right].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Right].setScale(scale);
            break;
        }

        case Tentacle:
        {
            sf::Vector2f scale = sf::Vector2f(2.f, 2.f);
            textures.get(Textures::TentacleLeft).setSmooth(false);
            mKnockedAnimation.setPosition(sf::Vector2f(0, -32.f*(scale.y+0.5f)));
            mSprite.setTexture(textures.get(Textures::TentacleLeft));
            mSprite.setTextureRect(sf::IntRect(0,0,32,32));
            mSprite.setScale(scale);
            mAnimations[Left].setTexture(textures.get(Textures::TentacleLeft));
            mAnimations[Left].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Left].setNumFrames(3);
            mAnimations[Left].setDuration(sf::seconds(0.7f));
            mAnimations[Left].setRepeating(true);
            mAnimations[Left].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Left].setScale(scale);

            textures.get(Textures::TentacleRight).setSmooth(false);
            mAnimations[Right].setTexture(textures.get(Textures::TentacleRight));
            mAnimations[Right].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Right].setNumFrames(3);
            mAnimations[Right].setDuration(sf::seconds(0.7f));
            mAnimations[Right].setRepeating(true);
            mAnimations[Right].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Right].setScale(scale);
            break;
        }

        case Crawler:
        {
            sf::Vector2f scale = sf::Vector2f(4.f, 4.f);
            textures.get(Textures::CrawlerLeft).setSmooth(false);
            mKnockedAnimation.setPosition(sf::Vector2f(0, -32.f*(scale.y+0.5f)));
            mSprite.setTexture(textures.get(Textures::CrawlerLeft));
            mSprite.setTextureRect(sf::IntRect(0,0,32,32));
            mSprite.setScale(scale);
            mAnimations[Left].setTexture(textures.get(Textures::CrawlerLeft));
            mAnimations[Left].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Left].setNumFrames(4);
            mAnimations[Left].setDuration(sf::seconds(0.7f));
            mAnimations[Left].setRepeating(true);
            mAnimations[Left].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Left].setScale(scale);

            textures.get(Textures::CrawlerRight).setSmooth(false);
            mAnimations[Right].setTexture(textures.get(Textures::CrawlerRight));
            mAnimations[Right].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Right].setNumFrames(4);
            mAnimations[Right].setDuration(sf::seconds(0.7f));
            mAnimations[Right].setRepeating(true);
            mAnimations[Right].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Right].setScale(scale);
            break;
        }

        case Boss1:
        case Boss3:
        {
            sf::Vector2f scale = sf::Vector2f(10.f, 10.f);
            textures.get(Textures::CrawlerLeft).setSmooth(false);
            mKnockedAnimation.setPosition(sf::Vector2f(0, -32.f*(scale.y+0.5f)));
            mSprite.setTexture(textures.get(Textures::CrawlerLeft));
            mSprite.setTextureRect(sf::IntRect(0,0,32,32));
            mSprite.setScale(scale);
            mAnimations[Left].setTexture(textures.get(Textures::CrawlerLeft));
            mAnimations[Left].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Left].setNumFrames(4);
            mAnimations[Left].setDuration(sf::seconds(0.7f));
            mAnimations[Left].setRepeating(true);
            mAnimations[Left].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Left].setScale(scale);

            textures.get(Textures::CrawlerRight).setSmooth(false);
            mAnimations[Right].setTexture(textures.get(Textures::CrawlerRight));
            mAnimations[Right].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Right].setNumFrames(4);
            mAnimations[Right].setDuration(sf::seconds(0.7f));
            mAnimations[Right].setRepeating(true);
            mAnimations[Right].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Right].setScale(scale);
            break;
        }

        case Boss2:
        {
            sf::Vector2f scale = sf::Vector2f(10.f, 10.f);
            textures.get(Textures::TentacleLeft).setSmooth(false);
            mKnockedAnimation.setPosition(sf::Vector2f(0, -32.f*(scale.y+0.5f)));
            mSprite.setTexture(textures.get(Textures::TentacleLeft));
            mSprite.setTextureRect(sf::IntRect(0,0,32,32));
            mSprite.setScale(scale);
            mAnimations[Left].setTexture(textures.get(Textures::TentacleLeft));
            mAnimations[Left].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Left].setNumFrames(3);
            mAnimations[Left].setDuration(sf::seconds(0.7f));
            mAnimations[Left].setRepeating(true);
            mAnimations[Left].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Left].setScale(scale);

            textures.get(Textures::TentacleRight).setSmooth(false);
            mAnimations[Right].setTexture(textures.get(Textures::TentacleRight));
            mAnimations[Right].setFrameSize(sf::Vector2i(32,32));
            mAnimations[Right].setNumFrames(3);
            mAnimations[Right].setDuration(sf::seconds(0.7f));
            mAnimations[Right].setRepeating(true);
            mAnimations[Right].setOrigin(sf::Vector2f(16.f, 32.f));
            mAnimations[Right].setScale(scale);
            break;
        }

        default:break;
    }
}
コード例 #30
0
Item::Item(Type type, const TextureHolder& textures)
	: mType(type)
	, mBehavors(None)
	, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
	, mFootSenseCount()
	, mIsMarkedForRemoval(false)
	, mElapsedTime(sf::Time::Zero)
	, mCollisionDispatcher()
	, mCollision()
	, mBehaversCollision()
	, mUpdateDispatcher()
	, mUpdater()
{
	using namespace std::placeholders;

	switch (mType)
	{
	case Type::StaticCoin:
		mCollision = std::bind(&Item::collisions, this, _1, _2);
		mBehaversCollision.insert({
			{ Category::BigPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
			{ Category::SmallPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
		});
		break;
	case Type::MoveableCoin:
		mUpdater = std::bind(&Item::moveableCoinUpdate, this, _1);

		break;
	case Type::Mushroom:
	{
		mUpdater = std::bind(&Item::behaversUpdate, this, _1);
		mUpdateDispatcher.emplace_back(Behavors::None, std::bind(&Item::mushroomNoneUpdate, this, _1));
		mUpdateDispatcher.emplace_back(Behavors::Air, std::bind(&Item::airUpdate, this, _1));
		mUpdateDispatcher.emplace_back(Behavors::Ground, std::bind(&Item::mushroomGroundUpdate, this, _1));
		if (mUpdateDispatcher.capacity() > mUpdateDispatcher.size())
		{
			mUpdateDispatcher.shrink_to_fit();
		}
		mCollision = std::bind(&Item::resolveMushroom, this, _1, _2);
		Dispatcher airCollision({
			// Tiles
			{ Category::Brick, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			{ Category::Block, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			{ Category::TransformBox, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			{ Category::CoinsBox, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			{ Category::SoloCoinBox, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			{ Category::SolidBox, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			// Enemies
			{ Category::Goomba, std::bind(&Item::airMushroomObjectsCollision, this, _1, _2) },
			// Player
			{ Category::BigPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
			{ Category::SmallPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
		});

		Dispatcher groundCollision({
			// Tiles
			{ Category::Brick, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			{ Category::Block, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			{ Category::TransformBox, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			{ Category::CoinsBox, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			{ Category::SoloCoinBox, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			{ Category::SolidBox, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			// Enemies
			{ Category::Goomba, std::bind(&Item::groundMushroomObjectsCollision, this, _1, _2) },
			// Player
			{ Category::BigPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
			{ Category::SmallPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
		});

		mCollisionDispatcher.emplace_back(Behavors::Air, airCollision);
		mCollisionDispatcher.emplace_back(Behavors::Ground, groundCollision);
		if (mCollisionDispatcher.capacity() > mCollisionDispatcher.size())
		{
			mCollisionDispatcher.shrink_to_fit();
		}
	}
		break;
	case Type::Flower:
		mUpdater = std::bind(&Item::flowerUpdate, this, _1);
		mCollision = std::bind(&Item::collisions, this, _1, _2);
		mBehaversCollision.insert({
			{ Category::BigPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
			{ Category::SmallPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
		});
		break;
	case Type::Star:
	{
		mUpdater = std::bind(&Item::behaversUpdate, this, _1);
		mUpdateDispatcher.emplace_back(Behavors::None, std::bind(&Item::starNoneUpdate, this, _1));
		mUpdateDispatcher.emplace_back(Behavors::Air, std::bind(&Item::airUpdate, this, _1));
		if (mUpdateDispatcher.capacity() > mUpdateDispatcher.size())
		{
			mUpdateDispatcher.shrink_to_fit();
		}
		mCollision = std::bind(&Item::collisions, this, _1, _2);
		mBehaversCollision.insert({
			// Tiles
			{ Category::Brick, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			{ Category::Block, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			{ Category::TransformBox, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			{ Category::CoinsBox, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			{ Category::SoloCoinBox, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			{ Category::SolidBox, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			// Enemies
			{ Category::Goomba, std::bind(&Item::starObjectsCollision, this, _1, _2) },
			// Player
			{ Category::BigPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
			{ Category::SmallPlayer, std::bind(&Item::playerCollision, this, _1, _2) },
		});
	}
	break;
	default: break;
	}

	auto bounds = mSprite.getLocalBounds();
	mSprite.setOrigin(bounds.width / 2.f, bounds.height / 2.f);

	mFootShape.setFillColor(sf::Color::Transparent);
	mFootShape.setOutlineColor(sf::Color::White);
	mFootShape.setSize({ bounds.width, 2.f });

	mFootShape.setPosition(0.f, bounds.height / 2.f);
	mFootShape.setOutlineThickness(-0.5f);
	bounds = mFootShape.getLocalBounds();
	mFootShape.setOrigin(bounds.width / 2.f, bounds.height / 2.f);
}