protected override void Start() { base.Start(); turns = this.GetComponent <MapTurns>(); this.rectTransform = this.GetComponent <RectTransform>(); this.currentDirection = Directions.Right; this.moveCoroutines = new Queue <Coroutine>(); this.blinkCoroutines = new Queue <Coroutine>(); this.hammerCdCoroutines = new Queue <Coroutine>(); this.spriteRenderer = this.GetComponent <SpriteRenderer>(); this.health = this.GetComponent <MapHealth>(); this.possibleDirectionsInOrder = System.Enum.GetValues(typeof(Directions)).OfType <Directions>().ToList(); }
IEnumerator RemoveActor(MapTurns actor) { yield return(new WaitForEndOfFrame()); Coroutine thisCoroutine = objectsMoving[actor].Last(); while (objectsMoving[actor].Peek() != thisCoroutine) { yield return(false); } actor.DestroyIcon(); objectsMoving[actor].Dequeue(); }
IEnumerator CreateActorInPosition(MapTurns actor, int position) { yield return(new WaitForEndOfFrame()); Coroutine thisCoroutine = objectsMoving[actor].Last(); while (objectsMoving[actor].Peek() != thisCoroutine) { yield return(false); } actor.CreateObjectIcon(this.transform); Vector2 desiredPosition = new Vector3(position * this.IconDistance, 0, 0); float desiredScale = position == 0 ? actor.GetInitialScale() : actor.GetInitialScale() - Constants.Sizes.NextItemScaleFactor; actor.MoveObjectIcon(desiredPosition); actor.ScaleObjectIcon(desiredScale); objectsMoving[actor].Dequeue(); }
IEnumerator MoveActorToPosition(MapTurns actor, int position) { yield return(new WaitForEndOfFrame()); Coroutine thisCoroutine = objectsMoving[actor].Last(); while (objectsMoving[actor].Peek() != thisCoroutine) { yield return(false); } Vector2 actorPosition; Vector2 initialActorPosition = Vector2.zero; Vector2 desiredPosition = new Vector3(position * this.IconDistance, 0, 0); float desiredScale = position == 0 ? actor.GetInitialScale() : actor.GetInitialScale() - Constants.Sizes.NextItemScaleFactor; float initialScale = actor.GetInitialScale(); float currentScale = initialScale; float time = 0f; while (actor.TryGetPosition(out actorPosition) && actor.TryGetScale(out currentScale) && ( Vector2.Distance(actorPosition, desiredPosition) > Constants.Distances.MinimumDesiredDistanceToStop || Mathf.Abs(currentScale - desiredScale) > Constants.Distances.MinimumDesiredDistanceToStop)) { if (time == 0f) { initialActorPosition = actorPosition; actor.TryGetScale(out initialScale); } var posX = Mathf.SmoothStep(initialActorPosition.x, desiredPosition.x, time * 2); var posY = Mathf.SmoothStep(initialActorPosition.y, desiredPosition.y, time * 2); actor.MoveObjectIcon(new Vector2(posX, posY)); var scaleStep = Mathf.SmoothStep(initialScale, desiredScale, time * 2); actor.ScaleObjectIcon(scaleStep); time += Time.deltaTime; yield return(true); } objectsMoving[actor].Dequeue(); }