예제 #1
0
        void RunGameLogic(float frameTimeInSeconds)
        {
            try
            {
                if (gamePaused == false)
                {
                    frameTime = frameTimeInSeconds;

                    if ((balloonLaunched == true) &&
                        (explosionSprite.Visible == false) &&
                        (balloonSprite.Parent != null) &&
                        (balloonSprite.PositionY >= 0) &&
                        ((balloonSprite.PositionY - balloonSprite.ContentSize.Height) <= layerHeight) &&
                        (balloonSprite.PositionX + balloonSprite.ContentSize.Width >= 0) &&
                        ((balloonSprite.PositionX - balloonSprite.ContentSize.Width) <= layerWidth))
                    {
                        // If balloon was just launched, wobble it and perform other operations.
                        if ((bool)balloonSprite.UserData == true)
                        {
                            if (touchForce >= 4)
                            {
                                CCRotateBy rotateBackBy        = new CCRotateBy(0.12f, -20);
                                CCRotateBy rotateForthBy       = new CCRotateBy(0.12f, 20);
                                CCRotateBy rotateBackFasterBy  = new CCRotateBy(0.06f, -10);
                                CCRotateBy rotateForthFasterBy = new CCRotateBy(0.06f, 10);
                                CCSequence launchSequence      = new CCSequence(rotateBackBy, rotateForthBy, rotateForthBy, rotateBackBy, rotateBackFasterBy, rotateForthFasterBy,
                                                                                rotateForthFasterBy, new CCRotateTo(0.25f, 0));

                                balloonSprite.RunAction(launchSequence);

                                balloonSprite.UserData = false;
                            }

                            touchForce = 0;
                        }

                        newBalloonYVelocity     -= frameTimeInSeconds * GAME_GRAVITY * 1000;
                        balloonSprite.PositionX += balloonXVelocity * frameTimeInSeconds * 1000 + (windBlowingRight == true ? 1 : -1) * windSpeed * frameTimeInSeconds * 100;
                        balloonSprite.PositionY -= ((newBalloonYVelocity * newBalloonYVelocity) - (balloonYVelocity * balloonYVelocity)) / GAME_GRAVITY;
                        balloonYVelocity         = newBalloonYVelocity;

                        if (CheckForExplosion() == true)
                        {
                            ExplodeBalloon();
                        }
                        else
                        {
                            if ((DateTime.Now.Subtract(lastGameVariationTime).TotalSeconds > GAME_VARIATION_FREQUENCY))
                            {
                                ChangeWindSpeed(false);
                            }

                            SetStopwatch();
                        }
                    }
                    else if ((balloonLaunched == false) &&
                             (balloonSprite.PositionY <= 0) &&
                             (balloonSprite.Parent != null) &&
                             ((DateTime.Now.Subtract(lastPlayTime).TotalSeconds > REMINDER_ALERT_DURATION)))
                    {
                        Task balloonReminderTask = new Task(async() =>
                        {
                            await balloonSprite.RunActionsAsync(new CCScaleTo(0.10f, 1.5f), new CCScaleTo(0.10f, 1f));
                            await balloonSprite.RunActionsAsync(new CCScaleTo(0.10f, 1.5f), new CCScaleTo(0.10f, 1f));
                        });

                        lastPlayTime = DateTime.Now;

                        balloonReminderTask.Start();
                    }
                }

                UpdateDebugData();
            }
            catch (Exception runGameLogicException)
            {
                errorLog += "\r\n\r\n" + DateTime.Now.ToString() + ": " + runGameLogicException;
            }
        }