forked from jeff-1amstudios/OpenC1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpponent.cs
79 lines (70 loc) · 2.66 KB
/
Opponent.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
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using OpenC1.Physics;
using StillDesign.PhysX;
namespace OpenC1
{
class Opponent
{
public Vehicle Vehicle;
public CpuDriver Driver;
BoundingSphere _boundingSphere;
public bool IsDead { get { return Driver.IsDead; } }
public Opponent(string carFile, Vector3 position, float direction)
: this(carFile, position, direction, null)
{
}
public Opponent(string carFile, Vector3 position, float direction, CpuDriver driver)
{
if (driver == null) driver = new CpuDriver();
Driver = driver;
Vehicle = new Vehicle(GameVars.BasePath + @"cars\" + carFile, Driver);
if (driver is CopDriver)
{
Vehicle.Chassis.Actor.GlobalPosition = position;
Vehicle.Chassis.Actor.GlobalOrientation *= Matrix.CreateRotationY(MathHelper.ToRadians(90));
}
else
{
Vehicle.PlaceOnGrid(position, direction);
}
SetupVehicle();
}
public void SetupVehicle()
{
TireFunctionDescription frontLateralTireFn = new TireFunctionDescription();
frontLateralTireFn.ExtremumSlip = 0.26f;
frontLateralTireFn.ExtremumValue = 2.3f;
frontLateralTireFn.AsymptoteSlip = 2.21f;
frontLateralTireFn.AsymptoteValue = 0.001f;
TireFunctionDescription rearLateralTireFn = new TireFunctionDescription();
rearLateralTireFn.ExtremumSlip = 0.35f;
rearLateralTireFn.ExtremumValue = 2.3f;
rearLateralTireFn.AsymptoteSlip = 2.4f;
rearLateralTireFn.AsymptoteValue = 0.001f;
foreach (VehicleWheel wheel in Vehicle.Chassis.Wheels)
{
wheel.Shape.LateralTireForceFunction = wheel.IsRear ? rearLateralTireFn : frontLateralTireFn;
}
Vector3 massPos = Vehicle.Chassis.Actor.CenterOfMassLocalPosition;
massPos.Y -= 0.3f;
//Vehicle.Chassis.Actor.SetCenterOfMassOffsetLocalPosition(massPos);
}
public BoundingSphere GetBoundingSphere()
{
if (_boundingSphere.Radius == 0)
{
Bounds3 bounds = Vehicle.Chassis.Actor.Shapes[0].WorldSpaceBounds;
_boundingSphere = new BoundingSphere(Vector3.Zero, bounds.Size.Length());
}
_boundingSphere.Center = Vehicle.Position;
return _boundingSphere;
}
public void Kill()
{
Driver.IsDead = true;
}
}
}