示例#1
0
        //public Task GetDetectionTask()
        //{

        //}

        public void DetectAndReportBeats()
        {
            detector.setStarted(true);

            while (true)
            {
                detector.update();

                lastBeat = detector.getLastBeat();

                //I'm sure no song has a bpm higher than 6000 so
                //it's safe to sleep 10ms before checking if a new beat has been detected
                //This will also save a lot of processing power.
                Thread.Sleep(10);
                if (detector.getLastBeat() != null && lastBeat != null)
                {
                    if (lastBeat.getMilliseconds() != detector.getLastBeat().getMilliseconds())
                    {
                        reportLastBeat();
                    }
                }
            }
        }
示例#2
0
        //move ALL tiles simultaneously
        private void gravity_Tick(object sender, EventArgs e)
        {
            if (hitBar.Value == 0)
            {
                //initialize gameover
                GameOver();
            }
            else
            {
                //detect beats
                detector.update();

                if (localLastbeat != detector.getLastBeat())
                {
                    //spawn here
                    Button    btn  = new Button();
                    myButtons butt = new myButtons();
                    btn.BackColor = butt.getBtnColor();
                    btn.FlatStyle = butt.getStyle();
                    btn.Size      = butt.getSize();
                    btn.Font      = butt.getFont();

                    btn.Location = butt.randLoc((rnd.Next(0, 4)));

                    if (btn.Location == new Point(0, -22))
                    {
                        btn.Text = "D";
                    }
                    else if (btn.Location == new Point(71, -22))
                    {
                        btn.Text = "F";
                    }
                    else if (btn.Location == new Point(142, -22))
                    {
                        btn.Text = "J";
                    }
                    else if (btn.Location == new Point(213, -22))
                    {
                        btn.Text = "K";
                    }

                    Controls.Add(btn);
                    btn.BringToFront();

                    //update last beat
                    localLastbeat = detector.getLastBeat();
                }

                //iterate through buttons

                foreach (Button item in Controls.OfType <Button>())
                {
                    if (item != start && item != loadSongs)
                    {
                        //check if item is beyond deleteLocation
                        if (item.Top > deleteLocation)
                        {
                            //remove form controls
                            Controls.Remove(item);
                            //dispose button in array
                            item.Dispose();
                        }
                        else
                        {
                            //move tiles per tick
                            item.Top += gamespeed;

                            if (item.Top > maxHit && item.BackColor == Color.Black)
                            {
                                item.BackColor = Color.Red;
                                item.Font      = new Font("Segoe UI", 9, FontStyle.Bold);
                                item.Text      = "Missed!";
                                penalty        = gamespeed * 10;
                                DeductBar(penalty);
                                //deduct hitbar value
                            }
                        }
                    }
                }
            }

            //display score
            scoreDisplay.Text = "Score: " + Convert.ToString(score);
            //get high Score
            SetHighScore();



            if (detector.isPlaying() == false)
            {
                GameOver();
            }
        }