Пример #1
0
    public virtual void OnPosition(GameEntity entity, Vector2Int value)
    {
        transform.DOLocalMove(CoordinatesConverter.Convert(value, size), 0.3f);
        bubblePosition = value;

        collider.enabled = true;
    }
        protected override void Execute(List <TimerEntity> entities)
        {
            foreach (var e in entities)
            {
                var mergeProgressMergeNumber = e.mergeProgress.mergeNumber;
                var mergeBubblePosition      = e.mergeProgress.mergeBubblePosition;

                e.RemoveTimer();
                contexts.timer.RemoveMergeProgress();
                var newBubble = contexts.game.GetBubbleWithPosition(mergeBubblePosition);
                contexts.game.SpawnEffect(
                    CoordinatesConverter.Convert(mergeBubblePosition, contexts.config.gameConfig.value.BubbleSize), mergeProgressMergeNumber);

                contexts.game.SpawnTextEffect(
                    CoordinatesConverter.Convert(mergeBubblePosition, contexts.config.gameConfig.value.BubbleSize), mergeProgressMergeNumber);

                contexts.gameState.ReplaceScore(contexts.gameState.score.value + mergeProgressMergeNumber);

                if (newBubble != null)
                {
                    newBubble.isNewBubble = true;
                }
                else
                {
                    contexts.game.isMoveComplete = true;
                }
            }
        }
    public virtual void OnPosition(GameEntity entity, Vector2Int value)
    {
        transform.DOKill();
        transform.localScale = new Vector3(0.01f, 0.01f, 1);
        var newPos = CoordinatesConverter.Convert(value, 1.2f);

        newPos.z = -1;
        transform.localPosition = newPos;

        transform.DOScale(new Vector3(0.45f, 0.45f, 1), 0.5f);
    }
Пример #4
0
 public void OnMergeTarget(GameEntity entity, Vector2Int value)
 {
     shadow.SetActive(false);
     gameObject.transform.DOLocalMove(CoordinatesConverter.Convert(value, size), destroyDuration).OnComplete(
         () =>
     {
         entity.isDestroyed = true;
         base.destroy();
         entity.Destroy();
     });
 }
    public void Link(IEntity entity)
    {
        var e = (GameEntity)entity;

        e.AddPositionListener(this);
        e.AddVisibleListener(this);

        if (e.hasPosition)
        {
            transform.localPosition = CoordinatesConverter.Convert(e.position.value, 1.2f);
        }

        SpriteRenderer.enabled = false;
    }
Пример #6
0
    public override void Link(IEntity entity)
    {
        base.Link(entity);
        var e = (GameEntity)entity;

        e.AddPositionListener(this);
        e.AddMergeTargetListener(this);
        e.AddFallingListener(this);
        collider.enabled = false;
        if (e.hasPosition)
        {
            if (e.hasStartPosition)
            {
                transform.localPosition = CoordinatesConverter.Convert(e.startPosition.Position, size);
            }
            else
            {
                transform.localPosition = CoordinatesConverter.Convert(e.position.value, size);
            }

            bubblePosition   = e.position.value;
            collider.enabled = true;
        }
    }
Пример #7
0
    private void PredictReflectionPattern(Vector2 position, Vector2 direction, GameEntity launcherEntity, GameEntity previewEntity)
    {
        bool       isReflected                = false;
        bool       isHitBubble                = false;
        Vector2    hitPoint                   = new Vector2();
        Vector2Int hitBubblePosition          = new Vector2Int();
        Vector2    hitBubbleTransformPosition = new Vector2();

        var startingPosition = position;
        var reflectionCount  = 0;
        var collisionPoints  = new List <Vector2>();

        collisionPoints.Add(startingPosition);

        while (reflectionCount <= contexts.config.gameConfig.value.MaxAmountOfReflections)
        {
            var hit = Physics2D.Raycast(position, direction, maxStepDistance);
            if (hit.collider == null)
            {
                break;
            }

            if (hit.collider.tag == "Bubble")
            {
                hitPoint                   = hit.point;
                hitBubblePosition          = hit.collider.gameObject.GetComponent <BoardBubbleView>().bubblePosition;
                hitBubbleTransformPosition = hit.collider.transform.position;
                isHitBubble                = true;
                collisionPoints.Add(hitPoint);
                break;
            }

            if (hit.collider.tag == "Wall")
            {
                direction = Vector2.Reflect(direction, hit.normal);
                position  = hit.point;

                //small adjustment so we not stuck in the wall
                if (position.x < startingPosition.x)
                {
                    position.x += 0.01f;
                }

                if (position.x > startingPosition.x)
                {
                    position.x -= 0.01f;
                }

                collisionPoints.Add(position);
                reflectionCount++;
            }
        }

        if (isHitBubble == false)
        {
            launcherEntity.ReplaceVisible(false);
            previewEntity.ReplaceVisible(false);
        }
        else
        {
            var newBubblePosition = CalculateNewBubblePosition(hitBubblePosition, hitBubbleTransformPosition, hitPoint);

            var shownTrajectory  = collisionPoints.ToArray();
            var flyingTrajectory = collisionPoints.ToArray();
            flyingTrajectory[flyingTrajectory.Length - 1] = GameObject.FindWithTag("Board").transform.TransformPoint(CoordinatesConverter.Convert(newBubblePosition, contexts.config.gameConfig.value.BubbleSize));
            launcherEntity.ReplaceLauncherTrajectory(hitPoint, shownTrajectory, flyingTrajectory);

            if (!previewEntity.hasPosition)
            {
                previewEntity.AddPosition(newBubblePosition);
            }

            if (previewEntity.hasPosition && previewEntity.position.value != newBubblePosition)
            {
                previewEntity.ReplacePosition(newBubblePosition);
            }

            launcherEntity.ReplaceVisible(true);
            previewEntity.ReplaceVisible(true);
        }
    }