void OnTriggerEnter(Collider other) { //Is it the Player who enters the collider? if ((!other.CompareTag("Player1")) && (!other.CompareTag("Player2"))) { return; } // return; //If it's not the player doLapsnt continue if (other.CompareTag("Player1")) { choosen_laps = player_1.GetComponent <Laps>(); } if (other.CompareTag("Player2")) { choosen_laps = player_2.GetComponent <Laps>(); } if (transform == choosen_laps.checkpointA[choosen_laps.currentCheckpoint].transform) { //Check so we dont exceed our checkpoint quantity //Add to currentLap if currentCheckpoint is 0 if (choosen_laps.currentCheckpoint == choosen_laps.checkpointA.Length - 1) { choosen_laps.NewLapTriggered(); choosen_laps.currentLap++; choosen_laps.currentCheckpoint = 0; } choosen_laps.currentCheckpoint++; } choosen_laps.CheckpointTriggered(); }
private void CheckAndOverrideBestLap(double layoutLength) { if (DriverInfo.Timing.BestLapTime == TimeSpan.Zero) { return; } if (BestLap == null) { ILapInfo newBestLap = new StaticLapInfo(Laps.Count + 1, DriverInfo.Timing.BestLapTime, false, Laps.LastOrDefault(), layoutLength, this); _lapsInfo.Insert(0, newBestLap); BestLap = newBestLap; LapCompleted?.Invoke(this, new LapEventArgs(newBestLap)); return; } if (BestLap.LapTime == DriverInfo.Timing.BestLapTime) { return; } ILapInfo oldBestLap = BestLap; oldBestLap.OverrideTime(DriverInfo.Timing.BestLapTime); BestLap = Laps.Where(x => x.Completed && x.Valid && x.LapTime != TimeSpan.Zero).OrderBy(x => x.LapTime).FirstOrDefault(); LapTimeReevaluated?.Invoke(this, new LapEventArgs(oldBestLap)); }
public async Task Test4ThensAsync500MsEach2000MsTotal() { // Start the runner asynchronously. Task t = Runner.Run(S).Then(S, S, S).Async(); // Take a lap right away. This should be only a few milliseconds in // if the runner tasks really started asynchronously. Laps.Add(Lapper.Lap()); // Wait for all of the runner tasks to finish. await t.ConfigureAwait(false); Lapper.Stop(); // There should be 5 laps; one that we took right away and one each per runner task. Assert.Equal(5, Laps.Count); // The first task should have been lapped right away, a few milliseconds after starting. // Let's give a 500% epsilon since the expected time is so short. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(10), Lapper.Laps[0], 5); // The rest should each take about 500ms. foreach (var lap in Laps.Skip(1)) { TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1); } // ... And the total time should have been about 4 x 500ms = 2000ms. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(2000), Lapper.Elapsed, 0.1); }
public async Task Test4AndsAsync500MsEach500MsTotal() { // Start the runner asynchronously. Task t = Runner.Run(S).And(S, S, S).Async(); // Take a lap right away. This should be only a few milliseconds in // if the runner tasks really started asynchronously. Laps.Add(Lapper.Lap()); // Wait for the runner to finish. await t.ConfigureAwait(false); Lapper.Stop(); // The async lap (first lap) should have been only a few ms after its stopwatch started. TimeAssert.EpsilonEquals(TimeSpan.FromMilliseconds(25), Laps[0], TimeSpan.FromMilliseconds(50)); // We should have one lap per task run. Assert.Equal(5, Laps.Count); // Each lap should be about 500ms... // Skip the first lap because it was the one we took right away. foreach (TimeSpan lap in Laps.Skip(1)) { TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1); } // And the elapsed time should be 500ms since the tasks were all run in parallel. TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), Lapper.Elapsed, 0.1); }
/// <summary> /// Executes the load laps command. /// </summary> async Task ExecuteLoadLapsCommand() { if (IsBusy) { return; } IsBusy = true; try { var laps = await App.RestService.LapsByRaceAndDriverAsync(Race.Season, Race.Round, Driver.Id); Race.Laps = laps.Laps; Laps.Clear(); foreach (var l in laps.Laps) { Laps.Add(l); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void MakeLap(CompetingModels CM) { if (Finished) { Finished = false; BadFinish = false; } DateTime Now = DateTime.Now; if (Laps.Count == 0) { RoundStart = Now; PreviousTime = Now; Laps.Add(new Lap(Now, Now, true)); } else { CurrentTime = Now; Laps.Add(new Lap(Now, PreviousTime, false)); PreviousTime = Now; } if (Laps.Count - 1 == CM.LapsCount) { Finish(); return; } }
// Start is called before the first frame update void Awake() { laps = player.GetComponent <Laps>(); lapResults = new List <float>(); laptext = GetComponent <Text>(); laptext.text = "Laptime: 00:00:000"; }
private void Add(int rot) { Laps.Add(new Lap(rot)); Calc(); SetLabel(); }
public virtual void AddLap(LapRecord lr) { Laps.Add(lr); OrderedLaps.Add(lr); OrderedLaps.Sort(); UpdateTimes(); RecalculateMeanOfLapTimes(); }
public bool Equals(Round other) { if (other == null) { return(false); } return(Laps.Equals(other.Laps) && RoundTime().Equals(other.RoundTime())); }
public void Lap(string lapName) { _stopwatch.Stop(); Laps.Add(new LappingStopwatchResult(lapName, _stopwatch.Elapsed)); _stopwatch.Reset(); _stopwatch.Start(); }
public void Append(Checkpoint cp, bool finish = false) { if (RiderId != cp.RiderId) { throw new ArgumentException($"Found checkpoints with different RiderIds {RiderId} {cp.RiderId}", nameof(cp)); } var newLaps = Laps.Concat(new [] { Laps.LastOrDefault()?.CreateNext(cp) ?? new Lap(cp, Start) }); UpdateFromLaps(RiderId, newLaps, finish); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (Description != null) { hashCode = hashCode * 59 + Description.GetHashCode(); } if (Photos != null) { hashCode = hashCode * 59 + Photos.GetHashCode(); } if (Gear != null) { hashCode = hashCode * 59 + Gear.GetHashCode(); } if (Calories != null) { hashCode = hashCode * 59 + Calories.GetHashCode(); } if (SegmentEfforts != null) { hashCode = hashCode * 59 + SegmentEfforts.GetHashCode(); } if (DeviceName != null) { hashCode = hashCode * 59 + DeviceName.GetHashCode(); } if (EmbedToken != null) { hashCode = hashCode * 59 + EmbedToken.GetHashCode(); } if (SplitsMetric != null) { hashCode = hashCode * 59 + SplitsMetric.GetHashCode(); } if (SplitsStandard != null) { hashCode = hashCode * 59 + SplitsStandard.GetHashCode(); } if (Laps != null) { hashCode = hashCode * 59 + Laps.GetHashCode(); } if (BestEfforts != null) { hashCode = hashCode * 59 + BestEfforts.GetHashCode(); } return(hashCode); } }
public override string ToString() { var builder = new System.Text.StringBuilder(); builder.AppendFormat("{0} {{", nameof(LeaderboardEntry)).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(CarId), CarId.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(LapTime), LapTime.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(Laps), Laps.ToString()).AppendLine(); builder.AppendFormat(" {0} = {1}", nameof(HasFinished), HasFinished.ToString()).AppendLine(); builder.AppendFormat("}}").AppendLine(); return(builder.ToString()); }
public void AddLap() { string tempFullTime = "Общее время: " + Time; TimeSpan tempT = TimeSpan.FromMilliseconds(elapsedTime - lastTime); lastTime = elapsedTime; string tempLapTime = "Время круга: "; tempLapTime += string.Format("{0:D2}:{1:D2}:{2:D2}", tempT.Hours, tempT.Minutes, tempT.Seconds); Laps.Add(new Lap { LapNumber = Laps.Count + 1, LapTime = tempLapTime, FullTime = tempFullTime }); }
private void Cancel() { LapCount = Laps.Count; if (LapCount == 0) { return; } Laps.RemoveAt(LapCount - 1); Calc(); SetLabel(); }
private void DriverTimingOnNewLapStarted(object sender, DriverTiming.LapEventArgs e) { /*if (!Laps.Last().LapInfo.Completed) * { * Laps.RemoveAt(Laps.Count - 1); * }*/ var newLapModel = new LapViewModel(e.Lap); if (Laps.Any() && Laps.Last().LapNumber == newLapModel.LapNumber) { Laps.Remove(Laps.Last()); } Laps.Add(newLapModel); _gui.LapsGrid.ScrollIntoView(newLapModel); }
private void Save() { var div = "\t"; var sb = new StringBuilder(); sb.Append("時刻") .Append(div) .Append("ロット数") .AppendLine(); Laps.ForEach(x => { sb.Append(x.TimeStamp.ToString("yyyy/MM/dd HH:mm:ss.fff")) .Append(div) .Append(x.Rot) .AppendLine(); }); sb.AppendLine(); sb.Append("悟飯の出番").Append(div).Append(LapCount.ToString()).AppendLine(); sb.Append("合計ロット数").Append(div).Append(TotalRot.ToString()).AppendLine(); sb.Append("最大ロット数").Append(div).Append(MaxRot.ToString()).AppendLine(); sb.Append("平均ロット数").Append(div).Append(AverageRot.ToString("f2")).AppendLine(); try { Clipboard.SetText(sb.ToString()); } catch (Exception) { MessageBox.Show( "クリップボードにコピーできませんでした。", "エラー", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBox.Show( "カカログをクリップボードにコピーしました。", "完了", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Convert the list of points to a list of common coordinates /// </summary> /// <returns></returns> public List <GeoCoordinateExtended> ToCoords() { List <GeoCoordinateExtended> merged = new List <GeoCoordinateExtended>(); Laps.ForEach(lap => merged.AddRange(lap.Track.ToCoords())); // Infilling is done for each track but there could be bad coordinates left over at the start or end of tracks that // might still need dealing with so check first rather than always doing it. if (merged.Where(pt => pt.BadCoordinate).Count() > 0) { return(merged.InfillPositions()); // Infill the positions that might still exist in boundaries between tracks before returning } else { return(merged); // No need for infilling as no bad coordinates } }
private void Calc() { LapCount = Laps.Count; if (LapCount == 0) { TotalRot = 0; MaxRot = 0; AverageRot = 0; } else { TotalRot = Laps.Sum(x => x.Rot); MaxRot = Laps.Max(x => x.Rot); AverageRot = (double)TotalRot / LapCount; } }
private List <RaceLap> GetLapsByLapNumber(int lapNumber, bool searchDownForPreviousLapsForEveryDriver) { List <RaceLap> ret = new List <RaceLap>(); ret = Laps.Get(lapNumber); if (searchDownForPreviousLapsForEveryDriver) { List <Driver> drivers = Laps.GetDrivers().ToList(); foreach (var lap in ret) { if (drivers.Contains(lap.Driver)) { drivers.Remove(lap.Driver); } } int lastDriversCount = drivers.Count; while (drivers.Count > 0) { Driver driver = drivers[0]; for (int i = lapNumber - 1; i > 0; i--) { RaceLap lap = Laps.Get(i, driver); if (lap != null) { ret.Add(lap); drivers.Remove(driver); break; } } if (lastDriversCount == drivers.Count) { throw new Exception("Cannot get last previous lap of driver " + driver.NameSurname + ". Invalid data."); } else { lastDriversCount = drivers.Count; } } } return(ret); }
private void EvaluateLaps(out RaceLap zeroLapOfPolePosition) { Minner <RaceLap> m = new Minner <RaceLap>( (RaceLap l) => l.CrossedAtTime ); RaceLap lapZero; var drivers = Laps.GetDrivers(); foreach (var driver in drivers) { RecalculateLapTimesOfDriver(driver, out lapZero); m.Add(lapZero as RaceLap); Laps.Remove(0, driver); RefreshLinksOfDriver(driver); } zeroLapOfPolePosition = m.MinimumItem; }
public void RecalculateLapTimes() { var drivers = Laps.GetDrivers(); // order laps of all drivers by time foreach (var driver in drivers) { var laps = Laps[driver]; laps.Sort(new Lap.ByCrossedAtTimeComparer()); for (int i = 1; i < laps.Count; i++) { Time bef = laps[i - 1].CrossedAtTime; Time curr = laps[i].CrossedAtTime; Time diff = curr - bef; laps[i].Time = diff; laps[i].LapNumber = i; } Laps.Remove(0, driver); } }
private void analyseLaps() { var lDist = Laps.Sum(l => l.DistanceMeters); var lapsWithTrackPoints = Laps.Where(l => l.TrackPoints != null && l.TrackPoints.Any()).ToList(); if (lapsWithTrackPoints.Any()) { var tDist = lapsWithTrackPoints.SelectMany(l => l.TrackPoints).Max(t => t.DistanceMeters); if (lDist != tDist) { Debugger.Log(1, "", $"Laps inconsistent: trackpoints cover {100.0 * tDist / lDist}% of lap distance ({tDist} vs {lDist})\r\n"); } } TrackPoint lastTrackPoint = null; var totalDistance = 0.0; foreach (var lap in Laps) { totalDistance += lap.DistanceMeters; foreach (var trackpoint in lap.TrackPoints) { if (lastTrackPoint != null) { var interval = trackpoint.Time - lastTrackPoint.Time; var intervalS = interval.TotalSeconds; var distanceCovered = trackpoint.DistanceMeters - lastTrackPoint.DistanceMeters; lastTrackPoint.Interval = interval; trackpoint.DistanceCoveredMeters = distanceCovered; } lastTrackPoint = trackpoint; } } if (lastTrackPoint != null) { lastTrackPoint.Interval = EndTime - lastTrackPoint.Time; } }
public void RegisterPitLaps() { this.PitLaps.Clear(); var drivers = Laps.GetDrivers(); foreach (var driver in drivers) { var laps = Laps[driver]; laps.ForEach(i => i.PitState = RaceLap.ePitState.None); laps.Sort(new Lap.ByCrossedAtTimeComparer()); for (int i = 1; i < laps.Count - 1; i++) { if (laps[i].IsPitted == false) { continue; } RaceLap current = laps[i]; RaceLap next = laps[i + 1]; this.PitLaps.Add(current, next); if (current.PitState == RaceLap.ePitState.Exit) { current.PitState = RaceLap.ePitState.ExitAndEntry; } else { current.PitState = RaceLap.ePitState.Entry; } next.PitState = RaceLap.ePitState.Exit; } } }
public void RefreshLinks() { var drivers = Laps.GetDrivers(); NonRacePositionCollection bestLaps = new NonRacePositionCollection(); // order laps of all drivers by time foreach (var driver in drivers) { var laps = Laps[driver]; LapProvider.ReLinkByCrossedAt(laps); LapProvider.ReLinkByTime(laps); laps.Sort(new Lap.ByLapTimeComparer()); if (laps.Count > 0) { bestLaps.Add(laps[0]); } } // get positions bestLaps.Sort(new Lap.ByLapTimeComparer()); Positions = bestLaps; }
public void AddLap() { var newLap = new UserLap { SetupSheetID = new Guid(), LapTime = TimeSpan.Zero }; if (SelectedLap == null || SelectedLap.InLap) { var lastNonInLap = Laps.LastOrDefault(x => x.InLap == false); if (lastNonInLap != null) { newLap.LapNumber = lastNonInLap.LapNumber + 1; } else { newLap.LapNumber = Laps.Count() + 1; } } else { newLap.LapNumber = Laps.Count() + 1; } //bump the lap number of every lap beyond the insert point. for (var i = newLap.LapNumber - 1; i < Laps.Count(); i++) { Laps[i].LapNumber++; } var lvm = new LapViewModel { Lap = newLap }; Laps.Add(lvm); var lastOrDefault = Laps.LastOrDefault(x => x.InLap == false); SelectedLap = lastOrDefault; }
// Start is called before the first frame update void Awake() { laps = player.GetComponent <Laps>(); checkpoints = GetComponent <Text>(); checkpoints.text = "Lap: 0"; }
public void AddLap(Lap lap) { Laps.Add(lap); }
private SectorTiming FindBestSector(Func <LapInfo, SectorTiming> sectorPickerFunc) { return(Laps.Where(l => l.Valid).Select(sectorPickerFunc).Where(s => s != null && s.Duration != TimeSpan.Zero) .OrderBy(s => s.Duration).FirstOrDefault()); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { mapTexture = skin.mapTexture; // Get input KeyboardState keyboard = Keyboard.GetState(); GamePadState gamePad = GamePad.GetState(PlayerIndex.One); #region Allways keys // back to menu if (keyboard.IsKeyDown(Keys.M) && gameState != GameState.Options) { gameState = GameState.Intro; ////turn off all sounds foreach (Motor motor in motors) { motor.Active = false; motor.Update(gameTime); } } #endregion #region Intro if (gameState == GameState.Intro) { winner.Clear(); winner.Append("Welcome to ZUZELO Steering:\n"); winner.Append(" ONE: Left, Up, Right\n"); winner.Append(" TWO: A, S, D\n"); winner.Append("Press: \n"); winner.Append("B - one player single game G - one player Tournament\n"); winner.Append("N - two player single game H - two player Tournament\n"); winner.Append("O - options"); //new game if (keyboard.IsKeyDown(Keys.B)) { gameState = GameState.NewGame; player2 = Players.AI; whatGame = WhatGame.singleGame; } //options if (keyboard.IsKeyDown(Keys.O)) { gameState = GameState.Options; } //new game if (keyboard.IsKeyDown(Keys.N)) { gameState = GameState.NewGame; player2 = Players.Player2; whatGame = WhatGame.singleGame; } //new game if (keyboard.IsKeyDown(Keys.G)) { gameState = GameState.NewGame; player2 = Players.AI; whatGame = WhatGame.Tournament; tournament = new Tournament(GameConstants.ROUNDSTOURNAMENT); } //new game if (keyboard.IsKeyDown(Keys.H)) { gameState = GameState.NewGame; player2 = Players.Player2; whatGame = WhatGame.Tournament; tournament = new Tournament(GameConstants.ROUNDSTOURNAMENT); } // Allows the game to exit if (gamePad.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape)) { MyExit(); } } #endregion #region Options if (gameState == GameState.Options) { // Allows the game to exit if (gamePad.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape)) { MyExit(); } // back to menu if (keyboard.IsKeyDown(Keys.M)) { gameState = GameState.Intro; ////turn off all sounds foreach (Motor motor in motors) { motor.Active = false; motor.Update(gameTime); } InitiateSave(); } winner.Clear(); if (difficulty == Difficulty.Easy) { winner.Append("I - Difficulty Easy Made by:\n"); } else { winner.Append("I - Difficulty Hard Made by:\n"); } if (classicMode) winner.Append("T - Classic mode ON www.krzykustudio.pl\n"); else winner.Append("T - Classic mode OFF www.krzykustudio.pl\n"); if (soundON) winner.Append("U - Sound ON\n"); else winner.Append("U - Sound OFF\n"); if (showFps) winner.Append("Y - Show fps ON Sounds from:\n"); else winner.Append("Y - Show fps OFF Sounds from:\n"); winner.Append("M - Menu www.freefx.co.uk\n"); winner.Append("K - " + skin.skinName + " 2015\n"); //classic mode if (keyboard.IsKeyDown(Keys.T) && keyTup) { if (classicMode) { classicMode = false; } else { classicMode = true; } keyTup = false; } if (keyboard.IsKeyUp(Keys.T)) { keyTup = true; } //difficulty if (keyboard.IsKeyDown(Keys.I) && keyIup) { if (difficulty == Difficulty.Easy) { difficulty = Difficulty.Hard; } else { difficulty = Difficulty.Easy; } keyIup = false; } if (keyboard.IsKeyUp(Keys.I)) { keyIup = true; } //Skin if (keyboard.IsKeyDown(Keys.K) && keyKup) { if (skin == skin1) { skin = skin2; } else { skin = skin1; } keyKup = false; } if (keyboard.IsKeyUp(Keys.K)) { keyKup = true; } //sounds on off if (keyboard.IsKeyDown(Keys.U) && keyUup) { if (soundON) { soundON = false; } else { soundON = true; } keyUup = false; } if (keyboard.IsKeyUp(Keys.U)) { keyUup = true; } //show fps if (keyboard.IsKeyDown(Keys.Y) && keyYup) { if (showFps) { showFps = false; } else { showFps = true; } keyYup = false; } if (keyboard.IsKeyUp(Keys.Y)) { keyYup = true; } } #endregion #region New Game if (gameState == GameState.NewGame) { tireMarks.Clear(); motors.Clear(); laps.Clear(); int index, pos; lapsWinner.Clear(); //sounds counting flag soundPlayingGO = false; soundPlaying1 = false; soundPlaying2 = false; soundPlaying3 = false; //starting positions List<int> positions = new List<int>(); positions.Add(0); positions.Add(1); positions.Add(2); positions.Add(3); int mode; float speed = GameConstants.MOTOR_ACC_SPEED; if (difficulty == Difficulty.Easy) { speed = GameConstants.MOTOR_ACC_SPEED; } if (difficulty == Difficulty.Hard) { speed = GameConstants.MOTOR_ACC_SPEED + 0.07F; } if (classicMode) { mode = 1; } else { mode = 0; } pos = random.Next(positions.Count); index = positions[pos]; positions.RemoveAt(pos); motorSound = Content.Load<SoundEffect>("audio\\motorRunning1"); motorRed = new Motor("Red ", Content, skin.motorRed, (int)GameConstants.START_POS.X, (int)GameConstants.START_POS.Y + 27 * index, new Vector2(0, 0), motorSound, GameConstants.SFX_VOL, speed, mode); motors.Add(motorRed); pos = random.Next(positions.Count); index = positions[pos]; positions.RemoveAt(pos); motorSound = Content.Load<SoundEffect>("audio\\motorRunning2"); motorYellow = new Motor("Yellow", Content, skin.motorYellow, (int)GameConstants.START_POS.X, (int)GameConstants.START_POS.Y + 27 * index, new Vector2(0, 0), motorSound, GameConstants.SFX_VOL, speed, mode); motors.Add(motorYellow); pos = random.Next(positions.Count); index = positions[pos]; positions.RemoveAt(pos); motorSound = Content.Load<SoundEffect>("audio\\motorRunning3"); motorBlue = new Motor("Blue ", Content, skin.motorBlue, (int)GameConstants.START_POS.X, (int)GameConstants.START_POS.Y + 27 * index, new Vector2(0, 0), motorSound, GameConstants.SFX_VOL, speed, mode); motors.Add(motorBlue); pos = random.Next(positions.Count); index = positions[pos]; positions.RemoveAt(pos); motorSound = Content.Load<SoundEffect>("audio\\motorRunning3"); motorGreen = new Motor("Green ", Content, skin.motorGreen, (int)GameConstants.START_POS.X, (int)GameConstants.START_POS.Y + 27 * index, new Vector2(0, 0), motorSound, GameConstants.SFX_VOL, speed, mode); motors.Add(motorGreen); //AI layers aiGreen = new AIMotorMovement(motorGreen, checkAiPointsList, mode); aiBlue = new AIMotorMovement(motorBlue, checkAiPointsList, mode); aiYellow = new AIMotorMovement(motorYellow, checkAiPointsList, mode); // if tournament add players to tournament if (whatGame == WhatGame.Tournament) { if (tournament.State == Tournament.TournamentState.NewGame) { foreach (Motor motor in motors) { tournament.AddPlayer(motor.MotorName); } tournament.State = Tournament.TournamentState.Playing; } } clock = (int)gameTime.TotalGameTime.TotalSeconds; gameState = GameState.Counting; } #endregion #region Counting //Odliczanie if (gameState == GameState.Counting) { SoundEffect counting; counting = Content.Load<SoundEffect>("audio\\tick"); SoundEffectInstance instance; instance = counting.CreateInstance(); instance.IsLooped = false; winner.Clear(); if ((int)gameTime.TotalGameTime.TotalSeconds - clock == 2) { if (!soundPlaying3) { instance.Play(); soundPlaying3 = true; } winner.Append(" *********\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" *********\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" *********\n"); } if ((int)gameTime.TotalGameTime.TotalSeconds - clock == 3) { if (!soundPlaying2) { instance.Play(); soundPlaying2 = true; } winner.Append(" *********\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" ** \n"); winner.Append(" *********\n"); } if ((int)gameTime.TotalGameTime.TotalSeconds - clock == 4) { if (!soundPlaying1) { instance.Play(); soundPlaying1 = true; } winner.Append(" *****\n"); winner.Append(" * **\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" **\n"); winner.Append(" ****\n"); } if ((int)gameTime.TotalGameTime.TotalSeconds - clock >= 5) { if (!soundPlayingGO) { counting = Content.Load<SoundEffect>("audio\\tack"); counting.Play(); soundPlayingGO = true; } gameState = GameState.StartGame; } } #endregion #region Start Game if (gameState == GameState.StartGame) { clock = (int)gameTime.TotalGameTime.TotalMilliseconds; lapsMotorRed = new Laps(motorRed, checkPointsList, finishMapRectangle, GameConstants.LAPS_NUMBER, clock); laps.Add(lapsMotorRed); lapsMotorYellow = new Laps(motorYellow, checkPointsList, finishMapRectangle, GameConstants.LAPS_NUMBER, clock); laps.Add(lapsMotorYellow); lapsMotorGreen = new Laps(motorGreen, checkPointsList, finishMapRectangle, GameConstants.LAPS_NUMBER, clock); laps.Add(lapsMotorGreen); lapsMotorBlue = new Laps(motorBlue, checkPointsList, finishMapRectangle, GameConstants.LAPS_NUMBER, clock); laps.Add(lapsMotorBlue); gameState = GameState.Playing; } #endregion #region Game Playing if (gameState == GameState.Playing) { foreach (Motor motorek in motors) { motorek.AngleVelocity = 0.0F; motorek.Turning = false; } clock_elapsed = (int)gameTime.TotalGameTime.TotalMilliseconds; #region Move the player //RED if (keyboard.IsKeyDown(Keys.Left)) { if (classicMode) { motorRed.AngleVelocity = GameConstants.MOTOR_ANGLE - 0.02F; } else { motorRed.AngleVelocity = GameConstants.MOTOR_ANGLE; } motorRed.Turning = true; } if (keyboard.IsKeyDown(Keys.Right) && classicMode == false) { motorRed.AngleVelocity = -GameConstants.MOTOR_ANGLE; motorRed.Turning = true; } if (keyboard.IsKeyDown(Keys.Up) && classicMode == false) { motorRed.Thrust = true; } else if (classicMode) { motorRed.Thrust = true; } else { motorRed.Thrust = false; } //Yellow motor player or AI if (player2 == Players.Player2) { //YELLOW if (keyboard.IsKeyDown(Keys.A)) { if (classicMode) { motorYellow.AngleVelocity = GameConstants.MOTOR_ANGLE - 0.02F; } else { motorYellow.AngleVelocity = GameConstants.MOTOR_ANGLE; } motorYellow.Turning = true; } if (keyboard.IsKeyDown(Keys.D) && classicMode == false) { motorYellow.AngleVelocity = -GameConstants.MOTOR_ANGLE; motorYellow.Turning = true; } if (keyboard.IsKeyDown(Keys.W) && classicMode == false) { motorYellow.Thrust = true; } else if (classicMode) { motorYellow.Thrust = true; } else { motorYellow.Thrust = false; } } else { //AI Yellow aiYellow.Update(gameTime); } aiBlue.Update(gameTime); aiGreen.Update(gameTime); #endregion // Check collision with mapborder allMotorsActive = motors.Count(); foreach (Motor motorek in motors) { if (!motorek.Active) allMotorsActive -= 1; if (Intersect.IntersectPixels(motorek.DrawRectangle, motorek.TextureData, mapRectangle, mapGradTextureData)) { motorek.Active = false; } motorek.Update(gameTime); if (motorek.MotorName.Trim() == "Red") { tireMarks.Add(new TireMark(Content, skin.motorRedTires, motorek.DrawRectangle.Center.X, motorek.DrawRectangle.Center.Y)); } if (motorek.MotorName.Trim() == "Green") { tireMarks.Add(new TireMark(Content, skin.motorGreenTires, motorek.DrawRectangle.Center.X, motorek.DrawRectangle.Center.Y)); } if (motorek.MotorName.Trim() == "Blue") { tireMarks.Add(new TireMark(Content, skin.motorBlueTires, motorek.DrawRectangle.Center.X, motorek.DrawRectangle.Center.Y)); } if (motorek.MotorName.Trim() == "Yellow") { tireMarks.Add(new TireMark(Content, skin.motorYellowTires, motorek.DrawRectangle.Center.X, motorek.DrawRectangle.Center.Y)); } } if (allMotorsActive == 0) { gameState = GameState.GameOver; } //update playing foreach (Laps lap in laps) { lap.Update(gameTime, clock_elapsed - clock); } // build playing string if (gameTime.TotalGameTime.TotalMilliseconds - clock < 500) { winner.Clear(); winner.Append(" ******** ********\n"); winner.Append(" ** ** ** **\n"); winner.Append(" ** ** **\n"); winner.Append(" ** ***** ** **\n"); winner.Append(" ** ** ** **\n"); winner.Append(" ** ** ** **\n"); winner.Append(" ********* ********\n"); } else { winner.Clear(); winner.Append("GameTime: " + DisplayClock(clock_elapsed - clock) + "\n\n"); int position = 1; foreach (Laps lap in laps) { winner.Append(lap.MotorName + " Lap: " + lap.CurrentLap + "/" + GameConstants.LAPS_NUMBER.ToString() + "\n"); position++; } } if (tireMarks.Count > skin.tireLongMark) { tireMarks.RemoveAt(0); tireMarks.RemoveAt(0); tireMarks.RemoveAt(0); } } #endregion #region Game Over if (gameState == GameState.GameOver) { List<int> temporaryList = new List<int>(); var winnerMotor = from motor in laps where motor.LapTime > 0 orderby motor.LapTime select motor; winner.Clear(); foreach (Laps lap in winnerMotor) { lapsWinner.Add(lap); } //build winner list only in someone true ended race if (lapsWinner.Count > 0) { if (whatGame == WhatGame.singleGame) { winner.Append("Winner: " + lapsWinner[0].MotorName + " SPACE for main screen\n\n"); } else { winner.Append("Winner: " + lapsWinner[0].MotorName + " SPACE for tournament screen\n\n"); int score = 3; foreach (Laps lap in lapsWinner) { tournament.AddTimes(lap.MotorName, score, lap.LapTime); score--; } } int position = 1; foreach (Laps lap in lapsWinner) { winner.Append(position.ToString() + ". " + lap.MotorName + " time: " + DisplayClock(lap.LapTime) + "\n"); position++; } } else { winner.Clear(); if (whatGame == WhatGame.singleGame) { winner.Append("Nobody wins SPACE for main screen\n\n"); } else { winner.Append("Nobody wins SPACE for tournament screen\n\n"); } } gameState = GameState.DisplayResults; } #endregion #region Display Results if (gameState == GameState.DisplayResults) { //intro screen if (keyboard.IsKeyDown(Keys.Space) && whatGame == WhatGame.singleGame) { gameState = GameState.Intro; } //tournament results if (keyboard.IsKeyDown(Keys.Space) && whatGame == WhatGame.Tournament) { gameState = GameState.DisplayTournament; clock = (int)gameTime.TotalGameTime.TotalSeconds; } } #endregion #region Display Tournament if (gameState == GameState.DisplayTournament) { winner.Clear(); if (tournament.State == Tournament.TournamentState.Playing) { winner.Append("Tournament scores SPACE for next round\n"); winner.Append(tournament.ToString()); //new game with 1second delay hiting key if (keyboard.IsKeyDown(Keys.Space) && ((int)gameTime.TotalGameTime.TotalSeconds - clock) >= 1) { gameState = GameState.NewGame; tournament.AddRound(); } } else if (tournament.State == Tournament.TournamentState.Ended) { winner.Clear(); winner.Append("FINAL SCORES SPACE for end Tournament\n"); winner.Append(tournament.ToString()); //new game with 1second delay hiting key if (keyboard.IsKeyDown(Keys.Space) && ((int)gameTime.TotalGameTime.TotalSeconds - clock) >= 2) { gameState = GameState.Intro; clock = (int)gameTime.TotalGameTime.TotalSeconds; } } } #endregion #region Display Tournament Winner if (gameState == GameState.DisplayTournamentFinal) { //tournament results if (keyboard.IsKeyDown(Keys.Space) && ((int)gameTime.TotalGameTime.TotalSeconds - clock) >= 1) { gameState = GameState.Intro; } } #endregion //motors sounds on of foreach (Motor motor in motors) { motor.SoundOnOff(soundON, GameConstants.SFX_VOL); } //update fog float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; if (skin.skinName == "Skin1") { foreach (Motor motor in motors) { //add new smoke if (motor.Active) { int X = (int)(Math.Cos(motor.Angle) * -motor.DrawRectangle.Width / 2) + motor.DrawRectangle.Center.X; int Y = (int)(Math.Sin(motor.Angle) * motor.DrawRectangle.Height) + motor.DrawRectangle.Center.Y; UpdateSmokePlume(dt, X, Y); } } } fpsMonitor.Update(); base.Update(gameTime); }