Esempio n. 1
0
 public void Update(GameTime gameTime)
 {
     if (keyPressCooldown > 0)
     {
         keyPressCooldown--;
     }
     else
     {
         if (InputManager.GetValue("place"))
         {
             Game.CurrentRoom = Parent;
         }
     }
 }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            if (MediaPlayer.State == MediaState.Playing)
            {
                MediaPlayer.Stop();
            }
            bool selectPressed = InputManager.GetValue("place");
            bool upPressed     = InputManager.GetValue("up");
            bool downPressed   = InputManager.GetValue("down");
            bool exitPressed   = InputManager.GetValue("exit");

            if (BeginWaitCooldown < 0)
            {
                if (selectPressed && !prevSelectedPressed)
                {
                    BeginWaitCooldown = BeginWaitCooldownReset;
                    ButtonList[CurrentSelected].Value();
                }
                if (exitPressed && !prevExitPressed)
                {
                    Game.CurrentRoom = Parent;
                }
            }
            else
            {
                BeginWaitCooldown--;
            }
            if (upPressed && !prevUpPressed)
            {
                CurrentSelected--;
                if (CurrentSelected < 0)
                {
                    CurrentSelected = ButtonList.Count - 1;
                }
            }
            if (downPressed && !prevDownPressed)
            {
                CurrentSelected++;
                if (CurrentSelected >= ButtonList.Count)
                {
                    CurrentSelected = 0;
                }
            }

            prevUpPressed       = upPressed;
            prevDownPressed     = downPressed;
            prevSelectedPressed = selectPressed;
            prevExitPressed     = exitPressed;
        }
Esempio n. 3
0
        public virtual void Update(GameTime gameTime)
        {
            Music?.update();
            bool exitPressed = InputManager.GetValue("exit");

            if (exitPressed && !prevExitPressed)
            {
                PauseMusic();
                Game.CurrentRoom = Parent;
            }
            prevExitPressed = exitPressed;
            if (TimeBegan == 0)
            {
                //TimeBegan = (float)gameTime.TotalGameTime.TotalMilliseconds;
                PlayMusic();
            }
            if (TimeModifier == 0)
            {
                return;
            }
            float delta = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            //TimeElapsed += delta * TimeModifier;
            //TimeElapsed = (float)gameTime.TotalGameTime.TotalMilliseconds - TimeBegan;
            //time elapsed now takes from Music

            keyPresses = new bool[4];
            for (int i = 0; i < Columns.Length; i++)
            {
                keyPresses[i] = InputManager.GetValue("column" + i.ToString());
            }
            if (receiveInput)
            {
                for (int i = 0; i < Columns.Length; i++)
                {
                    List <float> column = Columns[i];
                    if (keyPresses[i] && !prevKeyPresses[i])
                    {
                        //we only care about the note closest to us
                        if (column.Count == 0)
                        {
                            continue;
                        }
                        int ind                 = 0; //given list is sorted smallest to largest
                        int noteY               = TimeToPosition(column[ind]);
                        int centerY             = noteY + (NoteHeight / 2);
                        int halfPressableHeight = NotePressableHeight / 2;
                        int dist                = Math.Max(Math.Abs(centerY - boardHeight) - (NoteHeight / 2), 0); //-noteheight/2 because it its perfect if we hit directly on the note
                        if (centerY - halfPressableHeight <= boardHeight && centerY + halfPressableHeight >= boardHeight)
                        {
                            //we have a hit
                            //calculate score
                            float accuracy = CalculateAccuracy(dist);
                            totalAccuracy += accuracy;
                            int score = (int)(accuracy * MaxNoteScore);
                            Score += score;
                            updateAccuracyMessage(GetAccuracyValue(accuracy));
                            //destroy the note
                            column.RemoveAt(ind);
                            notesAttempted++;
                        }
                        else
                        {
                            //we are hitting nothing. bad
                            //we dont actually care if the next note is too far away though
                            if (dist < hitIgnoreDistance)
                            {
                                updateAccuracyMessage(GetAccuracyValue(-1));
                                Score -= MaxNoteScore;
                                notesAttempted++;
                            }
                        }
                    }
                    for (int j = column.Count - 1; j >= 0; j--)
                    {
                        if (column[j] + NoteDestroyCushion < TimeElapsed)
                        {
                            column.RemoveAt(j);
                            Score -= MaxNoteScore;
                            notesAttempted++;
                        }
                    }
                }
                if (Randomized)
                {
                    if (randomNoteCooldown > 0)
                    {
                        randomNoteCooldown -= delta;
                    }
                    else
                    {
                        randomNoteCooldown = randomNoteCooldownReset;
                        //create a random note
                        int   column = GameMath.Choose(0, 1, 2, 3);
                        float time   = TimeElapsed + LookaheadTime;
                        Columns[column].Add(time);
                        Columns[column].Sort((a, b) => { return(Math.Sign(a - b)); });
                    }
                }
                if (TimeElapsed > TimeLength)
                {
                    //game end
                    Game.CurrentRoom = new EndRoom(Game, Parent, this); //intentionally make parent our parent so that we go back to map list
                }
            }

            if (timePositionFixCooldown > 0)
            {
                timePositionFixCooldown--;
            }
            else if (setMusicPositionToUsCooldown < 0)
            {
                if (hasSetMusicPositionToUs)
                {
                    timePositionFixCooldown = timePositionFixCooldownReset;
                    if ((TimeModifier == 0) != (!Music.isPlaying()))
                    {
                        if (TimeModifier == 0)
                        {
                            PauseMusic();
                        }
                        else
                        {
                            PlayMusic((uint)TimeElapsed);
                        }
                    }
                    if (Music.isPlaying())
                    {
                        float timeDifference = Music.GetTotalMilliseconds() - TimeElapsed;
                        if (Math.Abs(timeDifference) > timeEpsilon)
                        {
                            totalTimeDifference -= timeDifference;
                            System.Diagnostics.Debug.WriteLine("total time difference: " + totalTimeDifference);
                        }
                    }
                }
                else
                {
                    totalTimeDifference = 0;
                    Music.SetTimePosition((uint)TimeElapsed);
                    hasSetMusicPositionToUs = true;
                }
            }
            else
            {
                setMusicPositionToUsCooldown--;
            }
            if (totalTimeDifference != 0)
            {
                float amount = totalTimeDifference * totalTimeDifferenceScaleRate;
                totalTimeDifference -= amount;
                //TimeBegan += amount;
            }

            prevKeyPresses = keyPresses;
        }
Esempio n. 4
0
        public override void Update(GameTime gameTime)
        {
            float delta = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            leftPressed   = InputManager.GetValue("left");
            rightPressed  = InputManager.GetValue("right");
            upPressed     = InputManager.GetValue("up");
            downPressed   = InputManager.GetValue("down");
            placePressed  = InputManager.GetValue("place");
            removePressed = InputManager.GetValue("remove");
            pausePressed  = InputManager.GetValue("pause");
            savePressed   = InputManager.GetValue("save");
            if (beatNotificationOpacity > 0)
            {
                beatNotificationOpacity -= beatNotificationOpacityRate;
            }
            if (beatNotificationOpacity < 0)
            {
                beatNotificationOpacity = 0;
            }
            if (Music.beatWait)
            {
                Music.beatWait = false;
                HitBeat();
            }
            if (beginWaitCooldown > 0)
            {
                beginWaitCooldown--;
            }
            else
            {
                if (leftPressed && !prevLeftPressed)
                {
                    currentColumn--;
                    if (currentColumn < 0)
                    {
                        currentColumn = 3;
                    }
                }
                if (rightPressed && !prevRightPressed)
                {
                    currentColumn++;
                    if (currentColumn > 3)
                    {
                        currentColumn = 0;
                    }
                }
                if (upPressed)
                {
                    if (!prevUpPressed || timeShiftPressLength > timeShiftPressLengthGate)
                    {
                        TimeElapsed = snapTime(TimeElapsed + msPerBeatDiv);
                    }
                    timeShiftPressLength += delta;
                }
                if (downPressed)
                {
                    if (!prevDownPressed || timeShiftPressLength > timeShiftPressLengthGate)
                    {
                        TimeElapsed = snapTime(TimeElapsed - msPerBeatDiv);
                    }
                    timeShiftPressLength += delta;
                }
                if (!upPressed && !downPressed)
                {
                    timeShiftPressLength = 0;
                }
                if (placePressed && !prevPlacePressed)
                {
                    Columns[currentColumn].Add(snapTime(TimeElapsed));
                    Columns[currentColumn].Sort((a, b) => { return(Math.Sign(a - b)); });
                }
                if (removePressed && !prevRemovePressed)
                {
                    List <float> column = Columns[currentColumn];
                    for (int i = 0; i < column.Count; i++)
                    {
                        int noteY          = TimeToPosition(column[i]);
                        int halfNoteHeight = NoteHeight / 2;
                        int centerY        = noteY + halfNoteHeight;
                        if (centerY - halfNoteHeight <= boardHeight && centerY + halfNoteHeight >= boardHeight)
                        {
                            //destroy the note
                            column.RemoveAt(i);
                            break;
                        }
                    }
                }
                if (pausePressed && !prevPausePressed)
                {
                    if (TimeModifier == 0)
                    {
                        TimeModifier = 1;
                        //MediaPlayer.Play(Music, new TimeSpan((long)(TimeElapsed * TimeSpan.TicksPerMillisecond)));
                        PlayMusic((uint)TimeElapsed);
                        TimeBegan = (float)(gameTime.TotalGameTime.TotalMilliseconds - TimeElapsed);
                    }
                    else
                    {
                        TimeModifier = 0;
                        //MediaPlayer.Pause();
                        PauseMusic();
                    }
                }
                if (savePressed && !prevSavePressed)
                {
                    save();
                }
            }

            prevLeftPressed   = leftPressed;
            prevRightPressed  = rightPressed;
            prevUpPressed     = upPressed;
            prevDownPressed   = downPressed;
            prevPlacePressed  = placePressed;
            prevRemovePressed = removePressed;
            prevPausePressed  = pausePressed;
            prevSavePressed   = savePressed;
            base.Update(gameTime);
        }