Commit f0af2a5a authored by Gerard Gascón's avatar Gerard Gascón
Browse files

fix: grow animation spawning at correct positions

parent a06779c5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2458,6 +2458,7 @@ MonoBehaviour:
  - {fileID: 6383810576328763588}
  - {fileID: 8413760021314526160}
  - {fileID: 3176123164317376148}
  growAnimation: {fileID: 902566665}
--- !u!4 &1465666065
Transform:
  m_ObjectHideFlags: 0
+9 −4
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ namespace View.Scene {
		private SpawnRose _spawnRose;
		private bool _firstUpdate = true;

		public bool Growing { private set; get; } = true;

		private void Start() {
			_score = FindObjectOfType<Dependencies>().Score;
			_spawnRose = FindObjectOfType<Dependencies>().Spawner;
@@ -35,6 +37,7 @@ namespace View.Scene {
			}

			if (animationName == "Rosa_End") {
				Growing = true;
				_spawnRose.Execute();
				animator.ChangeAnimation(growAnimation);
				animator.PlayUntil(_score.GrowPercentage);
@@ -43,17 +46,19 @@ namespace View.Scene {

		public void GrowStep() {
			if (animator.CurrentAnimation == "Rosa_Grow") {
				animator.PlayUntil(IsLastGrowState(_score.Value, _score.GrowPercentage) ? 1f : _score.GrowPercentage);
				if (IsLastGrowState())
					Growing = false;
				animator.PlayUntil(IsLastGrowState() ? 1f : _score.GrowPercentage);
				if (_score.GrowPercentage < 1f && !_firstUpdate)
					RuntimeManager.PlayOneShot(growEvent);
			}
			_firstUpdate = false;
		}

		private bool IsLastGrowState(int score, float growPercentage) {
			if (growPercentage != 0)
		public bool IsLastGrowState() {
			if (_score.GrowPercentage != 0)
				return false;
			bool isLastFrame = score % (_score.GrowIterations * _score.SpawnRate) == 0;
			bool isLastFrame = _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;
			if (!isLastFrame)
				return false;
			if (_firstUpdate)
+9 −1
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ namespace View.Scene {
		[SerializeField] private GrowParticle growParticle;
		[SerializeField] private Transform[] growParticlePositions;

		[SerializeField] private GrowAnimation growAnimation;

		private Score _score;

		private void Awake() {
@@ -22,11 +24,17 @@ namespace View.Scene {

		public void OnInputReceived() {
			float randomRotation = Random.Range(0, 360);
			if(growAnimation.Growing)
				growParticle.Spawn(GetGrowParticlePosition(), Quaternion.Euler(0, 0, randomRotation));
		}

		private Vector3 GetGrowParticlePosition() {
			float iterationStep = 1f / _score.SpawnRate;
			bool isLastGrowStep = _score.Value % (_score.GrowIterations * _score.SpawnRate) == 0;

			if(isLastGrowStep)
				return growParticlePositions[^1].position;

			for (int i = 0; i < growParticlePositions.Length; i++) {
				if (_score.GrowPercentage < (i + 1) * iterationStep)
					return growParticlePositions[i].position;