1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
31 // going up the slope will set this, and renderer will adjust the position
32 // this is purely visual change, it won't affect anything else
33 slopeUpLeft
: Integer; // left to go
34 slopeFramesLeft
: Integer; // frames left to go
52 procedure g_Obj_Init(Obj
: PObj
); inline;
53 function g_Obj_Move(Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False; asProjectile
: Boolean=false): Word;
54 function g_Obj_Move_Projectile (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False): Word;
55 function g_Obj_Collide(Obj1
, Obj2
: PObj
): Boolean; inline; overload
;
56 function g_Obj_Collide(X
, Y
: Integer; Width
, Height
: Word; Obj
: PObj
): Boolean; inline; overload
;
57 function g_Obj_CollidePoint(X
, Y
: Integer; Obj
: PObj
): Boolean; inline;
58 function g_Obj_CollideLevel(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
59 function g_Obj_CollideStep(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
60 function g_Obj_CollideWater(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
61 function g_Obj_CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
62 function g_Obj_CollidePanel(Obj
: PObj
; XInc
, YInc
: Integer; PanelType
: Word): Boolean; inline;
63 function g_Obj_StayOnStep(Obj
: PObj
): Boolean; inline;
64 function g_Obj_CanMoveY(Obj
: PObj
; YInc
: Integer): Boolean; inline;
65 procedure g_Obj_Push(Obj
: PObj
; VelX
, VelY
: Integer); inline;
66 procedure g_Obj_PushA(Obj
: PObj
; Vel
: Integer; Angle
: SmallInt
); inline;
67 procedure g_Obj_SetSpeed(Obj
: PObj
; s
: Integer); inline;
68 function g_Obj_GetSpeedDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline; // `false`: zero speed
69 function g_Obj_GetAccelDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline; // `false`: zero speed
70 function z_dec(a
, b
: Integer): Integer; inline;
71 function z_fdec(a
, b
: Double): Double; inline;
74 gMon
: Boolean = False;
79 g_map
, g_basic
, Math
, g_player
, g_console
, SysUtils
,
80 g_sound
, g_gfx
, MAPDEF
, g_monsters
, g_game
, utils
;
84 SmoothSlopeFrames
= 4;
87 function g_Obj_StayOnStep(Obj
: PObj
): Boolean; inline;
89 Result
:= not g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
+Obj
^.Rect
.Height
-1,
92 and g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
+Obj
^.Rect
.Height
,
97 function g_Obj_CanMoveY(Obj
: PObj
; YInc
: Integer): Boolean; inline;
99 // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì ñòåíà => øàãàòü íåëüçÿ
100 // Èëè åñëè øàãíóòü âíèç, à òàì ñòóïåíü => øàãàòü íåëüçÿ
101 Result
:= not(g_Obj_CollideLevel(Obj
, 0, YInc
) or ((YInc
> 0) and g_Obj_StayOnStep(Obj
)));
104 function CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
106 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
107 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
*2 div 3,
108 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
111 function CollideLift(Obj
: PObj
; XInc
, YInc
: Integer): Integer; inline;
113 if g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
114 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
115 PANEL_LIFTUP
, False) then
117 else if g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
118 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
119 PANEL_LIFTDOWN
, False) then
125 function CollideHorLift(Obj
: PObj
; XInc
, YInc
: Integer): Integer; inline;
127 left
, right
: Boolean;
129 left
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
130 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
131 PANEL_LIFTLEFT
, False);
132 right
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
133 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
134 PANEL_LIFTRIGHT
, False);
135 if left
and not right
then
137 else if right
and not left
then
143 function CollidePlayers(_Obj
: PObj
; XInc
, YInc
: Integer): Boolean;
148 if (gPlayers
= nil) then exit
;
149 for plr
in gPlayers
do
151 if (plr
= nil) then continue
;
152 if not plr
.alive
then continue
;
155 if g_Collide(GameX
+PLAYER_RECT
.X
, GameY
+PLAYER_RECT
.Y
,
156 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
157 _Obj
^.X
+_Obj
^.Rect
.X
+XInc
, _Obj
^.Y
+_Obj
^.Rect
.Y
+YInc
,
158 _Obj
^.Rect
.Width
, _Obj
^.Rect
.Height
) then
167 function Blocked(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
169 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
170 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
171 PANEL_BLOCKMON
, False);
174 function g_Obj_CollideLevel(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
176 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
177 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
181 function g_Obj_CollideStep(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
183 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
184 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
188 function g_Obj_CollideWater(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
190 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
191 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
195 function g_Obj_CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
197 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
198 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
199 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
202 function g_Obj_CollidePanel(Obj
: PObj
; XInc
, YInc
: Integer; PanelType
: Word): Boolean; inline;
204 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
205 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
209 procedure g_Obj_Splash(Obj
: PObj
; Color
: Byte);
213 MaxVel
:= nmax(abs(Obj
^.Vel
.X
), abs(Obj
^.Vel
.Y
));
217 g_Sound_PlayExAt('SOUND_GAME_BULK1', Obj
^.X
, Obj
^.Y
)
219 g_Sound_PlayExAt('SOUND_GAME_BULK2', Obj
^.X
, Obj
^.Y
);
222 g_GFX_Water(Obj
^.X
+Obj
^.Rect
.X
+(Obj
^.Rect
.Width
div 2),
223 Obj
^.Y
+Obj
^.Rect
.Y
+(Obj
^.Rect
.Height
div 2),
224 Min(5*(abs(Obj
^.Vel
.X
)+abs(Obj
^.Vel
.Y
)), 50),
225 -Obj
^.Vel
.X
, -Obj
^.Vel
.Y
,
226 Obj
^.Rect
.Width
, 16, Color
);
230 function move (Obj
: PObj
; dx
, dy
: Integer; ClimbSlopes
: Boolean): Word;
236 procedure slope (s
: Integer);
241 while g_Obj_CollideLevel(Obj
, sx
, 0) and (i
< 4) do
249 Obj
.slopeUpLeft
+= i
*(-s
);
250 Obj
.slopeFramesLeft
:= SmoothSlopeFrames
;
254 function movex (): Boolean;
258 // Åñëè ìîíñòðó øàãíóòü â ñòîðîíó, à òàì áëîêìîí
259 if gMon
and ((st
and MOVE_BLOCK
) = 0) then
261 if Blocked(Obj
, sx
, 0) then st
:= st
or MOVE_BLOCK
;
264 // Åñëè øàãíóòü â ñòîðîíó, à òàì ñòåíà => øàãàòü íåëüçÿ
265 if g_Obj_CollideLevel(Obj
, sx
, 0) then
267 if ClimbSlopes
and (abs(dy
) < 2) then
270 if (not g_Obj_CollideLevel(Obj
, sx
, -12)) and // çàáèðàåìñÿ íà 12 ïèêñåëåé âëåâî/âïðàâî
271 (sy
>= 0) and (not g_Obj_CanMoveY(Obj
, sy
)) then // òîëüêî åñëè åñòü çåìëÿ ïîä íîãàìè
278 st
:= st
or MOVE_HITWALL
;
283 st
:= st
or MOVE_HITWALL
;
286 else // Òàì ñòåíû íåò
288 if CollideLiquid(Obj
, sx
, 0) then
289 begin // Åñëè øàãíóòü â ñòîðîíó, à òàì òåïåðü æèäêîñòü
290 if ((st
and MOVE_INWATER
) = 0) then st
:= st
or MOVE_HITWATER
;
292 else // Åñëè øàãíóòü â ñòîðîíó, à òàì óæå íåò æèäêîñòè
294 if ((st
and MOVE_INWATER
) <> 0) then st
:= st
or MOVE_HITAIR
;
303 function movey (): Boolean;
307 // Åñëè ìîíñòðó øàãíóòü ïî âåðòèêàëè, à òàì áëîêìîí
308 if gMon
and ((st
and MOVE_BLOCK
) = 0) then
310 if Blocked(Obj
, 0, sy
) then st
:= st
or MOVE_BLOCK
;
313 // Åñëè øàãàòü íåëüçÿ
314 if not g_Obj_CanMoveY(Obj
, sy
) then
317 st
:= st
or MOVE_HITLAND
319 st
:= st
or MOVE_HITCEIL
;
321 else // Òàì ñòåíû íåò. È ñòóïåíè ñíèçó òîæå íåò
323 if CollideLiquid(Obj
, 0, sy
) then
324 begin // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì òåïåðü æèäêîñòü
325 if ((st
and MOVE_INWATER
) = 0) then st
:= st
or MOVE_HITWATER
;
327 else // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì óæå íåò æèäêîñòè
329 if ((st
and MOVE_INWATER
) <> 0) then st
:= st
or MOVE_HITAIR
;
341 // Îáúåêò â æèäêîñòè?
342 if CollideLiquid(Obj
, 0, 0) then st
:= st
or MOVE_INWATER
;
344 // Ìîíñòð â áëîêìîíå?
347 if Blocked(Obj
, 0, 0) then st
:= st
or MOVE_BLOCK
;
350 // Äâèãàòüñÿ íå íàäî?
351 if (dx
= 0) and (dy
= 0) then begin result
:= st
; exit
; end;
353 sx
:= g_basic
.Sign(dx
);
354 sy
:= g_basic
.Sign(dy
);
358 for i
:= 1 to dx
do if not movex() then break
;
359 for i
:= 1 to dy
do if not movey() then break
;
365 procedure g_Obj_Init (Obj
: PObj
); inline;
367 ZeroMemory(Obj
, SizeOf(TObj
));
371 function g_Obj_Move_Projectile (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False): Word;
373 result
:= g_Obj_Move(Obj
, Fallable
, Splash
, ClimbSlopes
, true);
376 function g_Obj_Move (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False; asProjectile
: Boolean=false): Word;
378 xv
, yv
, dx
, dy
: Integer;
383 dirx
, diry
, speed
: Double;
387 // Ëèìèòû íà ñêîðîñòü è óñêîðåíèå
388 Obj
^.Vel
.X
:= nclamp(Obj
^.Vel
.X
, -LIMIT_VEL
, LIMIT_VEL
);
389 Obj
^.Vel
.Y
:= nclamp(Obj
^.Vel
.Y
, -LIMIT_VEL
, LIMIT_VEL
);
390 Obj
^.Accel
.X
:= nclamp(Obj
^.Accel
.X
, -LIMIT_ACCEL
, LIMIT_ACCEL
);
391 Obj
^.Accel
.Y
:= nclamp(Obj
^.Accel
.Y
, -LIMIT_ACCEL
, LIMIT_ACCEL
);
393 if Obj^.Vel.X < -LIMIT_VEL then Obj^.Vel.X := -LIMIT_VEL
394 else if Obj^.Vel.X > LIMIT_VEL then Obj^.Vel.X := LIMIT_VEL;
395 if Obj^.Vel.Y < -LIMIT_VEL then Obj^.Vel.Y := -LIMIT_VEL
396 else if Obj^.Vel.Y > LIMIT_VEL then Obj^.Vel.Y := LIMIT_VEL;
397 if Obj^.Accel.X < -LIMIT_ACCEL then Obj^.Accel.X := -LIMIT_ACCEL
398 else if Obj^.Accel.X > LIMIT_ACCEL then Obj^.Accel.X := LIMIT_ACCEL;
399 if Obj^.Accel.Y < -LIMIT_ACCEL then Obj^.Accel.Y := -LIMIT_ACCEL
400 else if Obj^.Accel.Y > LIMIT_ACCEL then Obj^.Accel.Y := LIMIT_ACCEL;
403 // Âûëåòåë çà íèæíþþ ãðàíèöó êàðòû?
404 if (Obj
^.Y
> Integer(gMapInfo
.Height
)+128) then begin result
:= MOVE_FALLOUT
; Obj
.slopeUpLeft
:= 0; Obj
.slopeFramesLeft
:= 0; exit
; end;
406 // Ìåíÿåì ñêîðîñòü è óñêîðåíèå òîëüêî ïî ÷åòíûì êàäðàì
407 c
:= (gTime
mod (GAME_TICK
*2) <> 0);
410 if {not c and} (Obj
.slopeUpLeft
> 0) then
412 if (Obj
.slopeFramesLeft
< 1) then
414 //conwritefln('SLOPE DONE: slopeUpLeft=%s', [Obj.slopeUpLeft]);
415 Obj
.slopeUpLeft
:= 0; // oops
419 slopeStep
:= Obj
.slopeUpLeft
div Obj
.slopeFramesLeft
;
420 if (slopeStep
< 1) then slopeStep
:= 1;
421 //conwritefln('SLOPE STEP: slopeUpLeft=%s; slopeFramesLeft=%s; slopeStep=%d', [Obj.slopeUpLeft, Obj.slopeFramesLeft, slopeStep]);
422 Dec(Obj
.slopeFramesLeft
);
423 Obj
.slopeUpLeft
-= slopeStep
;
424 if (Obj
.slopeUpLeft
< 1) then
426 Obj
.slopeUpLeft
:= 0;
427 Obj
.slopeFramesLeft
:= 0;
432 if c
then goto _move
;
434 case CollideLift(Obj
, 0, 0) of
437 Obj
^.Vel
.Y
-= 1; // Ëèôò ââåðõ
438 if (Obj
^.Vel
.Y
< -5) then Obj
^.Vel
.Y
+= 1;
442 if (Obj
^.Vel
.Y
> 5) then Obj
^.Vel
.Y
-= 1;
443 Obj
^.Vel
.Y
+= 1; // Ãðàâèòàöèÿ èëè ëèôò âíèç
447 if Fallable
then Obj
^.Vel
.Y
+= 1; // Ãðàâèòàöèÿ
448 if (Obj
^.Vel
.Y
> MAX_YV
) then Obj
^.Vel
.Y
-= 1;
452 case CollideHorLift(Obj
, 0, 0) of
456 if (Obj
^.Vel
.X
< -9) then Obj
^.Vel
.X
+= 3;
461 if (Obj
^.Vel
.X
> 9) then Obj
^.Vel
.X
-= 3;
463 // 0 is not needed here
467 inwater
:= CollideLiquid(Obj
, 0, 0);
472 //writeln('velocity=(', Obj^.Vel.X, ',', Obj^.Vel.Y, '); acceleration=(', Obj^.Accel.X, ',', Obj^.Accel.Y, ')');
473 if (g_Obj_GetSpeedDirF(Obj
, dirx
, diry
, speed
)) then
475 //writeln('SPEED: ', speed);
479 Obj
^.Vel
.X
:= round(dirx
*speed
);
480 Obj
^.Vel
.Y
:= round(diry
*speed
);
485 if (g_Obj_GetAccelDirF(Obj
, dirx
, diry
, speed
)) then
490 Obj
^.Accel
.X
:= round(dirx
*speed
);
491 Obj
^.Accel
.Y
:= round(diry
*speed
);
498 xv
:= abs(Obj
^.Vel
.X
)+1;
499 if (xv
> 5) then Obj
^.Vel
.X
:= z_dec(Obj
^.Vel
.X
, (xv
div 2)-2);
500 yv
:= abs(Obj
^.Vel
.Y
)+1;
501 if (yv
> 5) then Obj
^.Vel
.Y
:= z_dec(Obj
^.Vel
.Y
, (yv
div 2)-2);
504 xv
:= abs(Obj
^.Accel
.X
)+1;
505 if (xv
> 5) then Obj
^.Accel
.X
:= z_dec(Obj
^.Accel
.X
, (xv
div 2)-2);
506 yv
:= abs(Obj
^.Accel
.Y
)+1;
507 if (yv
> 5) then Obj
^.Accel
.Y
:= z_dec(Obj
^.Accel
.Y
, (yv
div 2)-2);
511 // Óìåíüøàåì ïðèáàâêó ê ñêîðîñòè
512 Obj
^.Accel
.X
:= z_dec(Obj
^.Accel
.X
, 1);
513 Obj
^.Accel
.Y
:= z_dec(Obj
^.Accel
.Y
, 1);
517 xv
:= Obj
^.Vel
.X
+Obj
^.Accel
.X
;
518 yv
:= Obj
^.Vel
.Y
+Obj
^.Accel
.Y
;
523 result
:= move(Obj
, dx
, dy
, ClimbSlopes
);
525 // Áðûçãè (åñëè íóæíû)
528 if WordBool(Result
and MOVE_HITWATER
) then
530 wtx
:= g_Map_CollideLiquid_Texture(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
531 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
*2 div 3);
533 LongWord(TEXTURE_SPECIAL_WATER
): g_Obj_Splash(Obj
, 3);
534 LongWord(TEXTURE_SPECIAL_ACID1
): g_Obj_Splash(Obj
, 2);
535 LongWord(TEXTURE_SPECIAL_ACID2
): g_Obj_Splash(Obj
, 1);
536 LongWord(TEXTURE_NONE
): begin end;
537 else g_Obj_Splash(Obj
, 0);
542 // Ìåíÿåì ñêîðîñòü è óñêîðåíèå òîëüêî ïî ÷åòíûì êàäðàì
545 // Âðåçàëèñü â ñòåíó - ñòîï
546 if ((Result
and MOVE_HITWALL
) <> 0) then
552 // Âðåçàëèñü â ïîë èëè ïîòîëîê - ñòîï
553 if ((Result
and (MOVE_HITCEIL
or MOVE_HITLAND
)) <> 0) then
561 function g_Obj_Collide(Obj1
, Obj2
: PObj
): Boolean; inline;
563 Result
:= g_Collide(Obj1
^.X
+Obj1
^.Rect
.X
, Obj1
^.Y
+Obj1
^.Rect
.Y
,
564 Obj1
^.Rect
.Width
, Obj1
^.Rect
.Height
,
565 Obj2
^.X
+Obj2
^.Rect
.X
, Obj2
^.Y
+Obj2
^.Rect
.Y
,
566 Obj2
^.Rect
.Width
, Obj2
^.Rect
.Height
);
569 function g_Obj_Collide(X
, Y
: Integer; Width
, Height
: Word; Obj
: PObj
): Boolean; inline;
571 Result
:= g_Collide(X
, Y
,
573 Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
574 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
);
577 function g_Obj_CollidePoint(X
, Y
: Integer; Obj
: PObj
): Boolean; inline;
579 Result
:= g_CollidePoint(X
, Y
, Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
580 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
);
583 procedure g_Obj_Push(Obj
: PObj
; VelX
, VelY
: Integer); inline;
585 Obj
^.Vel
.X
:= Obj
^.Vel
.X
+ VelX
;
586 Obj
^.Vel
.Y
:= Obj
^.Vel
.Y
+ VelY
;
589 procedure g_Obj_PushA(Obj
: PObj
; Vel
: Integer; Angle
: SmallInt
); inline;
594 SinCos(DegToRad(-Angle
), s
, c
);
596 Obj
^.Vel
.X
:= Obj
^.Vel
.X
+ Round(Vel
*c
);
597 Obj
^.Vel
.Y
:= Obj
^.Vel
.Y
+ Round(Vel
*s
);
600 procedure g_Obj_SetSpeed(Obj
: PObj
; s
: Integer); inline;
607 m
:= Max(abs(vx
), abs(vy
));
611 Obj
^.Vel
.X
:= (vx
*s
) div m
;
612 Obj
^.Vel
.Y
:= (vy
*s
) div m
;
615 // `false`: zero speed
616 function g_Obj_GetSpeedDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline;
620 if (Obj
^.Vel
.X
= 0) and (Obj
^.Vel
.Y
= 0) then
631 len
:= sqrt(vx
*vx
+vy
*vy
);
638 // `false`: zero acceleratin
639 function g_Obj_GetAccelDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline;
643 if (Obj
^.Accel
.X
= 0) and (Obj
^.Accel
.Y
= 0) then
654 len
:= sqrt(vx
*vx
+vy
*vy
);
662 // Ïðèáëèæàåì a ê 0 íà b åäèíèö:
663 function z_dec (a
, b
: Integer): Integer; inline;
665 if (abs(a
) < b
) then result
:= 0
666 else if (a
> 0) then result
:= a
-b
667 else if (a
< 0) then result
:= a
+b
668 else result
:= 0; // a = 0
672 // Ïðèáëèæàåì a ê 0.0 íà b åäèíèö:
673 function z_fdec (a
, b
: Double): Double; inline;
675 if (abs(a
) < b
) then result
:= 0.0
676 else if (a
> 0.0) then result
:= a
-b
677 else if (a
< 0.0) then result
:= a
+b
678 else result
:= 0.0; // a = 0.0