Beispiel #1
0
        public override void Initialize()
        {
            checkpointRasterization = raceTrack.GetCurveRasterization(checkpoints);

            List<AbstractTrigger> checkpointTriggers = new List<AbstractTrigger>();
            for (int i = 0; i < checkpoints; i++)
            {
                PositionTrigger trigger = new PositionTrigger(checkpointRasterization, i, true, true);
                string outputDebug = "Passing checkpoint " + i;
                trigger.Triggered += (sender, e) =>
                {
                    Console.WriteLine(outputDebug);

                    var now = DateTime.Now;
                    if (lastCheckpointPass != DateTime.MinValue)
                        gameInstance.GetService<HUDComponent>().ShowTextNotification(Color.BurlyWood, (now - lastCheckpointPass).ToString(@"m\:ss\:ff"));
                    lastCheckpointPass = now;

                    var current = states[CurrentState];
                    var aTrigger = sender as AbstractTrigger;
                    if (e.Object == car && current.Triggers.ContainsKey(aTrigger))
                        current.Triggers[aTrigger] = e;
                    AudioEngineManager.PlaySound("passfinishline");
                };

                string checkpointID = "checkpoint" + i;
                gameInstance.GetService<TriggerManager>().Triggers.Add(checkpointID, trigger);
                checkpointTriggers.Add(trigger);
                addedTriggers.Add(checkpointID);
            }

            // Keep track of times when passing goal line
            var goalTrigger = checkpointTriggers[0];
            goalTrigger.Triggered += (sender, e) =>
            {
                goalLineTimes.Add(e.Time.TotalGameTime);
                var player = gameInstance.GetService<Player>();
                string notification = (++player.Lap) > laps ? "Race finished!" : "Lap " + (player.Lap);
                gameInstance.GetService<HUDComponent>().ShowTextNotification(Color.Teal, notification);
            };

            for (int i = 0; i < laps; i++)
            {
                List<AbstractTrigger> lapTriggers = new List<AbstractTrigger>();
                lapTriggers.AddRange(checkpointTriggers);

                states.Add(new GameModeState(lapTriggers));
            }

            // Add state for passing the finish line
            states.Add(new GameModeState(checkpointTriggers.GetRange(index: 0, count: 1)));
        }
 public void AddLapTriggers()
 {
     // add lap counter triggers at finish line
     foreach (var player in players.FindAll(p => !p.LOCAL_PLAYER))
     {
         var lPlayer = player;
         var car = gameInstance.GetService<CarControlComponent>().Cars[lPlayer];
         PositionTrigger trigger = new PositionTrigger(checkpointRasterization, 0, true, true);
         trigger.Triggered += (sender, e) =>
         {
             lPlayer.Lap++;
         };
         Tuple<AbstractTrigger, List<IMovingObject>> objTrigger =
             new Tuple<AbstractTrigger, List<IMovingObject>>(trigger, new List<IMovingObject> { car });
         string id = "lapT" + lPlayer.PlayerName;
         gameInstance.GetService<TriggerManager>().ObjectTriggers.Add(id, objTrigger);
         addedObjTriggers.Add(id);
     }
 }