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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
29 // going up the slope will set this, and renderer will adjust the position
30 // this is purely visual change, it won't affect anything else
31 slopeUpLeft
: Integer; // left to go
32 slopeFramesLeft
: Integer; // frames left to go
33 // for frame interpolation
35 procedure lerp(t
: Single; out fX
, fY
: Integer);
53 procedure g_Obj_Init(Obj
: PObj
); inline;
54 function g_Obj_Move(Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False; asProjectile
: Boolean=false): Word;
55 function g_Obj_Move_Projectile (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False): Word;
56 function g_Obj_Collide(Obj1
, Obj2
: PObj
): Boolean; inline; overload
;
57 function g_Obj_Collide(X
, Y
: Integer; Width
, Height
: Word; Obj
: PObj
): Boolean; inline; overload
;
58 function g_Obj_CollidePoint(X
, Y
: Integer; Obj
: PObj
): Boolean; inline;
59 function g_Obj_CollideLevel(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
60 function g_Obj_CollideStep(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
61 function g_Obj_CollideWater(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
62 function g_Obj_CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
63 function g_Obj_CollidePanel(Obj
: PObj
; XInc
, YInc
: Integer; PanelType
: Word): Boolean; inline;
64 function g_Obj_StayOnStep(Obj
: PObj
): Boolean; inline;
65 function g_Obj_CanMoveY(Obj
: PObj
; YInc
: Integer): Boolean; inline;
66 procedure g_Obj_Push(Obj
: PObj
; VelX
, VelY
: Integer); inline;
67 procedure g_Obj_PushA(Obj
: PObj
; Vel
: Integer; Angle
: SmallInt); inline;
68 procedure g_Obj_SetSpeed(Obj
: PObj
; s
: Integer); inline;
69 function g_Obj_GetSpeedDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline; // `false`: zero speed
70 function g_Obj_GetAccelDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline; // `false`: zero speed
71 function z_dec(a
, b
: Integer): Integer; inline;
72 function z_fdec(a
, b
: Double): Double; inline;
75 gMon
: Boolean = False;
80 g_map
, g_basic
, Math
, g_player
, g_console
, SysUtils
,
81 g_sound
, g_gfx
, MAPDEF
, g_monsters
, g_game
, utils
;
85 SmoothSlopeFrames
= 4;
87 procedure TObj
.lerp(t
: Single; out fX
, fY
: Integer);
89 fX
:= nlerp(oldX
, X
, t
);
90 fY
:= nlerp(oldY
, Y
, t
);
93 function g_Obj_StayOnStep(Obj
: PObj
): Boolean; inline;
95 Result
:= not g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
+Obj
^.Rect
.Height
-1,
98 and g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
+Obj
^.Rect
.Height
,
103 function g_Obj_CanMoveY(Obj
: PObj
; YInc
: Integer): Boolean; inline;
105 // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì ñòåíà => øàãàòü íåëüçÿ
106 // Èëè åñëè øàãíóòü âíèç, à òàì ñòóïåíü => øàãàòü íåëüçÿ
107 Result
:= not(g_Obj_CollideLevel(Obj
, 0, YInc
) or ((YInc
> 0) and g_Obj_StayOnStep(Obj
)));
110 function CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
112 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
113 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
*2 div 3,
114 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
117 function CollideLift(Obj
: PObj
; XInc
, YInc
: Integer): Integer; inline;
119 if g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
120 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
121 PANEL_LIFTUP
, False) then
123 else if g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
124 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
125 PANEL_LIFTDOWN
, False) then
131 function CollideHorLift(Obj
: PObj
; XInc
, YInc
: Integer): Integer; inline;
133 left
, right
: Boolean;
135 left
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
136 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
137 PANEL_LIFTLEFT
, False);
138 right
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
^.Rect
.Y
+YInc
,
139 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
140 PANEL_LIFTRIGHT
, False);
141 if left
and not right
then
143 else if right
and not left
then
149 function CollidePlayers(_Obj
: PObj
; XInc
, YInc
: Integer): Boolean;
154 if (gPlayers
= nil) then exit
;
155 for plr
in gPlayers
do
157 if (plr
= nil) then continue
;
158 if not plr
.alive
then continue
;
161 if g_Collide(GameX
+PLAYER_RECT
.X
, GameY
+PLAYER_RECT
.Y
,
162 PLAYER_RECT
.Width
, PLAYER_RECT
.Height
,
163 _Obj
^.X
+_Obj
^.Rect
.X
+XInc
, _Obj
^.Y
+_Obj
^.Rect
.Y
+YInc
,
164 _Obj
^.Rect
.Width
, _Obj
^.Rect
.Height
) then
173 function Blocked(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
175 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
176 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
177 PANEL_BLOCKMON
, False);
180 function g_Obj_CollideLevel(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
182 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
183 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
187 function g_Obj_CollideStep(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
189 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
190 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
194 function g_Obj_CollideWater(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
196 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
197 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
201 function g_Obj_CollideLiquid(Obj
: PObj
; XInc
, YInc
: Integer): Boolean; inline;
203 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
204 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
205 PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
, False);
208 function g_Obj_CollidePanel(Obj
: PObj
; XInc
, YInc
: Integer; PanelType
: Word): Boolean; inline;
210 Result
:= g_Map_CollidePanel(Obj
^.X
+Obj
^.Rect
.X
+XInc
, Obj
^.Y
+Obj
.Rect
.Y
+YInc
,
211 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
,
215 procedure g_Obj_Splash(Obj
: PObj
; Color
: Byte);
219 MaxVel
:= nmax(abs(Obj
^.Vel
.X
), abs(Obj
^.Vel
.Y
));
223 g_Sound_PlayExAt('SOUND_GAME_BULK1', Obj
^.X
, Obj
^.Y
)
225 g_Sound_PlayExAt('SOUND_GAME_BULK2', Obj
^.X
, Obj
^.Y
);
228 g_GFX_Water(Obj
^.X
+Obj
^.Rect
.X
+(Obj
^.Rect
.Width
div 2),
229 Obj
^.Y
+Obj
^.Rect
.Y
+(Obj
^.Rect
.Height
div 2),
230 Min(5*(abs(Obj
^.Vel
.X
)+abs(Obj
^.Vel
.Y
)), 50),
231 -Obj
^.Vel
.X
, -Obj
^.Vel
.Y
,
232 Obj
^.Rect
.Width
, 16, Color
);
236 function move (Obj
: PObj
; dx
, dy
: Integer; ClimbSlopes
: Boolean): Word;
242 procedure slope (s
: Integer);
247 while g_Obj_CollideLevel(Obj
, sx
, 0) and (i
< 4) do
255 Obj
.slopeUpLeft
+= i
*(-s
);
256 Obj
.slopeFramesLeft
:= SmoothSlopeFrames
;
260 function movex (): Boolean;
264 // Åñëè ìîíñòðó øàãíóòü â ñòîðîíó, à òàì áëîêìîí
265 if gMon
and ((st
and MOVE_BLOCK
) = 0) then
267 if Blocked(Obj
, sx
, 0) then st
:= st
or MOVE_BLOCK
;
270 // Åñëè øàãíóòü â ñòîðîíó, à òàì ñòåíà => øàãàòü íåëüçÿ
271 if g_Obj_CollideLevel(Obj
, sx
, 0) then
273 if ClimbSlopes
and (abs(dy
) < 2) then
276 if (not g_Obj_CollideLevel(Obj
, sx
, -12)) and // çàáèðàåìñÿ íà 12 ïèêñåëåé âëåâî/âïðàâî
277 (sy
>= 0) and (not g_Obj_CanMoveY(Obj
, sy
)) then // òîëüêî åñëè åñòü çåìëÿ ïîä íîãàìè
284 st
:= st
or MOVE_HITWALL
;
289 st
:= st
or MOVE_HITWALL
;
292 else // Òàì ñòåíû íåò
294 if CollideLiquid(Obj
, sx
, 0) then
295 begin // Åñëè øàãíóòü â ñòîðîíó, à òàì òåïåðü æèäêîñòü
296 if ((st
and MOVE_INWATER
) = 0) then st
:= st
or MOVE_HITWATER
;
298 else // Åñëè øàãíóòü â ñòîðîíó, à òàì óæå íåò æèäêîñòè
300 if ((st
and MOVE_INWATER
) <> 0) then st
:= st
or MOVE_HITAIR
;
309 function movey (): Boolean;
313 // Åñëè ìîíñòðó øàãíóòü ïî âåðòèêàëè, à òàì áëîêìîí
314 if gMon
and ((st
and MOVE_BLOCK
) = 0) then
316 if Blocked(Obj
, 0, sy
) then st
:= st
or MOVE_BLOCK
;
319 // Åñëè øàãàòü íåëüçÿ
320 if not g_Obj_CanMoveY(Obj
, sy
) then
323 st
:= st
or MOVE_HITLAND
325 st
:= st
or MOVE_HITCEIL
;
327 else // Òàì ñòåíû íåò. È ñòóïåíè ñíèçó òîæå íåò
329 if CollideLiquid(Obj
, 0, sy
) then
330 begin // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì òåïåðü æèäêîñòü
331 if ((st
and MOVE_INWATER
) = 0) then st
:= st
or MOVE_HITWATER
;
333 else // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì óæå íåò æèäêîñòè
335 if ((st
and MOVE_INWATER
) <> 0) then st
:= st
or MOVE_HITAIR
;
347 // Îáúåêò â æèäêîñòè?
348 if CollideLiquid(Obj
, 0, 0) then st
:= st
or MOVE_INWATER
;
350 // Ìîíñòð â áëîêìîíå?
353 if Blocked(Obj
, 0, 0) then st
:= st
or MOVE_BLOCK
;
356 // Äâèãàòüñÿ íå íàäî?
357 if (dx
= 0) and (dy
= 0) then begin result
:= st
; exit
; end;
359 sx
:= g_basic
.Sign(dx
);
360 sy
:= g_basic
.Sign(dy
);
364 for i
:= 1 to dx
do if not movex() then break
;
365 for i
:= 1 to dy
do if not movey() then break
;
371 procedure g_Obj_Init (Obj
: PObj
); inline;
373 ZeroMemory(Obj
, SizeOf(TObj
));
377 function g_Obj_Move_Projectile (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False): Word;
379 result
:= g_Obj_Move(Obj
, Fallable
, Splash
, ClimbSlopes
, true);
382 function g_Obj_Move (Obj
: PObj
; Fallable
: Boolean; Splash
: Boolean; ClimbSlopes
: Boolean=False; asProjectile
: Boolean=false): Word;
384 xv
, yv
, dx
, dy
: Integer;
389 dirx
, diry
, speed
: Double;
393 // Ëèìèòû íà ñêîðîñòü è óñêîðåíèå
394 Obj
^.Vel
.X
:= nclamp(Obj
^.Vel
.X
, -LIMIT_VEL
, LIMIT_VEL
);
395 Obj
^.Vel
.Y
:= nclamp(Obj
^.Vel
.Y
, -LIMIT_VEL
, LIMIT_VEL
);
396 Obj
^.Accel
.X
:= nclamp(Obj
^.Accel
.X
, -LIMIT_ACCEL
, LIMIT_ACCEL
);
397 Obj
^.Accel
.Y
:= nclamp(Obj
^.Accel
.Y
, -LIMIT_ACCEL
, LIMIT_ACCEL
);
399 if Obj^.Vel.X < -LIMIT_VEL then Obj^.Vel.X := -LIMIT_VEL
400 else if Obj^.Vel.X > LIMIT_VEL then Obj^.Vel.X := LIMIT_VEL;
401 if Obj^.Vel.Y < -LIMIT_VEL then Obj^.Vel.Y := -LIMIT_VEL
402 else if Obj^.Vel.Y > LIMIT_VEL then Obj^.Vel.Y := LIMIT_VEL;
403 if Obj^.Accel.X < -LIMIT_ACCEL then Obj^.Accel.X := -LIMIT_ACCEL
404 else if Obj^.Accel.X > LIMIT_ACCEL then Obj^.Accel.X := LIMIT_ACCEL;
405 if Obj^.Accel.Y < -LIMIT_ACCEL then Obj^.Accel.Y := -LIMIT_ACCEL
406 else if Obj^.Accel.Y > LIMIT_ACCEL then Obj^.Accel.Y := LIMIT_ACCEL;
409 // Âûëåòåë çà íèæíþþ ãðàíèöó êàðòû?
410 if (Obj
^.Y
> Integer(gMapInfo
.Height
)+128) then begin result
:= MOVE_FALLOUT
; Obj
.slopeUpLeft
:= 0; Obj
.slopeFramesLeft
:= 0; exit
; end;
412 // Ìåíÿåì ñêîðîñòü è óñêîðåíèå òîëüêî ïî ÷åòíûì êàäðàì
413 c
:= (gTime
mod (GAME_TICK
*2) <> 0);
416 if {not c and} (Obj
.slopeUpLeft
> 0) then
418 if (Obj
.slopeFramesLeft
< 1) then
420 //conwritefln('SLOPE DONE: slopeUpLeft=%s', [Obj.slopeUpLeft]);
421 Obj
.slopeUpLeft
:= 0; // oops
425 slopeStep
:= Obj
.slopeUpLeft
div Obj
.slopeFramesLeft
;
426 if (slopeStep
< 1) then slopeStep
:= 1;
427 //conwritefln('SLOPE STEP: slopeUpLeft=%s; slopeFramesLeft=%s; slopeStep=%d', [Obj.slopeUpLeft, Obj.slopeFramesLeft, slopeStep]);
428 Dec(Obj
.slopeFramesLeft
);
429 Obj
.slopeUpLeft
-= slopeStep
;
430 if (Obj
.slopeUpLeft
< 1) then
432 Obj
.slopeUpLeft
:= 0;
433 Obj
.slopeFramesLeft
:= 0;
438 if c
then goto _move
;
440 case CollideLift(Obj
, 0, 0) of
443 Obj
^.Vel
.Y
-= 1; // Ëèôò ââåðõ
444 if (Obj
^.Vel
.Y
< -5) then Obj
^.Vel
.Y
+= 1;
448 if (Obj
^.Vel
.Y
> 5) then Obj
^.Vel
.Y
-= 1;
449 Obj
^.Vel
.Y
+= 1; // Ãðàâèòàöèÿ èëè ëèôò âíèç
453 if Fallable
then Obj
^.Vel
.Y
+= 1; // Ãðàâèòàöèÿ
454 if (Obj
^.Vel
.Y
> MAX_YV
) then Obj
^.Vel
.Y
-= 1;
458 case CollideHorLift(Obj
, 0, 0) of
462 if (Obj
^.Vel
.X
< -9) then Obj
^.Vel
.X
+= 3;
467 if (Obj
^.Vel
.X
> 9) then Obj
^.Vel
.X
-= 3;
469 // 0 is not needed here
473 inwater
:= CollideLiquid(Obj
, 0, 0);
478 //writeln('velocity=(', Obj^.Vel.X, ',', Obj^.Vel.Y, '); acceleration=(', Obj^.Accel.X, ',', Obj^.Accel.Y, ')');
479 if (g_Obj_GetSpeedDirF(Obj
, dirx
, diry
, speed
)) then
481 //writeln('SPEED: ', speed);
485 Obj
^.Vel
.X
:= round(dirx
*speed
);
486 Obj
^.Vel
.Y
:= round(diry
*speed
);
491 if (g_Obj_GetAccelDirF(Obj
, dirx
, diry
, speed
)) then
496 Obj
^.Accel
.X
:= round(dirx
*speed
);
497 Obj
^.Accel
.Y
:= round(diry
*speed
);
504 xv
:= abs(Obj
^.Vel
.X
)+1;
505 if (xv
> 5) then Obj
^.Vel
.X
:= z_dec(Obj
^.Vel
.X
, (xv
div 2)-2);
506 yv
:= abs(Obj
^.Vel
.Y
)+1;
507 if (yv
> 5) then Obj
^.Vel
.Y
:= z_dec(Obj
^.Vel
.Y
, (yv
div 2)-2);
510 xv
:= abs(Obj
^.Accel
.X
)+1;
511 if (xv
> 5) then Obj
^.Accel
.X
:= z_dec(Obj
^.Accel
.X
, (xv
div 2)-2);
512 yv
:= abs(Obj
^.Accel
.Y
)+1;
513 if (yv
> 5) then Obj
^.Accel
.Y
:= z_dec(Obj
^.Accel
.Y
, (yv
div 2)-2);
517 // Óìåíüøàåì ïðèáàâêó ê ñêîðîñòè
518 Obj
^.Accel
.X
:= z_dec(Obj
^.Accel
.X
, 1);
519 Obj
^.Accel
.Y
:= z_dec(Obj
^.Accel
.Y
, 1);
523 xv
:= Obj
^.Vel
.X
+Obj
^.Accel
.X
;
524 yv
:= Obj
^.Vel
.Y
+Obj
^.Accel
.Y
;
529 result
:= move(Obj
, dx
, dy
, ClimbSlopes
);
531 // Áðûçãè (åñëè íóæíû)
534 if WordBool(Result
and MOVE_HITWATER
) then
536 wtx
:= g_Map_CollideLiquid_Texture(Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
537 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
*2 div 3);
539 LongWord(TEXTURE_SPECIAL_WATER
): g_Obj_Splash(Obj
, 3);
540 LongWord(TEXTURE_SPECIAL_ACID1
): g_Obj_Splash(Obj
, 2);
541 LongWord(TEXTURE_SPECIAL_ACID2
): g_Obj_Splash(Obj
, 1);
542 LongWord(TEXTURE_NONE
): begin end;
543 else g_Obj_Splash(Obj
, 0);
548 // Ìåíÿåì ñêîðîñòü è óñêîðåíèå òîëüêî ïî ÷åòíûì êàäðàì
551 // Âðåçàëèñü â ñòåíó - ñòîï
552 if ((Result
and MOVE_HITWALL
) <> 0) then
558 // Âðåçàëèñü â ïîë èëè ïîòîëîê - ñòîï
559 if ((Result
and (MOVE_HITCEIL
or MOVE_HITLAND
)) <> 0) then
567 function g_Obj_Collide(Obj1
, Obj2
: PObj
): Boolean; inline;
569 Result
:= g_Collide(Obj1
^.X
+Obj1
^.Rect
.X
, Obj1
^.Y
+Obj1
^.Rect
.Y
,
570 Obj1
^.Rect
.Width
, Obj1
^.Rect
.Height
,
571 Obj2
^.X
+Obj2
^.Rect
.X
, Obj2
^.Y
+Obj2
^.Rect
.Y
,
572 Obj2
^.Rect
.Width
, Obj2
^.Rect
.Height
);
575 function g_Obj_Collide(X
, Y
: Integer; Width
, Height
: Word; Obj
: PObj
): Boolean; inline;
577 Result
:= g_Collide(X
, Y
,
579 Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
580 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
);
583 function g_Obj_CollidePoint(X
, Y
: Integer; Obj
: PObj
): Boolean; inline;
585 Result
:= g_CollidePoint(X
, Y
, Obj
^.X
+Obj
^.Rect
.X
, Obj
^.Y
+Obj
^.Rect
.Y
,
586 Obj
^.Rect
.Width
, Obj
^.Rect
.Height
);
589 procedure g_Obj_Push(Obj
: PObj
; VelX
, VelY
: Integer); inline;
591 Obj
^.Vel
.X
:= Obj
^.Vel
.X
+ VelX
;
592 Obj
^.Vel
.Y
:= Obj
^.Vel
.Y
+ VelY
;
595 procedure g_Obj_PushA(Obj
: PObj
; Vel
: Integer; Angle
: SmallInt); inline;
600 SinCos(DegToRad(-Angle
), s
, c
);
602 Obj
^.Vel
.X
:= Obj
^.Vel
.X
+ Round(Vel
*c
);
603 Obj
^.Vel
.Y
:= Obj
^.Vel
.Y
+ Round(Vel
*s
);
606 procedure g_Obj_SetSpeed(Obj
: PObj
; s
: Integer); inline;
613 m
:= Max(abs(vx
), abs(vy
));
617 Obj
^.Vel
.X
:= (vx
*s
) div m
;
618 Obj
^.Vel
.Y
:= (vy
*s
) div m
;
621 // `false`: zero speed
622 function g_Obj_GetSpeedDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline;
626 if (Obj
^.Vel
.X
= 0) and (Obj
^.Vel
.Y
= 0) then
637 len
:= sqrt(vx
*vx
+vy
*vy
);
644 // `false`: zero acceleratin
645 function g_Obj_GetAccelDirF(Obj
: PObj
; var dirx
, diry
, speed
: Double): Boolean; inline;
649 if (Obj
^.Accel
.X
= 0) and (Obj
^.Accel
.Y
= 0) then
660 len
:= sqrt(vx
*vx
+vy
*vy
);
668 // Ïðèáëèæàåì a ê 0 íà b åäèíèö:
669 function z_dec (a
, b
: Integer): Integer; inline;
671 if (abs(a
) < b
) then result
:= 0
672 else if (a
> 0) then result
:= a
-b
673 else if (a
< 0) then result
:= a
+b
674 else result
:= 0; // a = 0
678 // Ïðèáëèæàåì a ê 0.0 íà b åäèíèö:
679 function z_fdec (a
, b
: Double): Double; inline;
681 if (abs(a
) < b
) then result
:= 0.0
682 else if (a
> 0.0) then result
:= a
-b
683 else if (a
< 0.0) then result
:= a
+b
684 else result
:= 0.0; // a = 0.0