예제 #1
0
        public static void CollisionPtoActionCollider()
        {
            touchLadderCount = 0;
            onPlatCount      = 0;

            for (int i = 0; i < lstObject.Count; i++)
            {
                Vector p1    = new Vector(Canvas.GetLeft(ImageData.imgPlayer), Canvas.GetTop(ImageData.imgPlayer));
                Vector size1 = new Vector(PlayerStatus.playerSize.X, PlayerStatus.playerSize.Y);

                Vector p2    = new Vector(Canvas.GetLeft(lstObject[i].imgObject), Canvas.GetTop(lstObject[i].imgObject));
                Vector size2 = new Vector(lstObject[i].size.X, lstObject[i].size.Y);

                switch (lstObject[i].objectAttribute)
                {
                case ObjectAttribute.EmptyCollider:

                    if (!isTrigger)
                    {
                        if (CollisionCheck.Collision(p1, p2, size1, size2))
                        {
                            if (lstObject[i].triggerAction)
                            {
                                GetTriggerTargetPosition(i);

                                activeObject = i;

                                isTrigger = true;

                                Canvas.SetLeft(ImageData.imgPopCanTalk, triggerTargetPosition.X - 16);
                                Canvas.SetTop(ImageData.imgPopCanTalk, triggerTargetPosition.Y - 32);
                                ImageData.imgPopCanTalk.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            ImageData.imgPopCanTalk.Visibility = Visibility.Hidden;
                        }
                    }
                    else
                    {
                        if (!TriggerExitCheck())
                        {
                            oldActiveObject = 0;
                            isTrigger       = false;
                        }
                    }


                    break;

                case ObjectAttribute.Physicality:

                    Vector move1 = new Vector(0, 0);
                    Vector move2 = new Vector(0, 0);

                    move1.X = PlayerStatus.moveSpeed;


                    if (PlayerStatus.jumping)
                    {
                        move1.Y = -PlayerStatus.jumpPower;
                    }
                    else
                    {
                        move1.Y = PlayerStatus.weight;
                    }

                    if (CollisionCheck.CollisionWithObstacle(p1, p2, size1, size2, move1, move2))
                    {
                        if (p1.X + size1.X < p2.X)
                        {
                            obstacleRight = true;
                        }

                        if (p1.X > p2.X + size2.X)
                        {
                            obstacleLeft = true;
                        }

                        if (p1.Y + size1.Y < p2.Y)
                        {
                            obstacleDown = true;
                        }

                        if (p1.Y > p2.Y + size2.Y)
                        {
                            obstacleUp = true;
                        }
                    }
                    else
                    {
                        obstacleUp    = false;
                        obstacleDown  = false;
                        obstacleLeft  = false;
                        obstacleRight = false;
                    }

                    break;

                case ObjectAttribute.Ladder:

                    if (CollisionCheck.TouchTheLadder(p1, p2, size1, size2))
                    {
                        PlayerStatus.jumpCount         = 0;
                        PlayerStatus.fallingStartPoint = PlayerStatus.playerPos.Y;
                        touchLadderCount++;
                    }

                    break;

                case ObjectAttribute.Platform:

                    if (CollisionCheck.OnThePlatform(p1, p2, size1, size2))
                    {
                        PlayerStatus.jumpCount = 0;
                        onPlatCount++;
                    }

                    break;

                case ObjectAttribute.Goalgate:

                    if (CollisionCheck.TouchGoal(p1, p2, size1, size2))
                    {
                        if (lstObject[i].toggleSwitch)
                        {
                            StageManager.clearFlag = true;
                        }
                    }

                    break;
                }

                if (touchLadderCount == 0)
                {
                    PlayerStatus.isLadder = false;
                }
                else
                {
                    PlayerStatus.isLadder = true;
                }

                if (onPlatCount == 0)
                {
                    PlayerStatus.isPlat = false;
                }
                else
                {
                    PlayerStatus.isPlat = true;
                }
            }
        }