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


}
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();
}
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);
}
//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);
}
Beispiel #5
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);
   }
Beispiel #6
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);

	sf::FloatRect bounds = mSprite.getLocalBounds();
	mText.setPosition(bounds.width / 2.f, bounds.height / 2.f);
}
Beispiel #7
0
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);
}
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);
}
Beispiel #9
0
Pickup::Pickup(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
{
	centerOrigin(mSprite);
}
Beispiel #10
0
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);
}
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);
}
Beispiel #12
0
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);
    };
}
Beispiel #13
0
HelpNode::HelpNode(TextureHolder &textures) :
    SceneNode(Category::None),
    mFakePosition(152.f, -2.f)
{
    mSprite.setTexture(textures.get(Textures::Help));
    mSprite.setPosition(150.f, 55.f);
}
Beispiel #14
0
DeleteItem::DeleteItem(TextureHolder & textureHolder) : show(false){
	sprite.setTexture(*textureHolder.getTexture(Textures::DeleteItem));
	font.loadFromFile("resources/fonts/00TT.TTF");
	setPosition(1280/2 - sprite.getTextureRect().width/2, 32);
	deleteButton = sf::Rect<int>(getPosition().x + 57, getPosition().y + 61, 67, 25);
	cancelButton = sf::Rect<int>(getPosition().x + 126, getPosition().y + 61, 67, 25);
}
ParticleNode::ParticleNode(Particle::Type type, const TextureHolder& textures)
	: mParticles()
	, mTexture(textures.get(Textures::Particle))
	, mType(type)
	, mVertexArray(sf::Quads)
	, mNeedsVertexUpdate(true)
{
}
Beispiel #16
0
void Player::loadTexture(const TextureHolder& textures)
{
	mAnimation.setTexture(textures.get(Textures::Player));

	setOrigin(0,mSpriteSize.y);


}
Beispiel #17
0
Projectile::Projectile(Type type, const TextureHolder& textures)
: Entity(1)
, mType(type)
, mSprite(textures.get(Table[type].texture), Table[type].textureRect)
, mTargetDirection()
{
	centerOrigin(mSprite);
}
Beispiel #18
0
Projectile::Projectile(const TextureHolder& textures)
: mType(AlliedBullet)
{
    sf::Sprite spr(textures.get(Textures::Projectile));
    centerOrigin(spr);
    setSprite(spr);
    setID(1);
}
Beispiel #19
0
Paddle::Paddle(const TextureHolder& textures, const bool isPlayer) 
        :   mPlayer(isPlayer)
         , mSprite(textures.get(Textures::Paddle))
      
        
{
        centerOrigin(mSprite);
        
}
Beispiel #20
0
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)
{
}
Beispiel #21
0
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);

}
Beispiel #22
0
 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);
 }
Beispiel #23
0
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();
}
Beispiel #24
0
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();
}
Beispiel #25
0
    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("");
        }
    }
Beispiel #26
0
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();
}
Beispiel #27
0
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));
    }
}
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));
        
    }
}
Beispiel #29
0
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);
	};
}
Beispiel #30
0
Maze::Maze(const TextureHolder& textures, const sf::Vector2u& mazeSize) :
    mazeSize_(mazeSize),
    tileMap_(textures.resource(TextureId::Tiles)),
	mazeTexture_(),
	hitBox_(),
	contactNormals_(3),
	mazeMap_(),
	tileTextureById_(),
	tileHitBoxesById_(),
	wallCommand_()
{
	assert(tileSize > wallSize);
	mazeMap_.resize(mazeSize_.y);
	for(std::size_t i = 0; i < mazeSize_.y; ++i)
		mazeMap_[i].resize(mazeSize_.x);
    mazeTexture_.setPrimitiveType(sf::Triangles);
    mazeTexture_.resize(mazeSize_.x * mazeSize_.y* 6); //It needs 2 triangles to make a quad which makes 6 vertices.

	loadTiles();
    loadMaze();
}