-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaserComponent.ras
342 lines (320 loc) · 12.9 KB
/
LaserComponent.ras
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
procedure IncCurrentLaser(id: byte);
var
laserEmitId: byte;
begin
laserEmitId := objectList[id].laserEmitId;
if(laserList[laserEmitId].currentLaser < @MAX_LASER_SIZE) then
laserList[laserEmitId].currentLaser := laserList[laserEmitId].currentLaser + @LASER_STEP;
end;
function CalcFireExitDir(xdir, ydir: byte) : byte;
var
ret: byte;
begin
if (xdir = -1 and ydir = 0) then
ret := @RIGHT
else if (xdir = 1 and ydir = 0) then
ret := @LEFT
else if (xdir = 0 and ydir = -1) then
ret := @DOWN
else if (xdir = 0 and ydir = 1) then
ret := @UP
else
ret := $FF;
CalcFireExitDir := ret;
end;
procedure FireLaser(id: byte, xpos, ypos: byte, xdir, ydir: byte);
var
laserEmitId: byte;
laserId: byte;
collideId, collideId2, mirrorId, destroyAbleId, portalId, waterId: byte;
collide: boolean;
controlId: byte;
laserx, lasery, lastx, lasty: byte;
countLaser: byte;
turn: byte;
targetPortal: byte;
dir: byte;
portalIdMove : byte;
tempx, tempy, tempx2, tempy2, pos: byte;
laserType: byte;
collideControlId: byte;
begin
if(objectList[id].onOff = @ON) then begin
laserEmitId := objectList[id].laserEmitId;
controlId := $FF;
laserType := laserList[laserEmitId].laserType;
if(objectList[id].component0 & @COMP_CONTROL_0 = @COMP_CONTROL_0) then
controlId := objectList[id].controlId;
collide := false;
lastx := xpos;
lasty := ypos;
laserx := CalcPositionX(xpos, xdir);
lasery := CalcPositionY(ypos, ydir);
countLaser := 0;
if(laserType = @LASER_TYPE_USER and laserList[laserEmitId].currentLaser = @LASER_STEP) then begin
@PLAY_SOUND("3","sndLaser","255")
end;
collideId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_COLLIDE_ABLE_0, 0);
mirrorId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_MIRROR_1, 1);
// destroyAbleId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_DESTROY_ABLE_2, 2);
if ((collideId <> $FF and mirrorId = $FF) /* and destroyAbleId = $FF */ ) then collide := true;
while (collide = false and countLaser < laserList[laserEmitId].currentLaser) do begin
collideId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_COLLIDE_ABLE_0, 0);
mirrorId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_MIRROR_1, 1);
// destroyAbleId := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_DESTROY_ABLE_2, 2);
if ((collideId <> $FF and mirrorId = $FF) /* and destroyAbleId = $FF */) then collide := true
else begin
if (mapfront[laserx + ystart[lasery]] = $FF) then begin
laserId := GetId();
if(laserId <> $FF) then begin
if (xdir <> 0 and ydir = 0) then objectList[laserId].rendTilePos := $74
else if (xdir = 0 and ydir <> 0) then objectList[laserId].rendTilePos := $75;
if(laserType <> @LASER_TYPE_USER) then begin
objectList[laserId].component0 := $00 | @COMP_DESTROY_COLLIDE_0;
end
else
objectList[laserId].component0 := $00;
objectList[laserId].component1 := $00;
objectList[laserId].component2 := $00 | @COMP_LASERBEAN_2;
objectList[laserId].component3 := $00;
objectList[laserId].transX := laserx;
objectList[laserId].transY := lasery;
objectList[laserId].transZ := @Z_FRONT;
objectList[laserId].laserTag := id;
turn := $FF;
if(mirrorId <> $FF) then begin
turn := objectList[mirrorId].mirrorTurn;
// laser left
if (xdir = -1 and ydir = 0) then begin
if (turn = @TURN_RIGHT) then begin
xdir := 0;
ydir := -1;
objectList[laserId].rendTilePos := $79;
end
else if (turn = @TURN_LEFT) then begin
xdir := 0;
ydir := 1;
objectList[laserId].rendTilePos := $7a;
end
else if (turn = @TURN_THROUGH) then objectList[laserId].rendTilePos := $76;
end
// laser right
else if (xdir = 1 and ydir = 0) then begin
if (turn = @TURN_RIGHT) then begin
xdir := 0;
ydir := 1;
objectList[laserId].rendTilePos := $7b;
end
else if (turn = @TURN_LEFT) then begin
xdir := 0;
ydir := -1;
objectList[laserId].rendTilePos := $78;
end
else if (turn = @TURN_THROUGH) then objectList[laserId].rendTilePos := $76;
end
// laser up
else if (xdir = 0 and ydir = -1) then begin
if (turn = @TURN_RIGHT) then begin
xdir := 1;
ydir := 0;
objectList[laserId].rendTilePos := $7a;
end
else if (turn = @TURN_LEFT) then begin
xdir := -1;
ydir := 0;
objectList[laserId].rendTilePos := $7b;
end
else if (turn = @TURN_THROUGH) then objectList[laserId].rendTilePos := $77;
end
// laser down
else if (xdir = 0 and ydir = 1) then begin
if (turn = @TURN_RIGHT) then begin
xdir := -1;
ydir := 0;
objectList[laserId].rendTilePos := $78;
end
else if (turn = @TURN_LEFT) then begin
xdir := 1;
ydir := 0;
objectList[laserId].rendTilePos := $79;
end
else if (turn = @TURN_THROUGH) then objectList[laserId].rendTilePos := $77;
end;
end;
waterId := GetObjectByPosFilterComp(laserx, lasery, @Z_BACK2, @COMP_WATER_0, 0);
if(waterId <> $FF) then begin
if (xdir = 0 and ydir <> 0) then objectList[laserId].rendTilePos := $4d
else if (xdir <> 0 and ydir = 0) then objectList[laserId].rendTilePos := $4c;
end;
AddMapItem(laserId, laserx, lasery, @Z_FRONT);
PaintPos(laserx + ystart[lasery], false, $91);
end;
portalId := GetObjectByPosFilterComp(laserx, lasery, @Z_BACK1, @COMP_PORTAL_1, 1);
if(portalId <> $FF and (portals[0] <> $FF and portals[1] <> $FF)) then begin
if(portals[0] = portalId) then targetPortal := portals[1]
else targetPortal := portals[0];
laserx := objectList[targetPortal].transX;
lasery := objectList[targetPortal].transY;
if(objectList[targetPortal].portalFireExitDir = @UP) then begin
xdir := 0;
ydir := -1;
end
else if (objectList[targetPortal].portalFireExitDir = @DOWN) then begin
xdir := 0;
ydir := 1;
end
else if (objectList[targetPortal].portalFireExitDir = @LEFT) then begin
xdir := -1;
ydir := 0;
end
else if (objectList[targetPortal].portalFireExitDir = @RIGHT) then begin
xdir := 1;
ydir := 0;
end
end;
end;
lastx := laserx;
lasty := lasery;
laserx := CalcPositionX(laserx, xdir);
lasery := CalcPositionY(lasery, ydir);
inc(countLaser);
end;
end;
// Collide Actions
if(collide = true and collideId <> $FF) then begin
if(laserType <> @LASER_TYPE_USER) then begin
collideControlId := objectList[collideId].controlId;
if(collideControlId <> $FF and controlList[collideControlId].controlState <> @CTRL_STATE_DESTROY) then begin
@PLAY_SOUND("3","sndExplosion","200")
objectList[collideId].b_physFallDown := false;
controlList[collideControlId].controlState := @CTRL_STATE_DESTROY;
controlList[collideControlId].controlJumpStep := 0;
controlList[collideControlId].controlCollideLaserTag := id;
end;
end;
// PushPull
if(objectList[collideId].component1 & @COMP_PUSHPULL_1 = @COMP_PUSHPULL_1) then begin
if(mod(globaltime, 2) = 0) then begin
tempx := objectList[collideId].transX;
tempy := objectList[collideId].transY;
laserx := CalcPositionX(laserx, xdir * objectList[collideId].onOff);
lasery := CalcPositionY(lasery, ydir * objectList[collideId].onOff);
collideId2 := GetObjectByPosFilterComp(laserx, lasery, @Z_MAIN, @COMP_COLLIDE_ABLE_0, 0);
if(collideId2 = $FF) then begin
@PLAY_SOUND("1","sndShift","240")
objectList[collideId].transX := laserx;
objectList[collideId].transY := lasery;
SetPos(collideId, tempx, tempy, laserx, lasery, objectList[collideId].transZ);
end
end;
end;
// SwitchPos
if(laserType = @LASER_TYPE_USER and objectList[collideId].component2 & @COMP_LASERTRANS_ABLE_2 = @COMP_LASERTRANS_ABLE_2) then begin
if(mod(globaltime, 4) = 0) then begin
tempx := objectList[id].transX;
tempy := objectList[id].transY;
tempx2 := objectList[collideId].transX;
tempy2 := objectList[collideId].transY;
objectList[id].transX := tempx2;
objectList[id].transY := tempy2;
SetPos(id, tempx, tempy, tempx2, tempy2, objectList[id].transZ);
objectList[collideId].transX := tempx;
objectList[collideId].transY := tempy;
SetPos(collideId, tempx2, tempy2, tempx, tempy, objectList[id].transZ);
SetPos(id, tempx2, tempy2, tempx2, tempy2, objectList[id].transZ);
@PLAY_SOUND("1","sndTransport","240")
if(controlId <> $FF) then begin
controlList[controlId].b_waitRelease := true;
controlList[controlId].b_release := false;
end;
end;
end;
// PortalActivate
if(laserType = @LASER_TYPE_USER and objectList[collideId].component2 & @COMP_PORTAL_ACTIVATE_2 = @COMP_PORTAL_ACTIVATE_2) then begin
pos := lastx + ystart[lasty];
if(mapback1[pos] = $FF and mapmain[pos] = $FF) then begin
if(portals[0] <> $FF and portals[1] <> $FF) then begin
if(lastPortal = portals[0]) then portalIdMove := portals[1] else portalIdMove := portals[0];
tempx := objectList[portalIdMove].transX;
tempy := objectList[portalIdMove].transY;
SetPos(portalIdMove, tempx, tempy, lastx, lasty, @Z_BACK1);
objectList[portalIdMove].portalFireExitDir := CalcFireExitDir(xdir, ydir);
lastPortal := portalIdMove;
end
else begin
InitPortal(lastx, lasty, CalcFireExitDir(xdir, ydir));
PaintPos(lastx + ystart[lasty], false, $91);
end;
@PLAY_SOUND("2","sndPortalActivate","240")
if(controlId <> $FF) then begin
controlList[controlId].b_waitRelease := true;
controlList[controlId].b_release := false;
end;
end;
end;
end;
end;
end;
procedure UpdateLaser(id: byte);
var
id1,i,x,y: byte;
pos,id2: byte;
exit: boolean;
controlId : byte;
joy : byte;
laserEmitId: byte;
begin
exit := false;
joy := joy1;
controlId := $FF;
laserEmitId := objectList[id].laserEmitId;
if(objectList[id].component0 & @COMP_CONTROL_0 = @COMP_CONTROL_0) then begin
controlId := objectList[id].controlId;
if(gameMode = @MODE_COOP and controlId = 1) then joy := simJoy;
end;
if(gameMode = @MODE_SINGLE_2CHAR and (activeChar <> controlId and controlId <> $FF)) then
// do nothin
else begin
if(controlId <> $FF) then begin
if (controlList[controlId].b_waitRelease = true) then begin
if (controlList[controlId].b_release = true) then controlList[controlId].b_waitRelease := false
else begin
if (joy & joy_fire <> joy_fire) then controlList[controlId].b_release := true;
exit := true;
end;
end;
end;
if(exit = false) then begin
laserList[laserEmitId].laserDir := $FF;
if(((laserList[laserEmitId].laserType = @LASER_TYPE_USER and (joy & joy_fire = joy_fire and joy & joy_left = joy_left))) or laserList[laserEmitId].laserType = @LEFT) then begin
if (laserList[laserEmitId].lastLaserDir <> @LEFT) then laserList[laserEmitId].currentLaser := 0;
IncCurrentLaser(id);
FireLaser(id, objectList[id].transX,objectList[id].transY, -1, 0);
laserList[laserEmitId].laserDir := @LEFT;
laserList[laserEmitId].lastLaserDir := laserList[laserEmitId].laserDir;
end
else if(((laserList[laserEmitId].laserType = @LASER_TYPE_USER and (joy & joy_fire = joy_fire and joy & joy_right = joy_right))) or laserList[laserEmitId].laserType = @RIGHT) then begin
if (laserList[laserEmitId].lastLaserDir <> @RIGHT) then laserList[laserEmitId].currentLaser := 0;
IncCurrentLaser(id);
FireLaser(id, objectList[id].transX,objectList[id].transY, 1, 0);
laserList[laserEmitId].laserDir := @RIGHT;
laserList[laserEmitId].lastLaserDir := laserList[laserEmitId].laserDir;
end
else if(((laserList[laserEmitId].laserType = @LASER_TYPE_USER and (joy & joy_fire = joy_fire and joy & joy_up = joy_up))) or laserList[laserEmitId].laserType = @UP) then begin
if (laserList[laserEmitId].lastLaserDir <> @UP) then laserList[laserEmitId].currentLaser := 0;
IncCurrentLaser(id);
FireLaser(id, objectList[id].transX,objectList[id].transY, 0, -1);
laserList[laserEmitId].laserDir := @UP;
laserList[laserEmitId].lastLaserDir := laserList[laserEmitId].laserDir;
end
else if(((laserList[laserEmitId].laserType = @LASER_TYPE_USER and (joy & joy_fire = joy_fire and joy & joy_down = joy_down))) or laserList[laserEmitId].laserType = @DOWN) then begin
if (laserList[laserEmitId].lastLaserDir <> @DOWN) then laserList[laserEmitId].currentLaser := 0;
IncCurrentLaser(id);
FireLaser(id, objectList[id].transX,objectList[id].transY, 0, 1);
laserList[laserEmitId].laserDir := @DOWN;
laserList[laserEmitId].lastLaserDir := laserList[laserEmitId].laserDir;
end;
if(laserList[laserEmitId].laserDir = $FF) then laserList[laserEmitId].currentLaser := 0;
end;
end;
end;