Exemplo n.º 1
0
Arquivo: adsr.cpp Projeto: eriser/fml
ADSR::ADSR() {
  reset();
  setAttackRate(0);
  setDecayRate(0);
  setReleaseRate(0);
  setSustainLevel(1.0);
  setTargetRatioA(0.3);
  setTargetRatioDR(0.0001);
}
Exemplo n.º 2
0
void ADSREnv::setParameter( UINT16 paramId, FLOAT value, FLOAT modulation, INT16 voice )
{
    voice = min( numVoices_-1, voice );

    switch( paramId )
    {
    case PARAM_GATE:
        if( voice > -1 )
        {
		    FLOAT velo = value * modulation + ( 1 - modulation );
            value > 0.0f ? keyOn( velo, voice ) : keyOff( voice );
            break;
	    }
	case PARAM_ATTACK:  setAttackRate( value, voice ); break;
	case PARAM_DECAY:   setDecayRate( value, voice ); break;
	case PARAM_SUSTAIN: setSustainLevel( value, voice ); break;
	case PARAM_RELEASE: setReleaseRate( value, voice ); break;
    }
}
Exemplo n.º 3
0
void HelpState::addPlankton(PlanktonController::Type type)
{
    auto entity = std::make_unique<Entity>(m_messageBus);
    entity->setWorldPosition({ static_cast<float>(Util::Random::value(0, 1920)), static_cast<float>(Util::Random::value(0, 1080)) });

    auto physComponent = m_physWorld.addBody(planktonSize);
    physComponent->setPosition(entity->getWorldPosition());
    physComponent->setTriggerOnly(true);
    physComponent->setName("control");
    entity->addComponent<PhysicsComponent>(physComponent);

    auto& appInstance = getContext().appInstance;
    bool colourblind = appInstance.getGameSettings().colourblindMode;
    AnimatedDrawable::Ptr ad;
    auto ident = ParticleSystem::create(Particle::Type::Ident, m_messageBus);
    ident->setTexture(appInstance.getTexture("assets/images/particles/ident.png"));
    auto text = std::make_unique<TextDrawable>(m_messageBus);
    text->setFont(appInstance.getFont("assets/fonts/Ardeco.ttf"));
    switch (type)
    {
    case PlanktonController::Type::Good:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food01.png"));
        ad->loadAnimationData("assets/images/player/food01.cra");
        (colourblind) ? ident->setColour({ 14u, 160u, 225u }) : ident->setColour({ 84u, 150u, 75u });
        text->setString("+50 HP");
        break;
    case PlanktonController::Type::Bad:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food02.png"));
        ad->loadAnimationData("assets/images/player/food02.cra");
        (colourblind) ? ident->setColour({ 214u, 190u, 25u }) : ident->setColour({ 184u, 67u, 51u });
        text->setString("-35 HP");
        break;
    case PlanktonController::Type::Bonus:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food03.png"));
        ad->loadAnimationData("assets/images/player/food03.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("+100 HP");
        break;
    case PlanktonController::Type::UberLife:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/bonus.png"));
        ad->loadAnimationData("assets/images/player/bonus.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("FULL HEALTH");
        break;
    default:
        break;
    }
    ident->setName("ident");
    entity->addComponent<ParticleSystem>(ident);

    text->setCharacterSize(40u);
    Util::Position::centreOrigin(*text);
    text->setPosition(0.f, 40.f);
    text->setName("text");
    entity->addComponent<TextDrawable>(text);

    ad->setBlendMode(sf::BlendAdd);
    ad->setOrigin(sf::Vector2f(ad->getFrameSize()) / 2.f);
    if (!ad->getAnimations().empty()) ad->play(ad->getAnimations()[0]);
    ad->setName("drawable");
    entity->addComponent<AnimatedDrawable>(ad);

    auto trail = ParticleSystem::create(Particle::Type::Trail, m_messageBus);
    trail->setTexture(appInstance.getTexture("assets/images/particles/circle.png"));
    float particleSize = planktonSize / 12.f;
    trail->setParticleSize({ particleSize, particleSize });
    trail->setName("trail");
    trail->setEmitRate(10.f);
    entity->addComponent<ParticleSystem>(trail);

    if (type == PlanktonController::Type::UberLife)
    {
        auto tails = std::make_unique<TailDrawable>(m_messageBus);
        tails->addTail(sf::Vector2f(-18.f, -15.f));
        tails->addTail(sf::Vector2f(-8.f, -5.f));
        tails->addTail(sf::Vector2f(-8.f, 5.f));
        tails->addTail(sf::Vector2f(-18.f, 15.f));
        tails->setName("tail");
        entity->addComponent<TailDrawable>(tails);
    }

    auto controller = std::make_unique<PlanktonController>(m_messageBus);
    controller->setType(type);
    controller->setDecayRate(0.f);
    controller->setColourblind(colourblind);
    entity->addComponent<PlanktonController>(controller);

    m_rootNode.addChild(entity);
}
Exemplo n.º 4
0
void Ingredient::onUpdate(float dt)
{
	if (dsq->game->isPaused()) return;
	if (dsq->game->isWorldPaused()) return;

	Vector lastPosition = position;
	Entity::onUpdate(dt);

	if (dsq->game->collideCircleWithGrid(position, 24))
	{
		position = lastPosition;
		/*
		if (velocity.x < velocity.y)
			velocity.x = -velocity.x;
		else
			velocity.y = -velocity.y;
		*/
		velocity = 0;
	}

	if (lifeSpan > 0)
	{
		lifeSpan -= dt;
		if (lifeSpan <= 0)
		{
			lifeSpan = 0;
			gone = true;
			this->scale.interpolateTo(Vector(0,0),1);
			setLife(1);
			setDecayRate(1);
		}
	}

	Vector diff = (dsq->game->avatar->position - position);
	if (diff.isLength2DIn(64))
	{
		if (scale.x == 1)
		{
			// got
			safeKill();

			dsq->continuity.pickupIngredient(data, 1);

			dsq->game->pickupIngredientEffects(data);

			dsq->spawnParticleEffect("IngredientCollect", position);
			
			dsq->sound->playSfx("pickup-ingredient");
		}
	}
	else
	{
		float len = 1024;
		if (dsq->game->avatar->isRolling() && diff.isLength2DIn(len))
		{
			float maxSpeed = 1500;
			Vector maxV = diff;
			maxV.setLength2D(len);
			diff = maxV - diff;
			diff *= maxSpeed/len;
			velocity += diff * 1.5f * dt;
		}
	}

	velocity.capLength2D(1000);

	if (isRotKind() && !velocity.isZero())
	{
		int mag = velocity.getLength2D();
		if (velocity.x > 0)
			rotation.z += mag*0.01f;
		else
			rotation.z -= mag*0.01f;
	}


	Vector sub = velocity;
	if (!sub.isZero())
	{
		sub.setLength2D(100*dt);
		velocity -= sub;
	}
	// collision?
}