Ejemplo n.º 1
0
    void FixedUpdate()
    {
        float randomTicket = Random.Range(0f, 1f);

        if (randomTicket >= 0f && randomTicket < spawnFrequency / 3000) // 3000 calls in min
        {
            FallingItem clone = Instantiate(target);
            clone.transform.localPosition = new Vector2(Random.Range(-11f, 11f), cameraSize + 1);
            clone.transform.localScale   *= scale;
        }
    }
Ejemplo n.º 2
0
        public override void Update(GameTime gameTime)
        {
            controlLabel.Control = Global.Control;
            if (Global.MusicEnabled && MediaPlayer.State != MediaState.Playing)
            {
                MediaPlayer.Play(Global.GameplaySongs[Global.currentSongIndex]);
            }

            backGround.Image = Global.Backgrounds[Global.CurrentBackgroundIndex];
            if (Global.Control == ControlTypes.Swipe)
            {
                leftHelpButton.IsVisible  = false;
                rightHelpButton.IsVisible = false;
                //SpriteCollection["helperLabel"].Cast<SpriteLabel>().Text = "Swipe your finger left\n and right to move!";
            }
            else
            {
                leftHelpButton.IsVisible  = true;
                rightHelpButton.IsVisible = true;
                //SpriteCollection["helperLabel"].Cast<SpriteLabel>().Text = "Press the arrows to \nmove the character";
            }
            SpriteCollection["helperLabel"].Cast <SpriteLabel>().IsVisible = false;

            if (Global.PlayTutorial)
            {
                controlLabel.IsVisible = true;
                controlLabel.Scale     = new Vector2(1.5f);
                controlLabel.Position  = new Vector2((RenderTarget.Width - controlLabel.Width) / 2, (RenderTarget.Height - controlLabel.Height) / 2);
                SpriteCollection["helperLabel"].Cast <SpriteLabel>().IsVisible = true;
                elapsedBlinkTime  += gameTime.ElapsedGameTime;
                elapsedHelperTime += gameTime.ElapsedGameTime;
                elapsedGraceTime  += gameTime.ElapsedGameTime;

                if (elapsedGraceTime > timeToMove)
                {
                    controlLabel.Scale    = Vector2.SmoothStep(controlLabel.Scale, new Vector2(.5f), scaleStep);
                    scaleStep            += 0.03f;
                    controlLabel.Position = Vector2.SmoothStep(controlLabel.Position, new Vector2(RenderTarget.Width - controlLabel.Width - 30, 30), positionStep);
                    positionStep         += 0.03f;
                }

                if (elapsedBlinkTime > blinkTime)
                {
                    SpriteCollection["helperLabel"].Color = SpriteCollection["helperLabel"].Color == Color.White ? Color.Red : Color.White;

                    elapsedBlinkTime = TimeSpan.Zero;
                }

                if (elapsedHelperTime > helperTime)
                {
                    SpriteCollection["helperLabel"].Cast <SpriteLabel>().IsVisible = false;
                }

                if (elapsedGraceTime > graceTime)
                {
                    Global.PlayTutorial = false;
                }
            }
            else
            {
                if (player.CurrentState != CharacterState.Death)
                {
                    Global.ElapsedGameTime += gameTime.ElapsedGameTime;
                    elapsedSpawningTime    += gameTime.ElapsedGameTime;
                    elapsedDifficultyTime  += gameTime.ElapsedGameTime;
                    elapsedArrowTime       += gameTime.ElapsedGameTime;
                    timeLabel.Text          = String.Format("{0} :{1}", Global.ElapsedGameTime.Minutes.ToString("D2"), Global.ElapsedGameTime.Seconds.ToString("D2"));
                    timeLabel.Origin        = new Vector2(timeLabel.Width / 2, 0);
                    controlLabel.Control    = Global.Control;
                    controlLabel.IsVisible  = true;
                    if (elapsedArrowTime >= arrowFadeTime)
                    {
                        leftHelpButton.Color  = Color.Lerp(Color.White, Color.Transparent, startingArrowAlpha);
                        rightHelpButton.Color = leftHelpButton.Color;
                        startingArrowAlpha   += 0.02f;
                    }

                    if (elapsedDifficultyTime >= difficultyTime)
                    {
                        elapsedDifficultyTime = TimeSpan.Zero;
                        _level++;

                        switch (_level)
                        {
                        case 0:
                            FallingItem.FallingSpeed = 20;
                            difficultyTime           = startingDifficultyTime;
                            break;

                        case 1:
                            FallingItem.FallingSpeed = 23;
                            difficultyTime           = TimeSpan.FromSeconds(20f);
                            //badItems.Add(new Item(itemTextures[1], ItemType.Bad, true));
                            break;

                        case 2:
                            FallingItem.FallingSpeed = 24;
                            //badItems.Add(new Item(itemTextures[2], ItemType.Bad, true));
                            break;

                        case 3:
                            FallingItem.FallingSpeed = 26;
                            //badItems.Add(new Item(itemTextures[3], ItemType.Bad, true));
                            difficultyTime -= TimeSpan.FromSeconds(1f);
                            break;

                        case 4:
                            FallingItem.FallingSpeed = 28;
                            //badItems.Add(new Item(itemTextures[4], ItemType.Bad, true));
                            break;

                        case 5:
                            FallingItem.FallingSpeed = 30;
                            //badItems.Add(new Item(itemTextures[5], ItemType.Bad, true));
                            break;

                        case 6:
                            FallingItem.FallingSpeed = 32;
                            //badItems.Add(new Item(itemTextures[6], ItemType.Bad, true));
                            difficultyTime -= TimeSpan.FromSeconds(1f);
                            break;

                        case 7:
                            FallingItem.FallingSpeed = 34;
                            //badItems.Add(new Item(itemTextures[7], ItemType.Bad, true));
                            break;

                        case 8:
                            FallingItem.FallingSpeed = 36;
                            //badItems.Add(new Item(itemTextures[8], ItemType.Bad, true));
                            break;

                        case 9:
                            FallingItem.FallingSpeed = 38;
                            //badItems.Add(new Item(itemTextures[9], ItemType.Bad, true));
                            difficultyTime -= TimeSpan.FromSeconds(1f);
                            break;

                        case 10:
                            FallingItem.FallingSpeed = 40;
                            //badItems.Add(new Item(itemTextures[10], ItemType.Bad, true));
                            break;

                        case 11:
                            FallingItem.FallingSpeed = 42;
                            //badItems.Add(new Item(itemTextures[11], ItemType.Bad, true));
                            break;

                        case 12:
                            FallingItem.FallingSpeed = 44;
                            //badItems.Add(new Item(itemTextures[12], ItemType.Bad, true));
                            break;

                        case 13:
                            FallingItem.FallingSpeed = 46;
                            //badItems.Add(new Item(itemTextures[13], ItemType.Bad, true));
                            break;

                        case 14:
                            FallingItem.FallingSpeed = 48;
                            //badItems.Add(new Item(itemTextures[14], ItemType.Bad, true));
                            break;

                        default:
                            FallingItem.FallingSpeed = 50;
                            //badItems.Add(new Item(itemTextures[15], ItemType.Bad, true));
                            break;
                        }
                    }
#if WINDOWS
                    if (debug)
                    {
                        _elapsedDrawTime += gameTime.ElapsedGameTime;
                        if (_elapsedDrawTime > _drawTime)
                        {
                            _elapsedDrawTime = TimeSpan.Zero;
                            _fpsLabel.Text   = String.Format("FPS: {0} Speed: {1}", _drawCounter, FallingItem.FallingSpeed);
                            _drawCounter     = 0;
                        }
                        _fpsLabel.IsVisible = true;
                    }
#endif
                    if (_lastSpwaned.CanSpawn)
                    {
                        SpawnFallingObjects();
                    }

                    if (_level >= 1)
                    {
                        if (startingAlpha > endingAlpha)
                        {
                            startingAlpha -= 0.02f;
                        }
                    }
                    timeLabel.Color    = new Color(0, 0, 0, startingAlpha);
                    controlLabel.Color = new Color(255, 255, 255, startingAlpha);

                    //checks if any items hit the ground
                    for (int i = 0; i < _columns.Length; i++)
                    {
                        if (_columns[i].FallingItems.Count > 0)
                        {
                            FallingItem item = _columns[i].FallingItems[0];
                            if (item.BoundingBox.Bottom > player.BoundingBox.Top + player.BoundingBox.Height / 2)
                            {
                                item.Fade = true;
                            }
                        }
                    }

                    if (_columns[playerIndex].CheckHit(player))
                    {
                        if (player.CurrentState == CharacterState.Idle)
                        {
                            player.CurrentState = CharacterState.Death;
                            foreach (Column colum in _columns)
                            {
                                colum.Reset();
                            }

                            if (Global.SFXEnabled)
                            {
                                deathSound.Play();
                            }
                        }
                        else
                        {
                            hitDuringAnimation = true;
                        }
                    }
                }
            }

            if (player.CurrentState != CharacterState.Death)
            {
                switch (direction)
                {
                case Direction.None:
                    player.CurrentState = CharacterState.Idle;

                    if (Global.Control == ControlTypes.Tap)
                    {
                        handleInput();
                        if (direction != Direction.None)
                        {
                            sw.Start();
                            player.CurrentState = CharacterState.Moving;
                        }
                        if (direction == Direction.Right)
                        {
                            player.Effect = SpriteEffects.FlipHorizontally;
                        }
                        else if (direction == Direction.Left)
                        {
                            player.Effect = SpriteEffects.None;
                        }
                    }

                    break;

                case Direction.Left:

                    CheckLocation();

                    break;

                case Direction.Right:
                    CheckLocation();

                    break;
                }
            }

            base.Update(gameTime);
        }