/[cvs]/rabit/r3/Class_Game.cls
ViewVC logotype

Contents of /rabit/r3/Class_Game.cls

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Mar 12 21:29:08 2002 UTC (22 years, 8 months ago) by cvsrabit
Branch: NFO, MAIN
CVS Tags: v034a, HEAD
Changes since 1.1: +0 -0 lines
Error occurred while calculating annotation data.
Initial project import

1 VERSION 1.0 CLASS
2 BEGIN
3 MultiUse = -1 'True
4 Persistable = 0 'NotPersistable
5 DataBindingBehavior = 0 'vbNone
6 DataSourceBehavior = 0 'vbNone
7 MTSTransactionMode = 0 'NotAnMTSObject
8 END
9 Attribute VB_Name = "Class_Game"
10 Attribute VB_GlobalNameSpace = False
11 Attribute VB_Creatable = True
12 Attribute VB_PredeclaredId = False
13 Attribute VB_Exposed = False
14 Public bSceneLoaded As Boolean
15
16 Public lGameTime As Long
17 Public lGameType As Long
18
19 Public strSceneName As String
20
21 Public Col_clPlayers As New Collection
22 '
23
24 Public Function AddPlayer(clPlayer As Class_Player) As Long
25
26 AddPlayer = GetTickCount
27
28 clPlayer.strPlayerKey = "p" & AddPlayer
29
30 Col_clPlayers.Add clPlayer, clPlayer.strPlayerKey
31
32 If clPlayer.lPlayerType = 0 Then lLocalPlayerHandle = AddPlayer
33
34 End Function
35
36 Public Sub MovePlayers()
37
38 Dim clPlayer As Class_Player
39 Dim clTrackSegment As Class_TrackSegment
40
41 Dim l As Long
42
43 Dim lLastTrackSegment As Long
44 Dim lNextTrackSegment As Long
45
46 Dim lPlayerIndex As Long
47
48 Dim s As Single
49
50 Dim sgAccelerate As Single
51
52 Dim sgBreak As Single
53
54 Dim sgDX As Single
55 Dim sgDZ As Single
56 Dim sgDXMove As Single
57 Dim sgDZMove As Single
58
59 Dim sgGroundBump As Single
60
61 Dim sgMaxSpeedForward As Single
62 Dim sgMaxSpeedBackwards As Single
63
64 Dim sgPlayerAngleRad As Single
65
66 Dim sgReduceSteeringAccelerationBySpeed As Single
67 Dim sgReduceSteeringBySpeed As Single
68
69 Dim sgScale As Single
70
71 Dim sgSpeed As Single
72 Dim sgSpeedRotation As Single
73
74 Dim sgSlowDown As Single
75
76 Dim sgSteeringAccelerate As Single
77 Dim sgSteeringRelease As Single
78
79 Dim sgTimeDiff As Single
80
81 Dim sgX As Single
82 Dim sgY As Single
83
84 Dim tpVecPlayerPostion As D3DVECTOR
85
86 Static lLastTickCount As Long
87
88 l = GetTickCount
89
90 If lLastTickCount = 0 Then lLastTickCount = l
91
92 sgTimeDiff = (l - lLastTickCount) / 1000
93
94 If sgTimeDiff < 0.015 Then Exit Sub
95
96 lLastTickCount = l
97
98 '--- Car parameters:
99
100 ' sgMaxSpeedForward = 33.3333333333333 ' = 120 km/h '(meters per second)
101 ' sgMaxSpeedForward = 41.6666666666667 ' = 150 km/h '(meters per second)
102 sgMaxSpeedForward = 52.7777777777778 ' = 190 km/h '(meters per second)
103 ' sgMaxSpeedForward = 66.6666666666667 ' = 240 km/h '(meters per second)
104 sgMaxSpeedBackwards = -10 ' = -36 km/h
105
106 sgAccelerate = 3 ' m / (s ^ 2)
107
108 sgSlowDown = 2 ' m / (s ^ 2)
109 sgBreak = 30 ' m / (s ^ 2)
110
111 sgSteeringAccelerate = 1
112 sgSteeringRelease = 1.5
113
114 sgReduceSteeringBySpeed = 0.2 '.1
115 sgReduceSteeringAccelerationBySpeed = -1.4
116
117 '-----------------------
118
119 sgSpeedRotation = 120 * sgTimeDiff
120
121 For lPlayerIndex = 1 To clGame.Col_clPlayers.Count
122
123 Set clPlayer = clGame.Col_clPlayers(lPlayerIndex)
124
125 With clPlayer
126
127 .sgAcceleration = 0
128
129 s = sgAccelerate * sgTimeDiff
130
131 If (.lPlayerControlFlags And ePCF_Forward) = ePCF_Forward Then
132
133 If .sgSpeed < sgMaxSpeedForward Then
134
135 .sgAcceleration = .sgAcceleration + s
136
137 If .sgAcceleration > 1 Then .sgAcceleration = 1
138
139 End If
140
141 ElseIf (.lPlayerControlFlags And ePCF_Backward) = ePCF_Backward Then ' Move backwards
142
143 If .sgSpeed > sgMaxSpeedBackwards Then
144
145 .sgAcceleration = .sgAcceleration - s
146
147 If .sgAcceleration < -1 Then .sgAcceleration = -1
148
149 End If
150
151 Else
152
153 ' Let the car slow down (resistances)
154 If (.lPlayerControlFlags And ePCF_Break) = ePCF_Break Then s = sgBreak * sgTimeDiff Else s = sgSlowDown * sgTimeDiff
155
156 If Abs(.sgSpeed) >= s Then .sgSpeed = .sgSpeed - s * Sgn(.sgSpeed) Else .sgSpeed = 0
157
158 End If
159
160 s = sgSteeringAccelerate * sgTimeDiff
161
162 If (.lPlayerControlFlags And ePCF_Left) = ePCF_Left Then ' Rotate left
163
164 .sgSteeringWheelPosition = .sgSteeringWheelPosition + s * (1 - sgReduceSteeringAccelerationBySpeed * .sgSpeedRate) ' * Sgn(.sgSpeed) ' 0.1
165
166 If .sgSteeringWheelPosition > 1 Then .sgSteeringWheelPosition = 1
167
168 ElseIf (.lPlayerControlFlags And ePCF_Right) = ePCF_Right Then ' Rotate right
169
170 .sgSteeringWheelPosition = .sgSteeringWheelPosition - s * (1 - sgReduceSteeringAccelerationBySpeed * .sgSpeedRate) ' * Sgn(.sgSpeed) '0.1
171
172 If .sgSteeringWheelPosition < -1 Then .sgSteeringWheelPosition = -1
173
174 Else
175
176 s = sgSteeringRelease * sgTimeDiff
177
178 If Abs(.sgSteeringWheelPosition) >= s Then .sgSteeringWheelPosition = .sgSteeringWheelPosition - s * Sgn(.sgSteeringWheelPosition) Else .sgSteeringWheelPosition = 0
179
180 End If
181
182 .sgAngleY = .sgAngleY + .sgSteeringWheelPosition * (sgSpeedRotation - sgReduceSteeringBySpeed * .sgSpeedRate)
183
184 If .sgAngleY > 360 Then .sgAngleY = .sgAngleY - 360
185
186 If .sgAngleY < 0 Then .sgAngleY = .sgAngleY + 360
187
188 sgPlayerAngleRad = .sgAngleY * Const_sgDeg2Rad
189
190 .sgSpeed = .sgSpeed + .sgAcceleration
191
192 .sgSpeedRate = .sgSpeed / sgMaxSpeedForward
193
194 sgDX = -Sin(sgPlayerAngleRad)
195 sgDZ = Cos(sgPlayerAngleRad)
196
197 sgDXMove = .sgSpeed * sgDX * sgTimeDiff
198 sgDZMove = .sgSpeed * sgDZ * sgTimeDiff
199
200 tpVecPlayerPostion = .GetPosition
201
202 tpVecPlayerPostion.X = tpVecPlayerPostion.X - sgDXMove
203 tpVecPlayerPostion.Z = tpVecPlayerPostion.Z - sgDZMove
204
205 sgScale = 1
206
207 sgX = Form_D3D.Picture_TrackMap.ScaleWidth / 2 - sgScale * tpVecPlayerPostion.X
208 sgY = Form_D3D.Picture_TrackMap.ScaleHeight / 2 + sgScale * tpVecPlayerPostion.Z
209
210 If Form_D3D.Picture_TrackMap.Point(sgX, sgY) <> vbBlack Then ' do we drive off road ?)
211
212 sgGroundBump = Cos(tpVecPlayerPostion.X * 2) * Sin(tpVecPlayerPostion.Z * 2)
213 .sgSpeed = .sgSpeed - 25 * sgTimeDiff * .sgSpeedRate
214
215 tpVecPlayerPostion.Y = 0.3 * .sgSpeedRate * Abs(sgGroundBump)
216 .sgSteeringWheelPosition = .sgSteeringWheelPosition + 0.1 * .sgSpeedRate * sgGroundBump
217 .bOffroad = True
218
219 Else
220
221 tpVecPlayerPostion.Y = 0
222 .bOffroad = False
223
224 End If
225
226 lNextTrackSegment = .lTrackSegment + 1
227
228 If lNextTrackSegment > clScene.Col_clTrackSegments.Count Then lNextTrackSegment = 1
229
230 lLastTrackSegment = .lTrackSegment - 1
231
232 If lLastTrackSegment < 1 Then lLastTrackSegment = clScene.Col_clTrackSegments.Count
233
234 Set clTrackSegment = clScene.Col_clTrackSegments(lNextTrackSegment)
235
236 If clTrackSegment.GetSide(tpVecPlayerPostion) Then
237
238 .lTrackSegment = lNextTrackSegment
239
240 If .lTrackSegment = 1 Then
241
242 .lRoundCount = .lRoundCount + 1
243
244 If .sgRoundBestTime = 0 Then
245
246 .sgRoundBestTime = .sgRoundTime
247
248 ElseIf .sgRoundTime < .sgRoundBestTime Then
249
250 .sgRoundBestTime = .sgRoundTime
251
252 End If
253
254 .sgRoundTime = 0
255
256 End If
257
258 End If
259
260 If .lTrackSegment = 0 Then
261
262 .sgRoundTime = 0
263
264 Else
265
266 .sgRoundTime = .sgRoundTime + sgTimeDiff
267
268 Set clTrackSegment = clScene.Col_clTrackSegments(.lTrackSegment)
269
270 If Not clTrackSegment.GetSide(tpVecPlayerPostion) Then
271
272 .lTrackSegment = lLastTrackSegment
273
274 End If
275
276 End If
277
278 .SetPosition tpVecPlayerPostion
279
280 clD3DDevice.SetTransform D3DTS_VIEW, CreatePlayerViewMatrix
281
282 End With
283
284 Next lPlayerIndex
285
286 End Sub
287
288 Public Sub RemovePlayer(lPlayerHandle As Long)
289
290 Col_clPlayers.Remove "p" & lPlayerHandle
291
292 If lPlayerHandle = lLocalPlayerHandle Then lLocalPlayerHandle = 0
293
294 End Sub
295
296 Public Sub RemoveAllPlayers()
297
298 Set Col_clPlayers = New Collection
299
300 lLocalPlayerHandle = 0
301
302 End Sub

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed