Example #1
0
        public void OnPointerDown(PointerEventData eventData)
        {
            if (_target_btn.IsInteractable() && (eventData.button != PointerEventData.InputButton.Middle && eventData.button != PointerEventData.InputButton.Right))
            {
                //down 相关

                if (OnDown != null)
                {
                    OnDown.Invoke();
                }
                OnDownAction?.Invoke();

                //long tap 相关
                if (this.LongTapTime > 0)
                {
                }
            }
        }
Example #2
0
        public bool Move(bool move, float targetMoveX, float targetMoveY)
        {
            var moveX = 0f;
            var moveY = 0f;

            var returnCollide = false;

            var potentialCollideEntities = _level.GetAllEntitiesInCells(
                Entity.Box.Merge(new Rect(
                                     new Point(Entity.Box.Position.X + targetMoveX, Entity.Box.Position.Y + targetMoveY),
                                     Entity.Box.Size))).Where(filter => {
                if (!ReferenceEquals(Entity, filter) && filter.GetCurrentState().HasComponent <PhysicsComponent>())
                {
                    var filterComp = filter.GetCurrentState().GetComponent <PhysicsComponent>();
                    return(!filterComp.IgnoreTags.Contains(Entity.Tag) &&
                           (!filterComp.IsPlatform || Entity.Box.Bottom() <= filter.Box.Top()));
                }

                return(false);
            }).ToArray();

            var checkRect          = new Rect(Entity.Box);
            var triggerCallCounter = 0;

            // Do-while à la place d'un while pour vérifier si l'entité n'est pas déjà en overlaps avec une autre (mal placé)
            do
            {
                checkRect.Y = Entity.Box.Y + moveY + Math.Sign(targetMoveY) * Constants.PhysicsEpsilon;

                var collide = false;
                foreach (var it in potentialCollideEntities)
                {
                    if (checkRect.Overlaps(it.Box))
                    {
                        BoxSide side;

                        if (moveY < 0)
                        {
                            side = BoxSide.Up;
                        }
                        else if (moveY > 0)
                        {
                            side = BoxSide.Down;
                        }
                        else
                        {
                            // Permet de téléporter cette entité au-dessus de l'autre
                            if (move)
                            {
                                Entity.Box.Y = Math.Max(it.Box.Top() - Entity.Box.Height - Constants.PhysicsEpsilon,
                                                        _level.MatrixRect.Top());
                            }

                            continue;
                        }

                        collide = true;

                        TriggerCollisionEvent(it, side, triggerCallCounter++);
                    }
                }

                if (!collide && !moveY.EqualsEpsilon(targetMoveY, Constants.PhysicsEpsilon))
                {
                    moveY += Math.Sign(targetMoveY) * Constants.PhysicsEpsilon;
                }
                else
                {
                    if (!collide)
                    {
                        if (moveY > 0 && !Entity.Box.Top()
                            .EqualsEpsilon(_level.MatrixRect.Top(), Constants.PhysicsEpsilon))
                        {
                            OnUpAction.Invoke(Entity);
                        }
                        else if (moveY < 0)
                        {
                            OnDownAction.Invoke(Entity);
                        }
                    }
                    else
                    {
                        returnCollide = true;
                    }

                    if (move)
                    {
                        Entity.Box.Y =
                            Math.Max(Entity.Box.Y + moveY - Math.Sign(targetMoveY) * Constants.PhysicsEpsilon,
                                     _level.MatrixRect.Top());
                    }

                    checkRect.Y = Entity.Box.Y;
                    break;
                }
            } while (Math.Abs(moveY) < Math.Abs(targetMoveY));

            while (Math.Abs(moveX) < Math.Abs(targetMoveX))
            {
                checkRect.Position =
                    new Point(Entity.Box.X + moveX + Math.Sign(targetMoveX) * Constants.PhysicsEpsilon,
                              checkRect.Position.Y);
                var collide = false;

                foreach (var it in potentialCollideEntities)
                {
                    if (checkRect.Overlaps(it.Box))
                    {
                        BoxSide side;
                        if (moveX > 0)
                        {
                            side = BoxSide.Right;
                        }
                        else if (moveX < 0)
                        {
                            side = BoxSide.Left;
                        }
                        else
                        {
                            continue;
                        }

                        collide = true;

                        TriggerCollisionEvent(it, side, triggerCallCounter++);
                    }
                }

                if (!collide && !moveX.EqualsEpsilon(targetMoveX, Constants.PhysicsEpsilon))
                {
                    moveX += Math.Sign(targetMoveX) * Constants.PhysicsEpsilon;
                }
                else
                {
                    if (!collide)
                    {
                        if (moveX > 0 && !Entity.Box.Right()
                            .EqualsEpsilon(_level.MatrixRect.Right(), Constants.PhysicsEpsilon))
                        {
                            OnRightAction.Invoke(Entity);
                        }
                        else if (moveX < 0 && !Entity.Box.Left()
                                 .EqualsEpsilon(_level.MatrixRect.Left(), Constants.PhysicsEpsilon))
                        {
                            OnLeftAction.Invoke(Entity);
                        }
                    }
                    else
                    {
                        returnCollide = true;
                    }

                    if (move)
                    {
                        Entity.Box.X = MathHelper.Clamp(
                            Entity.Box.X + moveX - Math.Sign(targetMoveX) * Constants.PhysicsEpsilon,
                            _level.MatrixRect.Left(), _level.MatrixRect.Right() - Entity.Box.Width);
                    }

                    checkRect.X = Entity.Box.X;
                    break;
                }
            }

            return(returnCollide);
        }