Пример #1
0
        private static void EnemyHorizontalMove(int index, bool direction, Vector pos, Vector size,
                                                int speed, bool wait)
        {
            if (!lstEnemyData[index].valueSetComp)
            {
                EnemyBehaviorValuesSetup(index);
            }

            if (lstEnemyData[index].totalDistance.X < lstEnemyData[index].targetDistance.X)
            {
                if (!direction)
                {
                    if (!BlockCheck.BlockCheckLeft(pos.X, pos.Y, (int)size.Y, speed) &&
                        pos.X > 0)
                    {
                        if (pos.X - SystemOperator.PixelPerSecond(speed) > 0)
                        {
                            pos.X -= SystemOperator.PixelPerSecond(speed);
                        }
                        else
                        {
                            lstEnemyData[index].targetDistance = new Vector(0, lstEnemyData[index].targetDistance.Y);
                            lstEnemyData[index].direction      = true;
                        }
                    }
                }
                else
                {
                    if (!BlockCheck.BlockCheckRight(pos.X, pos.Y, (int)size.X, (int)size.Y, speed) &&
                        pos.X + size.X < 1024 - lstEnemyData[index].size.X)
                    {
                        if (pos.X + SystemOperator.PixelPerSecond(speed) < 992)
                        {
                            pos.X += SystemOperator.PixelPerSecond(speed);
                        }
                        else
                        {
                            lstEnemyData[index].targetDistance = new Vector(0, lstEnemyData[index].targetDistance.Y);
                            lstEnemyData[index].direction      = false;
                        }
                    }
                }

                lstEnemyData[index].position.X       = pos.X;
                lstEnemyData[index].totalDistance.X += SystemOperator.PixelPerSecond(speed);
            }
            else
            {
                if (wait)
                {
                    lstEnemyData[index].isWaiting      = true;
                    lstEnemyData[index].totalWaitTime  = 0;
                    lstEnemyData[index].targetWaitTime = 2000;
                }

                lstEnemyData[index].targetDistance = new Vector(0, 0);
                lstEnemyData[index].totalDistance  = new Vector(0, 0);
                lstEnemyData[index].valueSetComp   = false;
            }
        }
Пример #2
0
        public static void MovePlayer(Canvas canvas)
        {
            if (KeyController.keyLeft)
            {
                if (!BlockCheck.BlockCheckLeft(playerPos.X, playerPos.Y, (int)playerSize.Y, moveSpeed) &&
                    !ObjectChecker.obstacleLeft)
                {
                    if (playerPos.X - SystemOperator.PixelPerSecond(moveSpeed) > 0)
                    {
                        playerPos.X -= SystemOperator.PixelPerSecond(moveSpeed);
                        SystemOperator.moveCommonAmountX = moveSpeed;
                    }
                    playerDirection = false;
                }
            }

            if (KeyController.keyRight)
            {
                if (!BlockCheck.BlockCheckRight(playerPos.X, playerPos.Y, (int)playerSize.X, (int)playerSize.Y, moveSpeed) &&
                    !ObjectChecker.obstacleRight)
                {
                    if (playerPos.X + SystemOperator.PixelPerSecond(moveSpeed) < 992)
                    {
                        playerPos.X += SystemOperator.PixelPerSecond(moveSpeed);
                        SystemOperator.moveCommonAmountX = moveSpeed;
                    }
                    playerDirection = true;
                }
            }

            if (KeyController.keyLeft || KeyController.keyRight)
            {
                isMove = true;
            }
            else
            {
                isMove = false;
            }


            if (KeyController.keyUp && !TalkCommander.isTalk &&
                !ObjectChecker.obstacleUp)
            {
                if (isLadder)
                {
                    if (playerPos.Y - SystemOperator.PixelPerSecond(moveSpeed) > 0)
                    {
                        playerPos.Y -= SystemOperator.PixelPerSecond(moveSpeed);
                        SystemOperator.moveCommonAmountY = moveSpeed;
                    }
                }
            }

            if (KeyController.keyDown && !TalkCommander.isTalk &&
                !ObjectChecker.obstacleDown)
            {
                if (isLadder)
                {
                    if (playerPos.Y + SystemOperator.PixelPerSecond(moveSpeed) < 768)
                    {
                        playerPos.Y += SystemOperator.PixelPerSecond(moveSpeed);
                        SystemOperator.moveCommonAmountY = moveSpeed;
                    }
                }

                if (isPlat)
                {
                    if (playerPos.Y + SystemOperator.PixelPerSecond(moveSpeed) < 768)
                    {
                        playerPos.Y += SystemOperator.PixelPerSecond(moveSpeed);
                        SystemOperator.moveCommonAmountY = moveSpeed;
                    }
                }

                if (!isLadder)
                {
                    isSquat = true;
                }
            }
            else
            {
                isSquat = false;
            }

            //jump
            if (KeyController.keySpace && jumpCount == 0)
            {
                if (playerPos.Y - jumpPower > 0)
                {
                    jumpCount++;

                    jumping = true;
                }
            }

            if (jumping)
            {
                if (jumpTotalLength < jumpMaxHeight &&
                    !BlockCheck.BlockCheckTop(playerPos.X, playerPos.Y, (int)playerSize.X, jumpPower) &&
                    !ObjectChecker.obstacleUp)
                {
                    playerPos.Y -= SystemOperator.PixelPerSecond(jumpPower);
                    SystemOperator.moveCommonAmountY = SystemOperator.PixelPerSecond(jumpPower);

                    jumpTotalLength += SystemOperator.PixelPerSecond(jumpPower);
                }
                else
                {
                    jumping         = false;
                    jumpTotalLength = 0;
                }
            }


            //itemget
            if (KeyController.keyA)
            {
                PlayerItemGetting(canvas);
            }

            //Attack
            if (KeyController.keyS)
            {
                SubWeapon.SubWeaponGenerate(canvas, playerPos.X, playerPos.Y);
            }

            if (KeyController.keyD)
            {
                if (!isMainAttack)
                {
                    MainWeapon.imgMainWeapon.Visibility = Visibility.Visible;
                    meleeDirection = playerDirection;
                    isMainAttack   = true;
                }
            }

            if (KeyController.keyE)
            {
                if (ObjectChecker.isTrigger && !TalkCommander.isTalk)
                {
                    ObjectBehavior.OnTriggerReactEvent();
                }
            }

            if (isKnockBack)
            {
                SystemOperator.BoundObject(ref playerPos, boundDirectionX, ref knockBackTotalDis, knockBackTargetDis,
                                           ref knockBackBps, ref coefficient, ref boundDirectionY,
                                           weight, moveSpeed, jumpPower, playerSize, ref isKnockBack);
            }

            //image change
            if (GameTransition.gameTransition == GameTransitionType.StageDuring)
            {
                if (KeyController.keyLeft || KeyController.keyRight)
                {
                    if (!playerDirection)
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteMoveL);
                    }
                    else
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteMoveR);
                    }
                }
                else
                {
                    if (!playerDirection)
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteIdleL);
                    }
                    else
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteIdleR);
                    }
                }


                if (isSquat)
                {
                    if (!playerDirection)
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteSquatL);
                    }
                    else
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteSquatR);
                    }
                }

                if (jumping)
                {
                    if (!playerDirection)
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteJumpL);
                    }
                    else
                    {
                        ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteJumpR);
                    }
                }

                if (isLadder && (KeyController.keyUp || KeyController.keyDown))
                {
                    ImageData.imgPlayer.Source = ImageData.ImageSourceSelector(CategoryName.Player, StageData.lstDbPlayer.spriteLadder);
                }
            }

            Canvas.SetLeft(ImageData.imgPlayer, playerPos.X);
            Canvas.SetTop(ImageData.imgPlayer, playerPos.Y);
        }
Пример #3
0
        public static void BoundObject(ref Vector pos, bool charaDir, ref Vector total, Vector target, ref Vector bps,
                                       ref double coefficient, ref bool boundDir, int weight, int speed, int jumppower,
                                       Vector size, ref bool isKnockBack)
        {
            double addY   = 0;
            double radian = 0;



            bps.X = target.X / 32 * PixelPerSecond(64);
            bps.Y = target.Y * bps.X / target.X;

            addY = coefficient * weight / (target.X / 2) * 0.102;

            radian = Math.Atan(bps.Y - addY / bps.X) * Math.PI / 180;

            if (!boundDir)
            {
                if (total.Y < target.Y)
                {
                    if (!charaDir)
                    {
                        if (!BlockCheck.BlockCheckLeft(pos.X - bps.X, pos.Y, (int)size.Y, speed) &&
                            pos.X - bps.X > 0)
                        {
                            pos.X -= bps.X;
                        }
                    }
                    else
                    {
                        if (!BlockCheck.BlockCheckRight(pos.X + bps.X, pos.Y, (int)size.X, (int)size.Y, speed) &&
                            pos.X + bps.X < 1024 - (int)size.X)
                        {
                            pos.X += bps.X;
                        }
                    }

                    if (!BlockCheck.BlockCheckTop(pos.X, pos.Y - bps.Y, (int)size.X, jumppower) &&
                        pos.Y - bps.Y > 0)
                    {
                        pos.Y -= bps.Y;
                    }



                    total.X += Math.Sqrt(Math.Pow(bps.X, 2));
                    total.Y += Math.Sqrt(Math.Pow(bps.Y, 2));

                    bps.X += bps.X;
                    bps.Y += bps.Y;

                    coefficient++;
                }
                else
                {
                    boundDir = true;
                    total.Y  = target.Y;
                }
            }
            else
            {
                if (total.Y > 0)
                {
                    if (!charaDir)
                    {
                        if (!BlockCheck.BlockCheckLeft(pos.X - bps.X, pos.Y, (int)size.Y, speed) &&
                            pos.X - bps.X > 0)
                        {
                            pos.X -= bps.X;
                        }
                    }
                    else
                    {
                        if (!BlockCheck.BlockCheckRight(pos.X + bps.X, pos.Y, (int)size.X, (int)size.Y, speed) &&
                            pos.X + bps.X < 1024 - (int)size.X)
                        {
                            pos.X += bps.X;
                        }
                    }

                    if (!BlockCheck.BlockCheckBottom(pos.X, pos.Y + bps.Y, (int)size.X, (int)size.Y, weight) &&
                        pos.Y + bps.Y < 768 - (int)size.Y)
                    {
                        pos.Y += bps.Y;
                    }

                    total.X += Math.Sqrt(Math.Pow(bps.X, 2));
                    total.Y -= Math.Sqrt(Math.Pow(bps.Y, 2));

                    bps.X += bps.X;
                    bps.Y += bps.Y;

                    coefficient--;
                }
                else
                {
                    boundDir    = false;
                    isKnockBack = false;
                }
            }
        }