-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuWhirley.pas
203 lines (174 loc) · 5.78 KB
/
uWhirley.pas
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
unit uWhirley;
interface
uses
GLScene, uObjects, GLMaterial, GLObjects, SysUtils, uOde,
uCollisions, GLTexture, VectorTypes, VectorGeometry, ODEImport2,
ODEGL2, GLParticleFX, uDynamicPlatform, Dialogs, uAudio, uClasses,
uPlayer;
type
TWhirley = class(TBaseGameObject)
private
FKey: Integer;
FAngle: Integer;
FODEManager: TODEManager;
public
procedure Init;
end;
TWhirleyAng = (waOn,waOff,waEnd);
TWhirleyButton = class(TBaseGameObject)
private
FKey: Integer;
FAng: TWhirleyAng;
FPlayer: TPlayer;
public
procedure Init;
end;
function AddWhirley(Game: TGame; Scene: TGLScene; ODEManager: TODEManager; MaterialLibrary: TGLMaterialLibrary;
Material: AnsiString;x,y: Single; Key: Integer; Angle: Integer): TGLPlane;
function AddWhirleyButton(Game: TGame; Scene: TGLScene; Player: TPlayer; MaterialLibrary: TGLMaterialLibrary;
Material: AnsiString;x,y: Single; key: Integer): TGLPlane;
implementation
{ TWhirley }
procedure WhirleyStep(Sender: TObject; deltaTime: Double);
var
Obj: TWhirley;
i: Integer;
R: TdMatrix3;
begin
Obj:= Sender as TWhirley;
for i:= 0 to Obj.Scene.Objects.Count - 1 do
if Obj.Scene.Objects[i] is TWhirleyButton then
if (Obj.Scene.Objects[i] as TWhirleyButton).FKey = Obj.FKey then
if (Obj.Scene.Objects[i] as TWhirleyButton).FAng = waOn then
begin
//if Obj.FAngle = 0 then begin Obj.FAngle:= 1; Obj.RollAngle:= 90; end;
//if Obj.FAngle = 1 then begin Obj.FAngle:= 0; Obj.RollAngle:= 0; end;
if Obj.FAngle = 0 then
if Obj.RollAngle < 90 then
begin
Obj.RollAngle:= Obj.RollAngle + 5;
GLMatrixToODER(Obj.Matrix,R);
dGeomSetRotation(Obj.FODEManager.GetObj(Obj.Name).Geom,R)
end else
begin
Obj.RollAngle:= 90;
GLMatrixToODER(Obj.Matrix,R);
dGeomSetRotation(Obj.FODEManager.GetObj(Obj.Name).Geom,R);
Obj.FAngle:= 1;
(Obj.Scene.Objects[i] as TWhirleyButton).FAng:= waEnd;
Exit;
end;
if Obj.FAngle = 1 then
if Obj.RollAngle > 0 then
begin
Obj.RollAngle:= Obj.RollAngle - 5;//180*deltaTime;
GLMatrixToODER(Obj.Matrix,R);
dGeomSetRotation(Obj.FODEManager.GetObj(Obj.Name).Geom,R)
end else
begin
Obj.RollAngle:= 0;
GLMatrixToODER(Obj.Matrix,R);
dGeomSetRotation(Obj.FODEManager.GetObj(Obj.Name).Geom,R);
Obj.FAngle:= 0;
(Obj.Scene.Objects[i] as TWhirleyButton).FAng:= waEnd;
Exit;
end;
end;
{begin
if Obj.Material.FrontProperties.Diffuse.Alpha > 0 then
begin
Obj.Material.FrontProperties.Diffuse.Alpha:=
Obj.Material.FrontProperties.Diffuse.Alpha - 0.1;
end else dGeomDisable(Obj.FODEManager.GetObj(Obj.Name).Geom);
end
else
begin
if Obj.Material.FrontProperties.Diffuse.Alpha < 1 then
begin
Obj.Material.FrontProperties.Diffuse.Alpha:=
Obj.Material.FrontProperties.Diffuse.Alpha + 0.1;
dGeomEnable(Obj.FODEManager.GetObj(Obj.Name).Geom);
end;
end;}
end;
procedure TWhirley.Init;
begin
Step:= WhirleyStep;
end;
{ TWhirleyButton }
procedure WhirleyButtonStep(Sender: TObject; deltaTime: Double);
var
Obj: TWhirleyButton;
begin
Obj:= Sender as TWhirleyButton;
if (Collision(Obj,Obj.FPlayer,0.4,0.4,0.4,0.4)) or
(Collision(Obj.FPlayer.Game.CollisionsList,Obj,920,0.4,0.4,1,1)) then
begin
Obj.Material.FrontProperties.Diffuse.Alpha:= 0;
if Obj.FAng <> waEnd then Obj.FAng:= waOn;
end else
begin
Obj.Material.FrontProperties.Diffuse.Alpha:= 1;
if Obj.FAng = waEnd then Obj.FAng:= waOff;
end;
end;
procedure TWhirleyButton.Init;
begin
Step:= WhirleyButtonStep;
end;
function AddWhirley(Game: TGame; Scene: TGLScene; ODEManager: TODEManager; MaterialLibrary: TGLMaterialLibrary;
Material: AnsiString;x,y: Single; Key: Integer; Angle: Integer): TGLPlane;
var
Obj: TWhirley;
R: TdMatrix3;
begin
Obj:= TWhirley(Scene.Objects.AddNewChild(TWhirley));
Obj.Position.SetPoint(X,Y+0.2,0);
Obj.TagFloat:= 1;
Obj.Tag:= 2003;
Obj.Name:= 'Object_' + IntToStr(Scene.Objects.Count);
Obj.FODEManager:= ODEManager;
with ODEManager.AddObj(Obj,otStatic,gtBox) do
begin
SetScale(0.2,4,1);
Init;
end;
Obj.FAngle:= Angle;
if Angle = 0 then Obj.RollAngle:= 0;
if Angle = 1 then Obj.RollAngle:= 90;
GLMatrixToODER(Obj.Matrix,R);
dGeomSetRotation(ODEManager.GetObj(Obj.Name).Geom,R);
Obj.Scale.SetVector(0.3,4,1);
Obj.Material.MaterialLibrary:= MaterialLibrary;
Obj.Material.LibMaterialName:= Material;
Obj.Init;
end;
function AddWhirleyButton(Game: TGame; Scene: TGLScene; Player: TPlayer; MaterialLibrary: TGLMaterialLibrary;
Material: AnsiString;x,y: Single; key: Integer): TGLPlane;
var
Obj: TWhirleyButton;
Mat: TGLMaterial;
begin
Obj:= TWhirleyButton(Scene.Objects.AddNewChild(TWhirleyButton));
Obj.Position.SetPoint(X,Y,0);
Obj.TagFloat:= 1;
Obj.Tag:= 2003;
Obj.Name:= 'Object_' + IntToStr(Scene.Objects.Count);
Obj.Scale.SetVector(1,1,1);
Mat:= MaterialLibrary.Materials.GetLibMaterialByName(Material).Material;
Obj.Material.Texture:= Mat.Texture;
Obj.Material.BlendingMode:= bmTransparency;
Obj.Material.BlendingMode:= bmTransparency;
Obj.Material.Texture.TextureMode:= tmModulate;
Obj.Material.FrontProperties.Ambient.SetColor(1,1,1, 1);
Obj.Material.FrontProperties.Diffuse.SetColor(1,1,1, 1);
Obj.Material.FrontProperties.Emission.SetColor(1,1,1, 1);
Obj.Material.FrontProperties.Specular.SetColor(1,1,1, 1);
Obj.FKey:= Key;
Obj.FAng:= waOff;
Obj.FPlayer:= Player;
Obj.Init;
Game.CollisionsList.Add(Obj);
Result:= Obj;
end;
end.