forked from jeff-1amstudios/OpenC1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRaceTimeController.cs
102 lines (92 loc) · 3.14 KB
/
RaceTimeController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using OpenC1.Parsers;
using Microsoft.Xna.Framework;
using OpenC1.HUD;
using OpenC1.GameModes;
using OneAmEngine;
using OneAmEngine.Audio;
namespace OpenC1
{
class RaceTimeController
{
public bool IsStarted, IsOver;
public bool CountingDown { get; private set; }
public float CountdownTime;
int _lastSecond = -1;
public float TimeRemaining;
List<string> _countdownTextures = new List<string>();
List<int> _countdownSoundIds = new List<int>();
public float TotalTime;
public RaceTimeController()
{
_countdownTextures.Add("number5.pix");
_countdownTextures.Add("number4.pix");
_countdownTextures.Add("number3.pix");
_countdownTextures.Add("number2.pix");
_countdownTextures.Add("number1.pix");
_countdownTextures.Add("go.pix");
_countdownSoundIds.Add(8005);
_countdownSoundIds.Add(8004);
_countdownSoundIds.Add(8003);
_countdownSoundIds.Add(8002);
_countdownSoundIds.Add(8001);
_countdownSoundIds.Add(8000);
TimeRemaining = Race.Current.ConfigFile.InitialTimerValues[GameVars.SkillLevel];
}
public void StartCountdown()
{
CountingDown = true;
}
public void Update()
{
TotalTime += GameEngine.ElapsedSeconds;
if (IsOver) return;
if (IsStarted)
{
TimeRemaining -= GameEngine.ElapsedSeconds;
if (TimeRemaining < 0)
{
TimeRemaining = 0;
IsOver = true;
GameMode.Current = new RaceCompletedMode(CompletionType.TimeUp);
}
else if (TimeRemaining < 10)
{
int second = (int)TimeRemaining;
if (second != _lastSecond)
SoundCache.Play(SoundIds.TimeBuzzer, null, false);
_lastSecond = second;
}
}
if (CountingDown)
{
CountdownTime += GameEngine.ElapsedSeconds;
if (CountdownTime > 5)
{
IsStarted = true;
foreach (IDriver driver in Race.Current.Drivers)
driver.OnRaceStart();
}
if (CountdownTime > 6)
CountingDown = false;
}
}
public void Render()
{
if (CountingDown)
{
int second = (int)CountdownTime;
if (second > _lastSecond)
{
ISound sound = SoundCache.Play(_countdownSoundIds[second], null, false);
if (sound != null) sound.Volume = -1600;
MessageRenderer.Instance.PostMainMessage(_countdownTextures[second], 0.7f, 0.24f, 0.003f, 0);
}
_lastSecond = second;
}
}
}
}