Пример #1
0
        private void resetHealth()
        {
            if (_fallingObjects.Count > 30)
            {
                return;
            }

            CCSprite health = (CCSprite)_healthPool[_healthPoolIndex];

            _healthPoolIndex++;
            if (_healthPoolIndex == _healthPool.Count)
            {
                _healthPoolIndex = 0;
            }

            int health_x        = CCRandom.GetRandomInt(0, 1000) % (int)(_screenSize.Width * 0.8f + _screenSize.Width * 0.1f);
            int health_target_x = CCRandom.GetRandomInt(0, 1000) % (int)(_screenSize.Width * 0.8f + _screenSize.Width * 0.1f);

            health.StopAllActions();
            health.Position = new CCPoint(health_x, _screenSize.Height + health.BoundingBox.Size.Height * 0.5f);

            //create action (swing, move to target, and call function when done)
            CCFiniteTimeAction sequence = new CCSequence(
                new CCMoveTo(_healthSpeed, new CCPoint(health_target_x, _screenSize.Height * 0.15f)),
                new CCCallFuncN(fallingObjectDone));

            health.Visible = true;
            health.RunAction(_swingHealth);
            health.RunAction(sequence);
            _fallingObjects.Add(health);
        }
Пример #2
0
        /// <summary>
        /// Иговой цикл на экране с меню - падающие крисстальчики на фоне
        /// </summary>
        private void UpdateGems()
        {
            if (CCRandom.NextDouble() < 0.02)
            {
                var type   = CCRandom.GetRandomInt(0, 4);
                var sprite = new CCSprite("crystalscrystals/" + type + ".png");
                var x      = CCRandom.NextDouble() * CCDirector.SharedDirector.WinSize.Width + Constants.KGemSize / 2;
                var y      = CCDirector.SharedDirector.WinSize.Height + Constants.KGemSize / 2;
                var scale  = 0.2 + 0.8 * CCRandom.NextDouble();
                var speed  = 2 * scale * Constants.KGemSize / 40;
                sprite.Position = new CCPoint((float)x, (float)y);
                sprite.Scale    = (float)scale;
                _fallingGems.Add(sprite, (float)speed);
                _background.AddChild(sprite);
            }

            var gems = _fallingGems.Keys.ToArray();

            foreach (var gem in gems)
            {
                var speed = _fallingGems[gem];
                var pos   = gem.Position;
                gem.Position = pos - new CCPoint(0, speed);
                if (pos.Y < -Constants.KGemSize / 2)
                {
                    _background.RemoveChild(gem, true);
                    _fallingGems.Remove(gem);
                }
            }
        }
Пример #3
0
        void PositionMonkey()
        {
            // We start our rotation with an offset of 230,0 from the origin 0 degrees
            // and randomly position the monkey
            var startingAngle = CCRandom.GetRandomInt(-360, 360);

            monkey.Position = CCPoint.RotateByAngle(origin + new CCPoint(230, 0), origin, CCMathHelper.ToRadians(startingAngle));
            positioned      = true;
        }
Пример #4
0
        // Our main game logic (float is so we can schedule it, if we set it in the function it avoids recreating the function)
        void PickRandomMole(float time = 0f)
        {
            // Make sure we're in game
            if (currentState == GameState.Game)
            {
                // Activate a random mole
                moles[CCRandom.GetRandomInt(0, moles.Count)].ActivateMole(moleVisibleFor);

                // Recursion.
                // I don't use Schedule because the time keeps changing
                ScheduleOnce(PickRandomMole, timeBetweenMoles);
            }
        }
Пример #5
0
        void StripedBackground()
        {
            if (backGround != null)
            {
                backGround.RemoveFromParent();
            }

            // Use the bounds to layout the positioning of our drawable assets
            CCRect bounds = VisibleBoundsWorldspace;

            var backGroundColor = RandomBrightColor();
            var stripeColor     = RandomBrightColor();

            int minStripes = 4;
            int maxStripes = 10;

            // generate an even number of stripes or we will see offset patterns when using
            // linear wrap and scrolling.
            int numberOfStripes = 2 * CCRandom.GetRandomInt(minStripes / 2, maxStripes / 2);

            CCLog.Log("number of stripes " + numberOfStripes);

            backGround = new StripeWithColor(backGroundColor, stripeColor, 512, 512, numberOfStripes);

            backGround.AnchorPoint = CCPoint.AnchorLowerLeft;

            // MUST be power of 2 in order to create a continue effect.
            // eg: 32x64, 512x128, 256x1024, 64x64, etc..
            var textureWidth  = bounds.Size.Width.NextPOT();
            var textureHeight = bounds.Size.Height.NextPOT();

            backGround.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap;

            // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize
            backGround.TextureRectInPixels = new CCRect(0, 0, textureWidth, textureHeight);
            backGround.ContentSize         = backGround.TextureRectInPixels.Size;

            AddChild(backGround, -1);
        }
Пример #6
0
        private void resetMeteor()
        {
            //if too many objects on screen, return
            if (_fallingObjects.Count > 30)
            {
                return;
            }


            CCSprite meteor = _meteorPool[_meteorPoolIndex];

            _meteorPoolIndex++;
            if (_meteorPoolIndex == _meteorPool.Count)
            {
                _meteorPoolIndex = 0;
            }

            //pick start and target positions for new meteor
            int meteor_x        = CCRandom.GetRandomInt(1, 1000) % (int)((_screenSize.Width * 0.8f) + _screenSize.Width * 0.1f);
            int meteor_target_x = CCRandom.GetRandomInt(1, 1000) % (int)((_screenSize.Width * 0.8f) + _screenSize.Width * 0.1f);

            meteor.StopAllActions();
            meteor.Position = new CCPoint(meteor_x, _screenSize.Height + meteor.BoundingBox.Size.Height * 0.5f);

            //create action for meteor (rotate forever, move to target, and call function)
            CCRotateBy         rotate       = new CCRotateBy(0.5f, -90);
            CCAction           repeatRotate = new CCRepeatForever(rotate);
            CCFiniteTimeAction sequence     = new CCSequence(
                new CCMoveTo(_meteorSpeed, new CCPoint(meteor_target_x, _screenSize.Height * 0.15f)),
                new CCCallFuncN(fallingObjectDone));

            meteor.Visible = true;
            meteor.RunAction(repeatRotate);
            meteor.RunAction(sequence);
            _fallingObjects.Add(meteor);
        }
Пример #7
0
        byte RandomColorValue()
        {
            var random = CCRandom.GetRandomInt(0, 255);

            return((byte)random);
        }
Пример #8
0
        public void Connect(Action callbackMethod)
        {
            Task connectionTask;

            deviceName  = (String.IsNullOrWhiteSpace(deviceName) ? "iOS_" + CCRandom.GetRandomInt(0, 100) : deviceName);
            isCompleted = false;
            isConnected = false;

            connectionTask = new Task(async() =>
            {
                int locatorTimeout           = bridgeLocatorTimeout;
                Exception currentException   = new Exception();
                IBridgeLocator bridgeLocator = new HttpBridgeLocator();
                IEnumerable <LocatedBridge> locatedBridges = new List <LocatedBridge>();

                try
                {
                    locatedBridges = await bridgeLocator.LocateBridgesAsync(TimeSpan.FromSeconds(locatorTimeout));

                    if (((List <LocatedBridge>)locatedBridges).Count > 0)
                    {
                        while (((currentException.Source == null) ||
                                (currentException.Message == "Link button not pressed")) &&
                               (locatorTimeout >= 0))
                        {
                            try
                            {
                                hueClient = new LocalHueClient(((List <LocatedBridge>)locatedBridges)[0].IpAddress);

                                if (hueClient != null)
                                {
                                    if (await hueClient.CheckConnection() == false)
                                    {
                                        if (String.IsNullOrWhiteSpace(hueAppKey) == true)
                                        {
                                            hueAppKey = await hueClient.RegisterAsync(appName, deviceName);
                                        }

                                        if (String.IsNullOrWhiteSpace(hueAppKey) == false)
                                        {
                                            hueClient.Initialize(hueAppKey);

                                            colorBulbs = ((List <Light>) await hueClient.GetLightsAsync());

                                            for (int i = 0; i < colorBulbs.Count; i++)
                                            {
                                                if (colorBulbs[i].Type != "Extended color light")
                                                {
                                                    colorBulbs.RemoveAt(i);

                                                    i--;
                                                }
                                            }

                                            isConnected = true;

                                            break;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            catch (Exception connectionException)
                            {
                                currentException = connectionException;
                            }

                            await Task.Delay(1000);

                            locatorTimeout--;
                        }
                    }
                }
                catch (Exception bridgeLocatorException)
                {
                    currentException = bridgeLocatorException;
                }

                isCompleted = true;

                callbackMethod();
            });

            connectionTask.Start();
        }
Пример #9
0
        private void GameLoop()
        {
            if (!_isGameOver)
            {
                RemoveMarkedGems();

                int        x;
                FallingGem gem;

                // Add falling gems
                for (x = 0; x < Constants.KBoardWidth; x++)
                {
                    if (_numGemsInColumn[x] + _fallingGems[x].Count < Constants.KBoardHeight &&
                        _timeSinceAddInColumn[x] >= Constants.KTimeBetweenGemAdds)
                    {
                        // A gem should be added to this column!
                        var gemType   = CCRandom.GetRandomInt(0, 4);
                        var gemSprite = new CCSprite("crystalscrystals/" + gemType + ".png");
                        gemSprite.Position    = new CCPoint(_fieldPositionZero.X + x * Constants.KGemSize, _fieldPositionZero.Y + Constants.KBoardHeight * Constants.KGemSize);
                        gemSprite.AnchorPoint = CCPoint.Zero;

                        gem = new FallingGem()
                        {
                            gemType = gemType, sprite = gemSprite, yPos = Constants.KBoardHeight, ySpeed = 0
                        };
                        _fallingGems[x].Add(gem);

                        _gameBoardLayer.AddChild(gemSprite);

                        _timeSinceAddInColumn[x] = 0;
                    }

                    _timeSinceAddInColumn[x]++;
                }

                #region Move falling gems
                var gemLanded = false;
                for (x = 0; x < Constants.KBoardWidth; x++)
                {
                    var column         = _fallingGems[x];
                    var numFallingGems = _fallingGems[x].Count;
                    for (var i = numFallingGems - 1; i >= 0; i--)
                    {
                        gem = column[i];

                        gem.ySpeed += 0.06f;
                        gem.ySpeed *= 0.99f;
                        gem.yPos   -= gem.ySpeed;

                        if (gem.yPos <= _numGemsInColumn[x])
                        {
                            // The gem hit the ground or a fixed gem
                            if (!gemLanded)
                            {
                                CCSimpleAudioEngine.SharedEngine.PlayEffect("Sounds/tap-" + CCRandom.Next(0, 4) + ".wav");
                                gemLanded = true;
                            }

                            column.RemoveAt(i);

                            // Insert into board
                            var y = _numGemsInColumn[x];

                            if (_board[x + y * Constants.KBoardWidth] != -1)
                            {
                                Debug.WriteLine("Warning! Overwriting board idx: " + x + y * Constants.KBoardWidth + " type: " + _board[x + y * Constants.KBoardWidth]);
                            }

                            _board[x + y * Constants.KBoardWidth]        = gem.gemType;
                            _boardSprites[x + y * Constants.KBoardWidth] = gem.sprite;

                            // Update fixed position
                            gem.sprite.Position = new CCPoint(_fieldPositionZero.X + x * Constants.KGemSize, _fieldPositionZero.Y + y * Constants.KGemSize);
                            _numGemsInColumn[x]++;

                            _boardChangedSinceEvaluation = true;
                        }
                        else
                        {
                            // Update the falling gems position
                            gem.sprite.Position = new CCPoint(_fieldPositionZero.X + x * Constants.KGemSize, _fieldPositionZero.Y + gem.yPos * Constants.KGemSize);
                        }
                    }
                }
                #endregion

                // Check if there are possible moves and no gems falling
                var isFallingGems = false;
                for (x = 0; x < Constants.KBoardWidth; x++)
                {
                    if (_numGemsInColumn[x] != Constants.KBoardHeight)
                    {
                        isFallingGems = true;
                        break;
                    }
                }

                if (!isFallingGems)
                {
                    var possibleMove = FindMove();
                    if (possibleMove == -1)
                    {
                        // Create a possible move
                        CreateRandomMove();
                    }
                }

                // Update timer
                var currentTime = DateTime.Now;
                var elapsedTime = (currentTime - _startTime).TotalMilliseconds / Constants.KTotalGameTime;
                var timeLeft    = (1 - elapsedTime) * 100;
                if (timeLeft < 0)
                {
                    timeLeft = 0;
                }
                if (timeLeft > 99.9)
                {
                    timeLeft = 99.9;
                }

                _timer.Percentage = (float)timeLeft;

                // Update consecutive moves / powerplay
                if ((currentTime - _lastMoveTime).TotalMilliseconds > Constants.KMaxTimeBetweenConsecutiveMoves)
                {
                    _numConsecutiveGems = 0;
                }
                UpdatePowerPlay();

                // Update sparkles
                UpdateSparkles();

                // Check if timer sound should be played
                if (timeLeft < 6.6 && !_endTimerStarted)
                {
                    CCSimpleAudioEngine.SharedEngine.PlayEffect("Sounds/timer.wav");
                    _endTimerStarted = true;
                }

                // Check for game over
                if (timeLeft < 0.000001f)
                {
                    CreateGameOver();
                    RunOutroAnimations();
                    _isGameOver = true;
                    CCSimpleAudioEngine.SharedEngine.PlayEffect("Sounds/endgame.wav");
                    MainSceneLayer.LastScore = _score;
                }
                else if ((currentTime - _lastMoveTime).TotalMilliseconds > Constants.KDelayBeforeHint && !_isDisplayingHint)
                {
                    DisplayHint();
                }
            }
            else
            {
                UpdateGameOver();
            }
        }
Пример #10
0
        //---------------------------------------------------------------------------------------------------------
        // GetRandomBubbleColor
        //---------------------------------------------------------------------------------------------------------
        // Gets a random bubble sprite color

        static string GetRandomBubbleColor()
        {
            var randomColorSprite = (BubbleColors)CCRandom.GetRandomInt((int)BubbleColors.blue, (int)BubbleColors.yellow);

            return("bubble-std-" + randomColorSprite + ".png");
        }
Пример #11
0
 private void InitGraphic()
 {
     _graphic = new CCSprite(String.Format("/Assets/Content/Images/Periphery/cloud{0}.png", CCRandom.GetRandomInt(1, 2)));
     _graphic.IsAntialiased = false;
     _graphic.Opacity       = 128;
     _graphic.Position      = new CCPoint(_graphic.ContentSize.Width * 0.5f, _graphic.ContentSize.Height / 2);
     _graphic.AnchorPoint   = new CCPoint(0.0f, 0.0f);
     AddChild(_graphic);
 }
Пример #12
0
        //---------------------------------------------------------------------------------------------------------
        // GetRandomBonusType
        //---------------------------------------------------------------------------------------------------------
        // Randomly chooses a bonus bubble type
        //---------------------------------------------------------------------------------------------------------
        // TODO: Bonus bubbles that are the same as consumables need to be more rare so the player is encouraged to
        // buy them with their coins.
        //---------------------------------------------------------------------------------------------------------

        public Bonuses GetRandomBonusType()
        {
            Bonuses bonusType = Bonuses.unused;
            int     random;
            int     upperRandomRange = 0;

            if (currentLevel.BonusAddition)
            {
                upperRandomRange    += BWEIGHT_ADDITION;
                bWeightTotalAddition = upperRandomRange;
            }
            if (currentLevel.BonusBonusMF)
            {
                upperRandomRange   += BWEIGHT_BONUS_MF;
                bWeightTotalBonusMF = upperRandomRange;
            }
            if (currentLevel.BonusCheckpoint)
            {
                upperRandomRange      += BWEIGHT_CHECKPOINT;
                bWeightTotalCheckpoint = upperRandomRange;
            }
            if (currentLevel.BonusDoubleScore)
            {
                upperRandomRange       += BWEIGHT_DOUBLE_SCORE;
                bWeightTotalDoubleScore = upperRandomRange;
            }
            if (currentLevel.BonusMystery)
            {
                upperRandomRange   += BWEIGHT_MYSTERY;
                bWeightTotalMystery = upperRandomRange;
            }
            if (currentLevel.BonusNegPoints)
            {
                upperRandomRange     += BWEIGHT_NEG_POINTS;
                bWeightTotalNegPoints = upperRandomRange;
            }
            if (currentLevel.BonusNegTime)
            {
                upperRandomRange   += BWEIGHT_NEG_TIME;
                bWeightTotalNegTime = upperRandomRange;
            }
            if (currentLevel.BonusNextInSeq)
            {
                upperRandomRange     += BWEIGHT_NEXT_IN_SEQ;
                bWeightTotalNextInSeq = upperRandomRange;
            }
            if (currentLevel.BonusNextMF)
            {
                upperRandomRange  += BWEIGHT_NEXT_MF;
                bWeightTotalNextMF = upperRandomRange;
            }
            if (currentLevel.BonusPosPoints)
            {
                upperRandomRange     += BWEIGHT_POS_POINTS;
                bWeightTotalPosPoints = upperRandomRange;
            }
            if (currentLevel.BonusPosTime)
            {
                upperRandomRange   += BWEIGHT_POS_TIME;
                bWeightTotalPosTime = upperRandomRange;
            }
            if (currentLevel.BonusSubtraction)
            {
                upperRandomRange       += BWEIGHT_SUBTRACTION;
                bWeightTotalSubtraction = upperRandomRange;
            }
            if (currentLevel.BonusTapStrength)
            {
                upperRandomRange       += BWEIGHT_TAP_STR;
                bWeightTotalTapStrength = upperRandomRange;
            }
            if (currentLevel.BonusTripleScore)
            {
                upperRandomRange       += BWEIGHT_TRIPLE_SCORE;
                bWeightTotalTripleScore = upperRandomRange;
            }
            if (currentLevel.BonusLuckyPointChance)
            {
                upperRandomRange            += BWEIGHT_LUCKY_POINT_CHANCE;
                bWeightTotalLuckyPointChance = upperRandomRange;
            }
            if (currentLevel.BonusLuckyPointAmount)
            {
                upperRandomRange            += BWEIGHT_LUCKY_POINT_AMOUNT;
                bWeightTotalLuckyPointAmount = upperRandomRange;
            }

            random = CCRandom.GetRandomInt(1, upperRandomRange);              // we make the lower end of the range a 1 because any unused weights will be 0

            if (random <= bWeightTotalAddition)
            {
                bonusType = Bonuses.addition;
            }
            else if (random <= bWeightTotalBonusMF)
            {
                bonusType = Bonuses.bonus_mf;
            }
            else if (random <= bWeightTotalCheckpoint)
            {
                bonusType = Bonuses.checkpoint;
            }
            else if (random <= bWeightTotalDoubleScore)
            {
                bonusType = Bonuses.double_score;
            }
            else if (random <= bWeightTotalMystery)
            {
                bonusType = Bonuses.mystery;
            }
            else if (random <= bWeightTotalNegPoints)
            {
                bonusType = Bonuses.neg_points;
            }
            else if (random <= bWeightTotalNegTime)
            {
                bonusType = Bonuses.neg_time;
            }
            else if (random <= bWeightTotalNextInSeq)
            {
                bonusType = Bonuses.next_in_seq;
            }
            else if (random <= bWeightTotalNextMF)
            {
                bonusType = Bonuses.next_mf;
            }
            else if (random <= bWeightTotalPosPoints)
            {
                bonusType = Bonuses.pos_points;
            }
            else if (random <= bWeightTotalPosTime)
            {
                bonusType = Bonuses.pos_time;
            }
            else if (random <= bWeightTotalSubtraction)
            {
                bonusType = Bonuses.subtraction;
            }
            else if (random <= bWeightTotalTapStrength)
            {
                bonusType = Bonuses.tap_str;
            }
            else if (random <= bWeightTotalTripleScore)
            {
                bonusType = Bonuses.triple_score;
            }
            else if (random <= bWeightTotalLuckyPointChance)
            {
                bonusType = Bonuses.lucky_point_chance;
            }
            else if (random <= bWeightTotalLuckyPointAmount)
            {
                bonusType = Bonuses.lucky_point_amount;
            }
            //TODO: need to add assignment for Big Pos TIME and POINTS
            return(bonusType);
        }
Пример #13
0
        //---------------------------------------------------------------------------------------------------------
        // GetRandomTapsToPop
        //---------------------------------------------------------------------------------------------------------
        // Determines taps to pop based on bonus type and difficulty level
        //---------------------------------------------------------------------------------------------------------

        public int GetRandomTapsToPop(Bonuses bonusType)
        {
            int tapsNeeded = MIN_EASY_TAPS;

            switch (bonusType)
            {
            case Bonuses.pos_time:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.double_score:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.pos_points:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.addition:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.subtraction:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.checkpoint:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.triple_score:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.next_in_seq:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.next_mf:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.bonus_mf:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.tap_str:
            {
                tapsNeeded = MIN_EASY_TAPS;
                break;
            }

            case Bonuses.neg_time:
            {
                tapsNeeded = 1;
                break;
            }

            case Bonuses.neg_points:
            {
                tapsNeeded = 1;
                break;
            }

            case Bonuses.mystery:
            {
                tapsNeeded = CCRandom.GetRandomInt(MIN_HARD_TAPS, MAX_HARD_TAPS);
                break;
            }

            case Bonuses.lucky_point_chance:
            {
                tapsNeeded = 1;
                break;
            }

            case Bonuses.lucky_point_amount:
            {
                tapsNeeded = 1;
                break;
            }
            }

            return(tapsNeeded);
        }