void EnergyReceiver::ActivateByEnergy()
{
	if(_state <= ER_STAND && !_hideByThief)
	{
		_state = ER_ACTIVATED_BREAK;


		MM::manager.PlaySample("ReceiverActivated");

		ParticleEffectPtr eff = Game::AddEffect(GameField::Get()->_effContUpField, "RecReady");
		eff->SetPos(GetCenterPos());
		eff->Reset();

		Game::AddController(new Receiver::ReceiverEffect(FPoint(GetIndex())*GameSettings::SQUARE_SIDEF + FPoint(0.f, _fly_offset_y * GameSettings::SQUARE_SCALE), _uid, _crystalAnim->GetCurrentFrame()));
		_crystalAnim.reset();

		//_frame1 = _crystalAnim->GetCurrentFrame();
		//_frame2 = (_crystalAnim->GetLastPlayedFrame() - _crystalAnim->GetFirstPlayedFrame())*3 + 3;
		//_crystalTime = 0.f;
		//_crystalTimeScale = 1.f/1.5f;

		_timerForRunChipFall = gameInfo.getConstFloat("TIME_FOR_FOR_RUN_CHIP_AFTER_REMOVE_RECEIVER", 2.f);
		
		if(_partUp.get())
		{
			_partUp->Finish();
			_partUp.reset();
		}
		_effContDown.Finish();
		Tutorial::luaTutorial.AcceptMessage( Message("OnReceiverActivated") );
	}
}
Exemple #2
0
/// в теории-то разные могут быть последстви¤
void GameObject::getHit()
{
	_alive = false;
	ParticleEffectPtr projEff = p_effDel->AddEffect(_destroyEffectName);
	projEff->SetPos(_position);
	projEff->Reset();
}
void LevelEndBonusController::Update(float dt)
{
	local_time += dt;
	if( local_time >= 0.0f )
	{
		Game::FieldAddress address(_center);
		FPoint pos = GameSettings::gamefield[address]->GetCellPos() + GameSettings::CELL_HALF;
		ParticleEffectPtr eff = Game::AddEffect(gameField->_effTopCont, "LineBonusChip_0");
		eff->SetPos(pos);
		eff->Reset();

		gameField->addWave(pos.Rounded(), 0.02f, 1000.0f, 125.0f);
	}
}
Exemple #4
0
void Firework::Explode() {
	_isExplode = true;
	_tailEffect->Finish();
	_tailEffect = nullptr;
	std::string effectName = "SmallExplosion";
	if (_curLevel == 1) {
		effectName = "BigExplosion";
	} else if (_curLevel == _maxLevel) {
		effectName = "Particles";
	}
	ParticleEffectPtr explode = _container.AddEffect(effectName);
	explode->SetPos(_pos);
	explode->Reset();
	if (_curLevel < _maxLevel) {
		float offsetAngle = math::random(0.f, 2 * math::PI / _numChildrens);
		for (int i = 0; i < _numChildrens; ++i) {
			float angle = offsetAngle + 2 * math::PI * i / _numChildrens;
			FPoint newPos;
			newPos.x = _pos.x + RADIUS * math::cos(angle);
			newPos.y = _pos.y + RADIUS * math::sin(angle);
			_childrens.push_back(std::unique_ptr<Firework>(new Firework(newPos, angle, _curLevel + 1, _maxLevel, _numChildrens)));
		}
	}
}
	void ReceiverEffect::Update(float dt)
	{
		_localTime += dt;
		if(_crystalTime < 1)
		{
			_crystalTime = math::clamp(0.f, 1.f, _crystalTime + dt*_crystalTimeScale);
			int frames_count = _crystalAnim->GetLastPlayedFrame() - _crystalAnim->GetFirstPlayedFrame();
			int frame = _crystalAnim->GetFirstPlayedFrame() + (math::lerp(_frame1, _frame2, _crystalTime) % frames_count);
			_crystalAnim->SetCurrentFrame(frame);		
		}
		if(_state == RE_JUMP)
		{
			ReceiverEffect::keep_camera = true;
			if(_crystalAnim)
			{
				//_crystalAnim->Update(dt*math::lerp(0.f, _crystalTimeScale*2.f, sinf(math::ease(_time, 0.1f, 0.9f)*math::PI)));
			}
			if(_time < 1)
			{
				_time += dt*_jumpTmeScale;
				if(_time > 1)
				{
					_time = 0.f;
					_state = RE_STAY;		

					_flyEffect = _effCont.AddEffect("RecFly");
					_flyEffect->SetPos(GameSettings::ToScreenPos(_posStartOnField));
					_flyEffect->Reset();
					Assert(_flyEffect->IsPermanent());

				}
			}
		}
		else if(_state == RE_STAY)
		{
			ReceiverEffect::keep_camera = true;
			if(_time < 1)
			{
				_time += dt*_stayTimeScale;
				if(_time > 1)
				{
					_state = RE_FLY;
					_time = 0.f;
				}
			}
		}
		else if(_state == RE_FLY)
		{
			if(_time < 1)
			{
				_time += dt*_flyTimeScale;
				if(!_finishEffectRunning && (1 - _time)/_flyTimeScale < 0.5f)
				{
					//За 0.5с до прилета кристалла в лут запускаем эффект прилета
					_finishEffectRunning = true;
					ParticleEffectPtr eff = Game::AddEffect(GameField::Get()->_effContUp, "RecFinish");
					eff->SetPos(_lootPos);
					eff->Reset();
				}
				if(_time > 1)
				{
					_time = 0.f;
					_state = RE_HIDE;
					if(_flyEffect)
					{
						_flyEffect->Finish();
						_flyEffect.reset();
					}
					Core::LuaCallVoidFunction("gameInterfaceRunReceiverChangeEffect");
					//заменяем звук
					//MM::manager.StopSample(_idSample);
					//_idSample = MM::manager.PlaySample("RecieverLanded");
				}
			}
		}else if(_state == RE_HIDE)
		{
			if(_time < 1)
			{
				_time += dt*0.5f;
				if(_time > 1)
				{
					_time = 0.f;
					_state = RE_FINISH;
					Gadgets::receivers.AcceptMessage(Message("DestroyFinished", _uid));
				}
			}
		}
		//else if(_state == RE_WAIT)
		//{
		//	if(_time < 1)
		//	{
		//		_time += dt*1.0f;
		//		if(_time > 1)
		//		{
		//			_time = 0.f;
		//			_state = RE_FINISH;

		//		}
		//	}
		//}
		_effCont.Update(dt);
		_effContInner.Update(dt);
	}
	ReceiverEffect::ReceiverEffect(const FPoint pos, std::string uid, int current_frame)
		: GameFieldController("ReceiverEffect", 1.f, GameField::Get())
		, _time(0.f)
		, _localTime(0.f)
		, _state(RE_JUMP)
		, _uid(uid)
		, _finishEffectRunning(false)
	{
		JUMP_POS.y = gameInfo.getConstFloat("RECEIVER_JUMP_HEIGHT", 120.f);
		_jumpTmeScale = 1.f/gameInfo.getConstFloat("RECEIVER_JUMP_TIME", 0.5f);
		_stayTimeScale = 1.f/gameInfo.getConstFloat("RECEIVER_STAY_TIME", 0.5f);
		_flyTimeScale = 1.f/gameInfo.getConstFloat("RECEIVER_FLY_TIME", 1.f);
		_jumpScale = gameInfo.getConstFloat("RECEIVER_JUMP_SCALE", 2.f);
		
		_crystalAnim = Render::StreamingAnimation::Spawn("CrystalRotate");
		_crystalAnim->SetCurrentFrame(current_frame);
		_frame1 = current_frame;
		_frame2 = (_crystalAnim->GetLastPlayedFrame() - _crystalAnim->GetFirstPlayedFrame())*gameInfo.getConstInt("RECEIVER_ROTATE_COUNT", 3) + gameInfo.getConstInt("RECEIVER_LAST_FRAME", 3);
		
		_crystalTime = 0.f;
		_crystalTimeScale = _jumpTmeScale*_stayTimeScale/(_jumpTmeScale + _stayTimeScale);

		_posStartOnField = pos + FPoint(GameSettings::CELL_HALF.x, 0.f);
		_v0 = GameSettings::ToScreenPos(_posStartOnField + JUMP_POS); //Точка старта
		_lootPos = Core::LuaCallFunction<FPoint>("gameInterfaceReceiverPosition");
		FPoint v1 = _lootPos + CRYSTAL_POS_ANIM_ON_SQUARE - CRYSTAL_SCALE_CENTER; //Точка на панели
		_finishScaleCrystal = FPoint(0.75f, 0.75f);

		_spline.Clear();
		_spline.addKey(_v0);
		//FPoint dir = (v1 -_v0).Rotated(math::PI * 0.5f * (math::random(0,1) ? 1.f : -1.f));
		//FPoint dir = (v1 -_v0).Rotated(math::PI * 0.5f * -1.f);
		//_spline.addKey(_v0*0.5f + v1*0.5f + dir.Normalized()*100.f);
		_spline.addKey(v1);
		_spline.CalculateGradient();

		_angleSpline.Clear();
		float angle_prev = _spline.getGlobalFrame(0.f).GetDirectedAngleNormalize( FPoint(0.f, 1.f))*180.f/math::PI;
		if(angle_prev > 180.f)
		{
			angle_prev -= 360.f;
		}
		for(size_t i = 0; i <=2; i++)
		{
			float t = float(i)/2.f;
			float angle = _spline.getGlobalFrame(t).GetDirectedAngleNormalize(FPoint(0.f, 1.f))*180.f/math::PI;
			if(angle > 180.f)
			{
				angle -= 360.f;
			}
			while(abs(angle - angle_prev) > 180.f)
			{
				if(angle > angle_prev)
				{
					angle -= 360.f;
				}else{
					angle += 360.f;
				}
			}
			_angleSpline.addKey(angle);		
			angle_prev = angle;
		}
		_angleSpline.CalculateGradient();

		gameField->AddEnergyWave(pos, "EnergyWaveBig");

		//_idSample = MM::manager.PlaySample("RecieverFly",true);

        ParticleEffectPtr eff = Game::AddEffect(_effCont, "RecBreakFront");
		eff->SetPos(GameSettings::ToScreenPos(_posStartOnField + JUMP_POS));
		eff->Reset();
		ReceiverEffect::keep_camera = true;
	}