Example #1
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);
        }
//frameupdate
        protected void FrameUpdateTimer_Update(object sender, ElapsedEventArgs e)
        {
            try
            {
                this.Dispatcher.Invoke(() =>
                {
                    //TimeManagement
                    this.GetNowTime();
                    elapsedTime = nowTime - lastTime;

                    //debug
                    lblDebugA.Content = PlayerStatus.playerPos.X + "," + PlayerStatus.playerPos.Y;
                    lblDebugB.Content = SystemOperator.PixelPerSecond(PlayerStatus.weight);

                    if (elapsedTime < 0)
                    {
                        elapsedTime += 59999;
                    }


                    KeyController.KeyInterval();

                    //GameTransition
                    if (!GameTransition.duringTransition)
                    {
                        GameTransition.GameTransitionController(Canvas, CaLife, CaMana);
                    }

                    //EventAction



                    if (GameTransition.eventStart)
                    {
                        if (GameTransition.lstEventTask.Count > 0)
                        {
                            GameTransition.EventTaskCommander();
                        }


                        if (GameTransition.charaRenderStart)
                        {
                            GameTransition.CharaRender();
                        }

                        if (GameTransition.screenFadeStart)
                        {
                            GameTransition.ScreenFade(Canvas);
                        }

                        if (!GameTransition.eventBalloonIsOpen)
                        {
                            if (GameTransition.eventCount < StageEvent.listEvent.Count)
                            {
                                GameTransition.EventController(Canvas);
                            }
                        }
                        else
                        {
                            if (KeyController.keyReturn)
                            {
                                EnterKeyAction(Canvas);
                            }
                        }
                    }

                    if (KeyController.keyReturn)
                    {
                        EnterKeyAction(Canvas);
                    }

                    //got to Edit Mode
                    if (GameTransition.gameTransition == GameTransitionType.Title)
                    {
                        if (KeyController.keyE)
                        {
                            mainCanvas.Children.Remove(ImageData.imgTitle[0]); mainCanvas.Children.Remove(ImageData.imgTitle[1]);
                            countTime = 0;
                            GameTransition.gameTransition = GameTransitionType.EditMode;
                            timerFrameUpdate.Stop();
                            btnViewStageEditorWindow.IsEnabled = true;
                            btnViewMaterialBrowser.IsEnabled   = true;
                            btnViewImageManager.IsEnabled      = true;
                            btnViewDatabaseWindow.IsEnabled    = true;

                            lblMode.Content = "ゲームモード:エディット";
                        }
                    }

                    //StageDuring game play
                    if (GameTransition.gameTransition == GameTransitionType.StageDuring &&
                        !isDeactivated)
                    {
                        Animator.AnimationItem();
                        Animator.AnimationObject();

                        if (ObjectChecker.isTrigger && !TalkCommander.isTalk)
                        {
                            ObjectBehavior.OnTriggerTouchEvent();
                        }

                        if (TalkCommander.isTalk && !TalkCommander.isTalkOpenBalloon)
                        {
                            TalkCommander.TalkWithNpc(Canvas);
                        }

                        if (TalkCommander.isTalkSelecting)
                        {
                            TalkCommander.TalkSelecting(Canvas);
                        }

                        //first action,last Processing including deletion of list
                        SystemOperator.moveCommonAmountX = 0;
                        SystemOperator.moveCommonAmountY = 0;

                        ObjectChecker.CollisionPtoActionCollider();
                        PlayerBehavior.CollisionPtoE();

                        PlayerBehavior.MovePlayer(Canvas);
                        PlayerBehavior.FallingPlayer();

                        Item.FallingItems();

                        EnemyBehavior.EnemyAction();
                        Animator.AnimationEnemy();

                        SubWeapon.SubWeaponPosUpdate(Canvas);

                        if (PlayerStatus.isMainAttack)
                        {
                            MainWeapon.MainWeaponAttack(Canvas);
                            MainWeapon.MainWeaponCollision(Canvas);
                        }


                        SubWeapon.CollisionSubWeapon(Canvas);

                        PlayerStatus.PlayerStatusUpdate();
                        PlayerBehavior.DamageInvinsibleTimer();

                        SpawnEnemy.RemoveEnemy(Canvas);
                        SpawnEnemy.ReSpawnEnemy(Canvas);
                    }

                    if (Sound.seStop)
                    {
                        if (Sound.sePlayTime < 60)
                        {
                            Sound.sePlayTime++;
                        }
                        else
                        {
                            Sound.sePlayTime = 0;
                            Sound.seStop     = false;
                        }
                    }

                    lastTime = nowTime;
                });
            }
            catch (TaskCanceledException)
            {
            }
        }