示例#1
0
        public override void update()
        {
            base.update();

            if (Animating)
            {
                if (TimeMoving > Time.deltaTime)
                {
                    foreach (KeyValuePair <CardUi, Vector2> cardSpeedPair in CardSpeeds)
                    {
                        CardUi card = cardSpeedPair.Key;
                        card.position += cardSpeedPair.Value * Time.deltaTime;
                        card.setScale(card.scale.X + (1 - PreviousScale[card]) * (Time.deltaTime / SecondsToMove));
                    }
                    TimeMoving -= Time.deltaTime;
                }
                else
                {
                    foreach (KeyValuePair <CardUi, Vector2> cardSpeedPair in CardSpeeds)
                    {
                        CardUi card = cardSpeedPair.Key;
                        card.position += cardSpeedPair.Value * TimeMoving;
                        card.setScale(1);
                    }
                    TimeMoving = 0;
                    CardSpeeds.Clear();
                    AnimationHandler.EndAnimation();
                    Animating = false;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Stacks cards sequentially and fans them out
        /// </summary>
        protected void OrganizeHand()
        {
            AnimationHandler.AddAnimation();
            TimeMoving = SecondsToMove;
            Animating  = true;

            foreach (CardUi card in Cards)
            {
                PreviousScale[card] = card.scale.X;
            }
            if (Cards.Count <= MaxHandSizeBeforeOverlap)
            {
                for (int i = 0; i < Cards.Count; i++)
                {
                    CardUi cardEntity = Cards[i];
                    MoveToPositionInHand(cardEntity, i, CardUi.CardWidth);
                }
            }
            else
            {
                float distanceBetweenCards = (HandWidth - CardUi.CardWidth) / (Cards.Count - 1);
                for (int i = 0; i < Cards.Count; i++)
                {
                    CardUi cardEntity = Cards[i];
                    cardEntity.getComponent <Sprite>().layerDepth = 1 - (i * layerDepthIncriment);
                    MoveToPositionInHand(cardEntity, i, distanceBetweenCards);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Moves a card to a spot in hand based on the index and distanceBetweenCards
        /// </summary>
        /// <param name="cardEntity">Card to be moved</param>
        /// <param name="index">Position within hand to move to</param>
        /// <param name="distanceBetweenCards">how close each card in hand is</param>
        protected void MoveToPositionInHand(CardUi cardEntity, int index, float distanceBetweenCards)
        {
            float   startOfHand = position.X - HandWidth / 2 + CardUi.CardWidth / 2;
            Vector2 destination = new Vector2(distanceBetweenCards * index + startOfHand, position.Y);

            CardSpeeds[cardEntity] = (destination - cardEntity.position) / SecondsToMove;
        }
示例#4
0
        /// <summary>
        /// Moves a card to a spot in hand based on the index and distanceBetweenCards
        /// </summary>
        /// <param name="cardEntity">Card to be moved</param>
        /// <param name="index">Position within hand to move to</param>
        /// <param name="distanceBetweenCards">how close each card in hand is</param>
        protected void MoveToPositionInPlay(CardUi cardEntity, int index, int cardRowIndex)
        {
            float   starOfInPlay = position.X - InPlayWidth / 2;
            Vector2 destination  = new Vector2(
                (CardUi.CardWidth + SpaceBetweenCards) * index * TargetScale[cardRowIndex]
                + starOfInPlay
                + (CardUi.CardWidth + SpaceBetweenCards) * TargetScale[cardRowIndex] / 2,
                position.Y + (CardUi.CardHeight + SpaceBetweenCards) / 2
                );

            CardSpeeds[cardEntity] = (destination - cardEntity.position) / SecondsToMove;
        }
示例#5
0
        public override void update()
        {
            base.update();

            if (Animating)
            {
                if (TimeMoving > Time.deltaTime)
                {
                    foreach (KeyValuePair <CardUi, Vector2> cardSpeedPair in CardSpeeds)
                    {
                        cardSpeedPair.Key.position += cardSpeedPair.Value * Time.deltaTime;
                    }

                    List <CardUi>[] CardRows = new List <CardUi>[] { FrontRowCards, BackRowCards };
                    for (int i = 0; i < 2; i++)
                    {
                        for (int j = 0; j < CardRows[i].Count; j++)
                        {
                            CardUi card = CardRows[i][j];
                            card.setScale(card.scale.X + (TargetScale[i] - PreviousScale[i][card]) * (Time.deltaTime / SecondsToMove));
                        }
                    }
                    TimeMoving -= Time.deltaTime;
                }
                else
                {
                    foreach (KeyValuePair <CardUi, Vector2> cardSpeedPair in CardSpeeds)
                    {
                        CardUi card = cardSpeedPair.Key;
                        card.position += cardSpeedPair.Value * TimeMoving;
                    }

                    for (int i = 0; i < 2; i++)
                    {
                        for (int j = 0; j < CardRows[i].Count; j++)
                        {
                            CardRows[i][j].setScale(TargetScale[i]);
                        }
                    }

                    TimeMoving = 0;
                    CardSpeeds.Clear();
                    AnimationHandler.EndAnimation();
                    Animating = false;
                }
            }
        }
示例#6
0
        /// <summary>
        /// Stacks cards sequentially and fans them out
        /// </summary>
        protected void OrganizeHand()
        {
            AnimationHandler.AddAnimation();
            TimeMoving = SecondsToMove;
            Animating  = true;

            List <CardUi>[] CardRows = new List <CardUi>[] { FrontRowCards, BackRowCards };
            for (int i = 0; i < 2; i++)
            {
                if (CardRows[i].Count > MaxCardsBeforeOverlap)
                {
                    TargetScale[i] = (InPlayWidth / CardRows[i].Count) / (CardUi.CardWidth + SpaceBetweenCards);
                }
                for (int j = 0; j < CardRows[i].Count; j++)
                {
                    CardUi cardEntity = CardRows[i][j];
                    PreviousScale[i][cardEntity] = cardEntity.scale.X;
                    MoveToPositionInPlay(cardEntity, j, i);
                }
            }
        }
示例#7
0
        public void update()
        {
            if (!AnimationHandler.IsAnimationRunning())
            {
                entity.setPosition(Input.mousePosition);
                CardUi                 topCard          = null;
                BoardAreaUi            clickedBoardArea = null;
                float                  topLayerDepth    = LowestLayerDepth;
                IEnumerable <Collider> neighbors        = Physics.boxcastBroadphaseExcludingSelf(this, collidesWithLayers);

                if (!Dragging && Input.leftMouseButtonPressed)
                {
                    foreach (var neighbor in neighbors)
                    {
                        CollisionResult collisionResult = new CollisionResult();
                        if (neighbor.isTrigger)
                        {
                            continue;
                        }

                        if (collidesWith(neighbor, out collisionResult))
                        {
                            Entity collidedEntity = collisionResult.collider.entity;

                            if (collidedEntity is CardUi)
                            {
                                float currentLayerDepth;
                                currentLayerDepth = collisionResult.collider.entity.getComponent <Sprite>().layerDepth;

                                if (currentLayerDepth < topLayerDepth)
                                {
                                    topCard       = (CardUi)collidedEntity;
                                    topLayerDepth = currentLayerDepth;
                                }
                            }
                            else if (collidedEntity is BoardAreaUi)
                            {
                                clickedBoardArea = (BoardAreaUi)collidedEntity;
                            }
                        }
                    }

                    if (topCard != null)
                    {
                        DraggedCard        = topCard;
                        DragOffsetPosition = DraggedCard.position - Input.mousePosition;
                        DraggedCard.getComponent <Sprite>().renderLayer = PickedUpRenderLayer;
                        Dragging = true;
                    }
                    else if (clickedBoardArea != null)
                    {
                        //TODO: remove
                        Console.WriteLine(clickedBoardArea.GetType());
                    }
                }
                else if (Dragging && Input.leftMouseButtonDown)
                {
                    //TODO: check zone colliding with
                    //collidesWithAny(out collisionResult);
                    DraggedCard.position = Input.mousePosition + DragOffsetPosition;
                }
                else if (Dragging && !Input.leftMouseButtonDown)
                {
                    DraggedCard.getComponent <Sprite>().renderLayer = DefaultRenderLayer;
                    Dragging = false;
                }
            }
        }