コード例 #1
0
ファイル: GameRaceScript.cs プロジェクト: Erumaru/BunnyHop
        public void CheckpointHit(object sender, EventArgs <Checkpoint> eventArgs)
        {
            int index = eventArgs.Content.Index;

            if (WorldInfo.info.IsLastCheckpoint(index) && IsNextCheckpoint(index) && !finished)
            {
                // End of race
                stopwatch.Stop();
                demoRecorder.Finish(stopwatch.ElapsedTicks);
                finished = true;

                GameInfo.info.RunFinished(ElapsedTime, demoRecorder.Demo);

                Destroy(gameObject);
            }
            else if (IsNextCheckpoint(index))
            {
                // Hit next checkpoint
                currentCheckpoint++;
                demoRecorder.AddCheckpoint(stopwatch.ElapsedTicks);
                DisplayText[] lines =
                {
                    new DisplayText("+ 12:34.567",                                Color.red),
                    new DisplayText("#" + index + ": " + ElapsedTime.ShortText(), Color.white),
                };
                GameMenu.SingletonInstance.ShowTextBox(lines);
            }
            else if (index != currentCheckpoint)
            {
                GameMenu.SingletonInstance.ShowTextBox("Wrong Checkpoint!", Color.red);
            }
        }
コード例 #2
0
        public void CheckpointHit(object sender, EventArgs <Checkpoint> eventArgs)
        {
            if (WorldInfo.info.IsEndCheckpoint(eventArgs.Content) && IsNextCheckpoint(eventArgs.Content) && !finished)
            {
                // Hit last checkpoint
                long checkpointTime = stopwatch.ElapsedTicks;

                demoRecorder.AddCheckpoint(checkpointTime);
                checkpointTimes.Add(checkpointTime);

                // End of race
                stopwatch.Stop();
                demoRecorder.Finish(stopwatch.ElapsedTicks);
                finished = true;

                GameInfo.info.RunFinished(checkpointTimes.ToArray(), demoRecorder.Demo);
                WorldInfo.info.RemovePlayer();
                WorldInfo.info.OnCheckpointTrigger -= CheckpointHit;
                Destroy(gameObject);
            }
            else if (IsNextCheckpoint(eventArgs.Content))
            {
                // Hit next checkpoint
                long checkpointTime = stopwatch.ElapsedTicks;

                demoRecorder.AddCheckpoint(checkpointTime);
                checkpointTimes.Add(checkpointTime);

                List <DisplayText> lines = new List <DisplayText>();
                lines.Add(new DisplayText("  " + ElapsedTime.ToShortTimeString(), Color.blue));

                long[] pbTime;
                if (PlayerSave.current.GetPersonalBest(GameInfo.info.MapManager.CurrentMap, out pbTime))
                {
                    Assert.IsTrue(pbTime.Length >= currentCheckpoint.Index);

                    string pbComparisonString = "";
                    long   tickDifference     = checkpointTime - pbTime[currentCheckpoint.Index];
                    Color  textColor;

                    if (tickDifference > 0)
                    {
                        pbComparisonString += "+ ";
                        textColor           = Color.red;
                    }
                    else
                    {
                        pbComparisonString += "- ";
                        textColor           = Color.blue;
                    }

                    pbComparisonString += Math.Abs(tickDifference).ToShortTimeString();
                    lines.Add(new DisplayText(pbComparisonString, textColor));
                }

                GameMenu.SingletonInstance.ShowTextBox(lines, 1.5f);
                currentCheckpoint = eventArgs.Content;
            }
            else if (eventArgs.Content.Index != currentCheckpoint.Index)
            {
                GameMenu.SingletonInstance.ShowTextBox("Wrong Checkpoint!", Color.red);
            }
        }