X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_phys.pas;h=1e543d4f4b31c980be889bbdad0c5088d8783a24;hb=e24864cf808f2ef7a10fc41999b341ef8212fbe7;hp=a88ca21c9da246a2f61e2f76ff17160cc032681e;hpb=c7ee5fde8d382144cfd01bf9432031a827490e1b;p=d2df-sdl.git diff --git a/src/game/g_phys.pas b/src/game/g_phys.pas index a88ca21..1e543d4 100644 --- a/src/game/g_phys.pas +++ b/src/game/g_phys.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,20 +49,21 @@ const MOVE_HITAIR = 64; MOVE_BLOCK = 128; -procedure g_Obj_Init(Obj: PObj); +procedure g_Obj_Init(Obj: PObj); inline; function g_Obj_Move(Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean = False): Word; -function g_Obj_Collide(Obj1, Obj2: PObj): Boolean; overload; -function g_Obj_Collide(X, Y: Integer; Width, Height: Word; Obj: PObj): Boolean; overload; -function g_Obj_CollidePoint(X, Y: Integer; Obj: PObj): Boolean; -function g_Obj_CollideLevel(Obj: PObj; XInc, YInc: Integer): Boolean; -function g_Obj_CollideStep(Obj: PObj; XInc, YInc: Integer): Boolean; -function g_Obj_CollideWater(Obj: PObj; XInc, YInc: Integer): Boolean; -function g_Obj_CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; -function g_Obj_CollidePanel(Obj: PObj; XInc, YInc: Integer; PanelType: Word): Boolean; -function g_Obj_StayOnStep(Obj: PObj): Boolean; -procedure g_Obj_Push(Obj: PObj; VelX, VelY: Integer); -procedure g_Obj_PushA(Obj: PObj; Vel: Integer; Angle: SmallInt); -procedure g_Obj_SetSpeed(Obj: PObj; s: Integer); +function g_Obj_Collide(Obj1, Obj2: PObj): Boolean; inline; overload; +function g_Obj_Collide(X, Y: Integer; Width, Height: Word; Obj: PObj): Boolean; inline; overload; +function g_Obj_CollidePoint(X, Y: Integer; Obj: PObj): Boolean; inline; +function g_Obj_CollideLevel(Obj: PObj; XInc, YInc: Integer): Boolean; inline; +function g_Obj_CollideStep(Obj: PObj; XInc, YInc: Integer): Boolean; inline; +function g_Obj_CollideWater(Obj: PObj; XInc, YInc: Integer): Boolean; inline; +function g_Obj_CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; inline; +function g_Obj_CollidePanel(Obj: PObj; XInc, YInc: Integer; PanelType: Word): Boolean; inline; +function g_Obj_StayOnStep(Obj: PObj): Boolean; inline; +function g_Obj_CanMoveY(Obj: PObj; YInc: Integer): Boolean; inline; +procedure g_Obj_Push(Obj: PObj; VelX, VelY: Integer); inline; +procedure g_Obj_PushA(Obj: PObj; Vel: Integer; Angle: SmallInt); inline; +procedure g_Obj_SetSpeed(Obj: PObj; s: Integer); inline; function z_dec(a, b: Integer): Integer; inline; function z_fdec(a, b: Double): Double; inline; @@ -73,14 +74,14 @@ implementation uses g_map, g_basic, Math, g_player, g_console, SysUtils, - g_sound, g_gfx, MAPDEF, g_monsters, g_game, BinEditor, utils; + g_sound, g_gfx, MAPDEF, g_monsters, g_game, utils; const SmoothSlopeFrames = 4; -function g_Obj_StayOnStep(Obj: PObj): Boolean; +function g_Obj_StayOnStep(Obj: PObj): Boolean; inline; begin Result := not g_Map_CollidePanel(Obj^.X+Obj^.Rect.X, Obj^.Y+Obj^.Rect.Y+Obj^.Rect.Height-1, Obj^.Rect.Width, 1, @@ -90,14 +91,21 @@ begin PANEL_STEP, False); end; -function CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; +function g_Obj_CanMoveY(Obj: PObj; YInc: Integer): Boolean; inline; +begin + // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì ñòåíà => øàãàòü íåëüçÿ + // Èëè åñëè øàãíóòü âíèç, à òàì ñòóïåíü => øàãàòü íåëüçÿ + Result := not(g_Obj_CollideLevel(Obj, 0, YInc) or ((YInc > 0) and g_Obj_StayOnStep(Obj))); +end; + +function CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj^.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height*2 div 3, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False); end; -function CollideLift(Obj: PObj; XInc, YInc: Integer): Integer; +function CollideLift(Obj: PObj; XInc, YInc: Integer): Integer; inline; begin if g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj^.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, @@ -111,7 +119,7 @@ begin Result := 0; end; -function CollideHorLift(Obj: PObj; XInc, YInc: Integer): Integer; +function CollideHorLift(Obj: PObj; XInc, YInc: Integer): Integer; inline; var left, right: Boolean; begin @@ -138,7 +146,7 @@ begin for plr in gPlayers do begin if (plr = nil) then continue; - if not plr.Live then continue; + if not plr.alive then continue; with plr do begin if g_Collide(GameX+PLAYER_RECT.X, GameY+PLAYER_RECT.Y, @@ -153,42 +161,42 @@ begin end; end; -function Blocked(Obj: PObj; XInc, YInc: Integer): Boolean; +function Blocked(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, PANEL_BLOCKMON, False); end; -function g_Obj_CollideLevel(Obj: PObj; XInc, YInc: Integer): Boolean; +function g_Obj_CollideLevel(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, PANEL_WALL, False); end; -function g_Obj_CollideStep(Obj: PObj; XInc, YInc: Integer): Boolean; +function g_Obj_CollideStep(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, PANEL_STEP, False); end; -function g_Obj_CollideWater(Obj: PObj; XInc, YInc: Integer): Boolean; +function g_Obj_CollideWater(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, PANEL_WATER, False); end; -function g_Obj_CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; +function g_Obj_CollideLiquid(Obj: PObj; XInc, YInc: Integer): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, PANEL_WATER or PANEL_ACID1 or PANEL_ACID2, False); end; -function g_Obj_CollidePanel(Obj: PObj; XInc, YInc: Integer; PanelType: Word): Boolean; +function g_Obj_CollidePanel(Obj: PObj; XInc, YInc: Integer; PanelType: Word): Boolean; inline; begin Result := g_Map_CollidePanel(Obj^.X+Obj^.Rect.X+XInc, Obj^.Y+Obj.Rect.Y+YInc, Obj^.Rect.Width, Obj^.Rect.Height, @@ -257,7 +265,7 @@ var begin result := true; if (not g_Obj_CollideLevel(Obj, sx, -12)) and // çàáèðàåìñÿ íà 12 ïèêñåëåé âëåâî/âïðàâî - g_Obj_CollidePanel(Obj, 0, 1, PANEL_WALL or PANEL_STEP) then // òîëüêî åñëè åñòü çåìëÿ ïîä íîãàìè + (sy >= 0) and (not g_Obj_CanMoveY(Obj, sy)) then // òîëüêî åñëè åñòü çåìëÿ ïîä íîãàìè begin slope(-1); end @@ -299,9 +307,8 @@ var if Blocked(Obj, 0, sy) then st := st or MOVE_BLOCK; end; - // Åñëè øàãíóòü â ïî âåðòèêàëè, à òàì ñòåíà => øàãàòü íåëüçÿ - // Èëè åñëè øàãíóòü âíèç, à òàì ñòóïåíü => øàãàòü íåëüçÿ - if g_Obj_CollideLevel(Obj, 0, sy) or ((sy > 0) and g_Obj_StayOnStep(Obj)) then + // Åñëè øàãàòü íåëüçÿ + if not g_Obj_CanMoveY(Obj, sy) then begin if sy > 0 then st := st or MOVE_HITLAND @@ -352,7 +359,7 @@ begin end; -procedure g_Obj_Init (Obj: PObj); +procedure g_Obj_Init (Obj: PObj); inline; begin ZeroMemory(Obj, SizeOf(TObj)); end; @@ -385,7 +392,7 @@ begin } // Âûëåòåë çà íèæíþþ ãðàíèöó êàðòû? - if (Obj^.Y > gMapInfo.Height+128) then begin result := MOVE_FALLOUT; Obj.slopeUpLeft := 0; Obj.slopeFramesLeft := 0; exit; end; + if (Obj^.Y > Integer(gMapInfo.Height)+128) then begin result := MOVE_FALLOUT; Obj.slopeUpLeft := 0; Obj.slopeFramesLeft := 0; exit; end; // Ìåíÿåì ñêîðîñòü è óñêîðåíèå òîëüêî ïî ÷åòíûì êàäðàì c := (gTime mod (GAME_TICK*2) <> 0); @@ -514,7 +521,7 @@ _move: end; -function g_Obj_Collide(Obj1, Obj2: PObj): Boolean; +function g_Obj_Collide(Obj1, Obj2: PObj): Boolean; inline; begin Result := g_Collide(Obj1^.X+Obj1^.Rect.X, Obj1^.Y+Obj1^.Rect.Y, Obj1^.Rect.Width, Obj1^.Rect.Height, @@ -522,7 +529,7 @@ begin Obj2^.Rect.Width, Obj2^.Rect.Height); end; -function g_Obj_Collide(X, Y: Integer; Width, Height: Word; Obj: PObj): Boolean; +function g_Obj_Collide(X, Y: Integer; Width, Height: Word; Obj: PObj): Boolean; inline; begin Result := g_Collide(X, Y, Width, Height, @@ -530,19 +537,19 @@ begin Obj^.Rect.Width, Obj^.Rect.Height); end; -function g_Obj_CollidePoint(X, Y: Integer; Obj: PObj): Boolean; +function g_Obj_CollidePoint(X, Y: Integer; Obj: PObj): Boolean; inline; begin Result := g_CollidePoint(X, Y, Obj^.X+Obj^.Rect.X, Obj^.Y+Obj^.Rect.Y, Obj^.Rect.Width, Obj^.Rect.Height); end; -procedure g_Obj_Push(Obj: PObj; VelX, VelY: Integer); +procedure g_Obj_Push(Obj: PObj; VelX, VelY: Integer); inline; begin Obj^.Vel.X := Obj^.Vel.X + VelX; Obj^.Vel.Y := Obj^.Vel.Y + VelY; end; -procedure g_Obj_PushA(Obj: PObj; Vel: Integer; Angle: SmallInt); +procedure g_Obj_PushA(Obj: PObj; Vel: Integer; Angle: SmallInt); inline; var s, c: Extended; @@ -553,7 +560,7 @@ begin Obj^.Vel.Y := Obj^.Vel.Y + Round(Vel*s); end; -procedure g_Obj_SetSpeed(Obj: PObj; s: Integer); +procedure g_Obj_SetSpeed(Obj: PObj; s: Integer); inline; var m, vx, vy: Integer; begin