-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.p
executable file
·259 lines (215 loc) · 5.65 KB
/
Game.p
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
unit Game;
interface
uses
Sound, QDOffScreen, Tools, Globals, GameGlobals, GameTools, Animations, Car, RoadDraw, Display, Objects,
ToolUtils, Resources, Dialogs, Events;
procedure DoGame;
procedure BeginGame;
procedure EndGame;
procedure GameUpdate;
implementation
procedure DoGame;
var
Timer: longint;
DRECT:Rect;
begin
if GamePlay then
begin
Timer := TickCount;
SetGworld(ScreenWorld, nil);
if LockPixels(GetGworldPixMap(ScreenWorld)) and not GamePause then
begin
DoBackground;
DoObjects;
DoCar;
DoAnimations;
DoControl;
DoDisplay;
end;
if GamePause then
begin
KillEngine;
SetRect(DRECT,320-43,240-21,320+43,240+21);
DrawPicture(GetPicture(2040),DRECT);
URects[15]:=DRECT;
end;
BlitToScreen;
UnlockPixels(GetGWorldPixMap(Screenworld));
while TickCount<Timer+GamePrefs^^.Speed do ;
if GameOCount = 6 then
EndGame;
end;
end;
procedure BeginGame;
var
drawRect: rect;
procedure InitWorlds;
begin
Depth := TheScreen^^.gdPMap^^.PixelSize;
if Depth > 8 then
Depth := 8;
ScreenCT:=GetCTable(1000+Depth);
SetRect(drawRect, 0, 0, 620, 480);
DoError(NewGWorld(Screenworld, Depth, drawRect, ScreenCT, nil, keeplocal));
SetGworld(ScreenWorld, nil);
EraseRect(drawRect);
SetGWorld(CGrafPtr(Shellwindow),Thescreen);
SetRect(drawRect, 0, -44, GamePrefs^^.TextureSize, 480);
if BitTst(@GamePrefs^^.GrafFlags, 3) then
DoError(NewGWorld(Backworld, Depth, drawRect,ScreenCT, nil, keeplocal));
DoError(HandToHand(Handle(ScreenCT)));
end;
procedure FadeBlackWindow;
const
FadeSpeed = 40;
var
i: integer;
begin
for i:= 1 to FadeSpeed do
Screenblood(1,TRUE,TRUE,TRUE);
if BitTst(@GamePrefs^^.GrafFlags, 1) then begin
if Depth<8 then SetCLUT;
RaceWindow := GetNewWindow(1001, nil, Pointer(-1));
MoveWindow(RaceWindow, 0, 0, False);
SizeWindow(RaceWindow, TheScreen^^.gdpmap^^.bounds.right - TheScreen^^.gdpmap^^.bounds.left, TheScreen^^.gdpmap^^.bounds.bottom - TheScreen^^.gdpmap^^.bounds.top, false);
SetPort(RaceWindow);
SetOrigin(-RaceWindow^.portrect.right div 2+310,-RaceWindow^.portrect.bottom div 2+240);
Hidemenubar;
SetCLUT;
end else begin
SetCLUT;
RaceWindow := GetNewWindow(1002, nil, Pointer(-1));
end;
end;
procedure InitInterface;
begin
GamePlay := True;
EnableItem(FileMenu, 2);
EnableItem(FileMenu, 4);
DisableItem(FileMenu, 1);
DisableItem(OptMenu, 1);
DisableItem(OptMenu, 7);
DisposeWindow(ShellWindow);
ShellWindow:= nil;
FadeBlackWindow;
end;
procedure InitMask;
var
X: GWorldPtr;
MyClip, InvRgn: RgnHandle;
DrawingRect:Rect;
function InitMaskWorld: GWorldPtr;
type
RectHandle = ^RectPtr;
var
GWldSize: Rect;
WriteWorld: GworldPtr;
begin
SetRect(GWldSize, 0, 0, 620, 100);
DoError(NewGWorld(WriteWorld, 1, GWldSize, nil, nil, 0) );
if LockPixels(GetGWorldPixMap(WriteWorld)) then
begin
SetGWorld(WriteWorld, nil);
FillRect(GWldSize, qd.white);
SetRect(DrawingRect, 0, 0, 100, 100);
DrawPicture(GetPicture(2000), DrawingRect);
SetRect(DrawingRect, 100, 72, 620, 100);
FillRect(DrawingRect, qd.black);
SetGWorld(CGrafPtr(RaceWindow), TheScreen);
UnlockPixels(GetGWorldPixMap(WriteWorld));
InitMaskWorld := WriteWorld;
end;
end;
begin
X := InitMaskWorld;
MyClip := NewRgn;
InvRgn := NewRgn;
DoError(BitMapToRegion(MyClip, BitMapHandle(GetGWorldPixMap(X))^^));
DisposeGWorld(X);
OffSetRgn(MyClip, 0, 480 - 100);
Rectrgn(InvRgn, RaceWindow^.portRect);
XorRgn(MyClip, InvRgn, MyClip);
Clip:= MyClip;
end;
procedure Drawscreen;
begin
SetPort(RaceWindow);
SetRect(DrawRect, 0, 0, 620, 480);
FillRect(DrawRect, qd.black);
SetRect(DrawRect,310-83,240-21,310+83,240+21);
DrawPicture(GetPicture(2030),DrawRect);
ReleaseResource(GetResource('PICT',2030));
InitMask;
BeginUpdate(RaceWindow);
EndUpdate(RaceWindow);
end;
procedure ReleaseMem;
begin
ReleaseResource(GetResource('PICT',2010));
ReleaseResource(GetResource('PICT',2011));
ReleaseResource(GetResource('PICT',2020));
ReleaseResource(GetResource('PICT',2021));
ReleaseResource(GetResource('PICT',2022));
end;
begin
ReleaseMem;
InitWorlds;
InitInterface;
DrawScreen;
PreLoadSprites;
CarID := 1000;
Score := 0;
Lives := 3;
oldScore:=-1;
oldLives:=-1;
Lastlive:=0;
GameOCount := 0;
GameOver := false;
EnterLevel(Level);
MyCar := CarHandle(GetResource('CAR ', CarID))^^;
end;
procedure EndGame;
function CancelTest: boolean;
begin
CancelTest := false;
if GameOCount = 6 then
CancelTest := true
else if Alert(1003, nil) = 1 then
CancelTest := true
else if BitTst(@GamePrefs^^.GrafFlags,1) then
ReHideMenuBar;
end;
begin
if CancelTest then
begin
ShowCursor;
ShowMenubar;
KillEngine;
if TheScreen^^.gdType = fixedType then
TheScreen^^.gdPMap^^.pmTable^^.ctseed := CTorig;
ShellWindow := GetNewWindow(1000, nil, RaceWindow);
GamePlay := False;
DisposeWindow(RaceWindow);
RaceWindow:=nil;
DisposeGWorld(BackWorld);
DisposeGWorld(ScreenWorld);
DisposeLevel;
EnableItem(FileMenu, 1);
EnableItem(OptMenu, 1);
EnableItem(OptMenu, 7);
DisableItem(FileMenu, 2);
DisableItem(FileMenu, 4);
EnterHighScore(Score);
end;
end;
procedure GameUpdate;
var
InstrRect:Rect;
begin
BeginUpdate(RaceWindow);
SetRect(InstrRect,0,480-100,620,480);
if RectInRgn(InstrRect,RaceWindow^.visRgn) then
DrawInstr;
EndUpdate(RaceWindow);
end;
end.