summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e90ae21)
raw | patch | inline | side by side (parent: e90ae21)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Fri, 21 Dec 2018 17:15:40 +0000 (19:15 +0200) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Fri, 21 Dec 2018 17:16:08 +0000 (19:16 +0200) |
src/game/g_phys.pas | patch | blob | history | |
src/game/g_weapons.pas | patch | blob | history |
diff --git a/src/game/g_phys.pas b/src/game/g_phys.pas
index 1e543d4f4b31c980be889bbdad0c5088d8783a24..ce56afefa1612f45ed881936519955d5b3bc7a0e 100644 (file)
--- a/src/game/g_phys.pas
+++ b/src/game/g_phys.pas
MOVE_BLOCK = 128;
procedure g_Obj_Init(Obj: PObj); inline;
-function g_Obj_Move(Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean = False): Word;
+function g_Obj_Move(Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean=False; asProjectile: Boolean=false): Word;
+function g_Obj_Move_Projectile (Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean=False): Word;
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;
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 g_Obj_GetSpeedDirF(Obj: PObj; var dirx, diry, speed: Double): Boolean; inline; // `false`: zero speed
+function g_Obj_GetAccelDirF(Obj: PObj; var dirx, diry, speed: Double): Boolean; inline; // `false`: zero speed
function z_dec(a, b: Integer): Integer; inline;
function z_fdec(a, b: Double): Double; inline;
end;
-function g_Obj_Move (Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean=False): Word;
+function g_Obj_Move_Projectile (Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean=False): Word;
+begin
+ result := g_Obj_Move(Obj, Fallable, Splash, ClimbSlopes, true);
+end;
+
+function g_Obj_Move (Obj: PObj; Fallable: Boolean; Splash: Boolean; ClimbSlopes: Boolean=False; asProjectile: Boolean=false): Word;
var
xv, yv, dx, dy: Integer;
inwater: Boolean;
c: Boolean;
wtx: DWORD;
slopeStep: Integer;
+ dirx, diry, speed: Double;
label
_move;
begin
inwater := CollideLiquid(Obj, 0, 0);
if inwater then
begin
- xv := abs(Obj^.Vel.X)+1;
- if (xv > 5) then Obj^.Vel.X := z_dec(Obj^.Vel.X, (xv div 2)-2);
-
- yv := abs(Obj^.Vel.Y)+1;
- if (yv > 5) then Obj^.Vel.Y := z_dec(Obj^.Vel.Y, (yv div 2)-2);
-
- xv := abs(Obj^.Accel.X)+1;
- if (xv > 5) then Obj^.Accel.X := z_dec(Obj^.Accel.X, (xv div 2)-2);
+ if asProjectile then
+ begin
+ //writeln('velocity=(', Obj^.Vel.X, ',', Obj^.Vel.Y, '); acceleration=(', Obj^.Accel.X, ',', Obj^.Accel.Y, ')');
+ if (g_Obj_GetSpeedDirF(Obj, dirx, diry, speed)) then
+ begin
+ if (speed > 4) then
+ begin
+ speed := speed/2.0;
+ Obj^.Vel.X := round(dirx*speed);
+ Obj^.Vel.Y := round(diry*speed);
+ end;
+ end;
- yv := abs(Obj^.Accel.Y)+1;
- if (yv > 5) then Obj^.Accel.Y := z_dec(Obj^.Accel.Y, (yv div 2)-2);
+ // acceleration
+ if (g_Obj_GetAccelDirF(Obj, dirx, diry, speed)) then
+ begin
+ if (speed > 4) then
+ begin
+ speed := speed/2.0;
+ Obj^.Accel.X := round(dirx*speed);
+ Obj^.Accel.Y := round(diry*speed);
+ end;
+ end;
+ end
+ else
+ begin
+ // velocity
+ xv := abs(Obj^.Vel.X)+1;
+ if (xv > 5) then Obj^.Vel.X := z_dec(Obj^.Vel.X, (xv div 2)-2);
+ yv := abs(Obj^.Vel.Y)+1;
+ if (yv > 5) then Obj^.Vel.Y := z_dec(Obj^.Vel.Y, (yv div 2)-2);
+
+ // acceleration
+ xv := abs(Obj^.Accel.X)+1;
+ if (xv > 5) then Obj^.Accel.X := z_dec(Obj^.Accel.X, (xv div 2)-2);
+ yv := abs(Obj^.Accel.Y)+1;
+ if (yv > 5) then Obj^.Accel.Y := z_dec(Obj^.Accel.Y, (yv div 2)-2);
+ end;
end;
// Óìåíüøàåì ïðèáàâêó ê ñêîðîñòè
Obj^.Vel.Y := (vy*s) div m;
end;
+// `false`: zero speed
+function g_Obj_GetSpeedDirF(Obj: PObj; var dirx, diry, speed: Double): Boolean; inline;
+var
+ len, vx, vy: Double;
+begin
+ if (Obj^.Vel.X = 0) and (Obj^.Vel.Y = 0) then
+ begin
+ dirx := 0;
+ diry := 0;
+ speed := 0;
+ result := false;
+ exit;
+ end;
+
+ vx := Obj^.Vel.X;
+ vy := Obj^.Vel.Y;
+ len := sqrt(vx*vx+vy*vy);
+ dirx := vx/len;
+ diry := vy/len;
+ speed := len;
+ result := true;
+end;
+
+// `false`: zero acceleratin
+function g_Obj_GetAccelDirF(Obj: PObj; var dirx, diry, speed: Double): Boolean; inline;
+var
+ len, vx, vy: Double;
+begin
+ if (Obj^.Accel.X = 0) and (Obj^.Accel.Y = 0) then
+ begin
+ dirx := 0;
+ diry := 0;
+ speed := 0;
+ result := false;
+ exit;
+ end;
+
+ vx := Obj^.Accel.X;
+ vy := Obj^.Accel.Y;
+ len := sqrt(vx*vx+vy*vy);
+ dirx := vx/len;
+ diry := vy/len;
+ speed := len;
+ result := true;
+end;
+
// Ïðèáëèæàåì a ê 0 íà b åäèíèö:
function z_dec (a, b: Integer): Integer; inline;
diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index 3b1330170a988940f5d158494d4972a722faff6d..78965efd9378623329c16f2778abfd4daa412098 100644 (file)
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
if Stopped = 0 then
begin
- st := g_Obj_Move(@Obj, False, spl);
+ st := g_Obj_Move_Projectile(@Obj, False, spl);
end
else
begin