--- a/hedgewars/uGearsUtils.pas Thu Oct 05 18:26:08 2017 +0200
+++ b/hedgewars/uGearsUtils.pas Fri Oct 06 14:03:13 2017 +0200
@@ -56,6 +56,7 @@
function GetUtility(Hedgehog: PHedgehog): TAmmoType;
function WorldWrap(var Gear: PGear): boolean;
+function CalcWorldWrap(X, radius: LongInt): LongInt;
function IsHogLocal(HH: PHedgehog): boolean;
@@ -1598,6 +1599,27 @@
end;
end;
+// Takes an X coordinate and corrects if according to the world edge rules
+// Wrap-around: X will be wrapped
+// Bouncy: X will be kept inside the legal land (taking radius into account)
+// Other world edges: Just returns X
+// radius is a radius (gear radius) tolerance for an appropriate distance from bouncy world edges.
+// Set radius to 0 if you don't care.
+function CalcWorldWrap(X, radius: LongInt): LongInt;
+begin
+ if WorldEdge = weWrap then
+ if X < LongInt(leftX) then
+ X:= X + (LongInt(rightX) - LongInt(leftX))
+ else if X > LongInt(rightX) then
+ X:= X - (LongInt(rightX) - LongInt(leftX))
+ else if WorldEdge = weBounce then
+ if X - radius < LongInt(leftX) then
+ X:= LongInt(leftX) + radius
+ else if X + radius > LongInt(rightX) then
+ X:= LongInt(rightX) - radius;
+ CalcWorldWrap:= X;
+end;
+
procedure AddBounceEffectForGear(Gear: PGear);
var boing: PVisualGear;
begin