Example #1
0
        public override void Update()
        {
            if (active != null)
            {
                Visual.Update();
                if (Globals.nextBlock.p >= Globals.wave.get_data_p() + Globals.wave.get_data_size())
                {
                    Globals.wave.reset();
                }
            }
            if (focused)
            {
                //SCROLL UPDATE
                songbar.Update();
                int Offset = songbar.ScaledMove();

                //BUTTON UPDATE
                foreach (SongButton song in Songs)
                {
                    song.Move(new Vector2(-Offset, 0));
                    song.Update();
                }


                Point pos = Globals.currentMouseState.Position;
                foreach (SongButton s in Songs)
                {
                    //Checks for mouse hovering over songbuttons
                    if (s.Collide(pos))//check collision
                    {
                        if (Globals.currentMouseState.LeftButton == ButtonState.Released &&
                            clicked == s &&//THIS METHOD MAKES SURE YOU CANNOT RESELECT THE SAME SONG
                            Math.Pow((pressedpoint - Globals.currentMouseState.Position).X, 2) + Math.Pow((pressedpoint - Globals.currentMouseState.Position).Y, 2) < 10000)
                        {
                            if (active != s)
                            {
                                active = s;
                                bg     = s.texture;
                                if (Globals.wave != null)
                                {
                                    Globals.wave.reset();         //reset previous song
                                }
                                Globals.wave      = active.music; //new song
                                Globals.waveAudio = new Audio(Globals.wave, 0);
                                Visual            = new Visualizer(Globals.wave);
                            }
                        }
                        if (Globals.currentMouseState.LeftButton == ButtonState.Pressed &&
                            Globals.previousMouseState.LeftButton == ButtonState.Released)
                        {
                            clicked      = s;
                            pressedpoint = Globals.currentMouseState.Position;
                        }
                        if (Globals.currentMouseState.LeftButton == ButtonState.Released)
                        {
                            clicked = null;
                        }

                        s.Glow();//applies a glow effect
                    }
                }
                //DRAGGING SCREEN     move the screen with mouse/touchscreen
                if (Globals.currentMouseState.LeftButton == ButtonState.Pressed &&
                    0 < Globals.currentMouseState.Position.Y &&
                    Globals.currentMouseState.Position.Y < Options.Resolutions.Y * 4 / 5 &&
                    !songbar.pressed)
                {
                    if (Globals.currentMouseState.Position.X - Globals.previousMouseState.Position.X > 250)//added to avoid bug when click, release,click
                    {
                        dragspeed = 1;
                    }
                    else if (Globals.currentMouseState.Position.X - Globals.previousMouseState.Position.X < -250)
                    {
                        dragspeed = -1;
                    }
                    else
                    {
                        dragspeed = (Globals.currentMouseState.Position.X - Globals.previousMouseState.Position.X) / 4;
                    }
                }
                if (Globals.currentMouseState.LeftButton == ButtonState.Released)
                {
                    if (dragspeed > 0)
                    {
                        dragspeed -= .4;
                        if (dragspeed < .3)
                        {
                            dragspeed = 0;
                        }
                    }
                    else if (dragspeed < 0)
                    {
                        dragspeed += .4;
                        if (dragspeed > -.3)
                        {
                            dragspeed = 0;
                        }
                    }
                }
                songbar.bar.X -= (int)dragspeed;
                songbar.Update();

                //Button update-check for collisions
                if (Globals.previousMouseState.LeftButton == ButtonState.Pressed && Globals.currentMouseState.LeftButton == ButtonState.Released)
                {
                    if (Play.Collide(pos))
                    {
                        //this.manager.RegisterScene("Play", new LevelScene());
                        this.manager.AlmostCurrentScenes.Add("Background");
                        this.manager.AlmostCurrentScenes.Add("Level");
                        Globals.pathToCurrentMap         = active.dmlfile;
                        Globals.songname                 = active.title;
                        this.manager.transitioningScenes = true;
                        this.manager.FocusOn("Level");
                    }
                    if (Back.Collide(pos))
                    {
                        this.manager.AlmostCurrentScenes.Add("Background");
                        this.manager.AlmostCurrentScenes.Add("Main Menu");
                        this.manager.FocusOn("Main Menu");
                        this.manager.transitioningScenes = true;
                    }
                }
            }
        }