hedgewars/uGearsUtils.pas
changeset 12656 161c10db4f27
parent 12621 d972b31f8881
child 12712 31f7e0a31736
equal deleted inserted replaced
12655:913d25669131 12656:161c10db4f27
    54 
    54 
    55 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    55 function  GetAmmo(Hedgehog: PHedgehog): TAmmoType;
    56 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    56 function  GetUtility(Hedgehog: PHedgehog): TAmmoType;
    57 
    57 
    58 function WorldWrap(var Gear: PGear): boolean;
    58 function WorldWrap(var Gear: PGear): boolean;
       
    59 function CalcWorldWrap(X, radius: LongInt): LongInt;
    59 
    60 
    60 function IsHogLocal(HH: PHedgehog): boolean;
    61 function IsHogLocal(HH: PHedgehog): boolean;
    61 
    62 
    62 
    63 
    63 function MakeHedgehogsStep(Gear: PGear) : boolean;
    64 function MakeHedgehogsStep(Gear: PGear) : boolean;
  1596 *)
  1597 *)
  1597     WorldWrap:= true
  1598     WorldWrap:= true
  1598     end;
  1599     end;
  1599 end;
  1600 end;
  1600 
  1601 
       
  1602 // Takes an X coordinate and corrects if according to the world edge rules
       
  1603 // Wrap-around: X will be wrapped
       
  1604 // Bouncy: X will be kept inside the legal land (taking radius into account)
       
  1605 // Other world edges: Just returns X
       
  1606 // radius is a radius (gear radius) tolerance for an appropriate distance from bouncy world edges.
       
  1607 // Set radius to 0 if you don't care.
       
  1608 function CalcWorldWrap(X, radius: LongInt): LongInt;
       
  1609 begin
       
  1610     if WorldEdge = weWrap then
       
  1611         if X < LongInt(leftX) then
       
  1612              X:= X + (LongInt(rightX) - LongInt(leftX))
       
  1613         else if X > LongInt(rightX) then
       
  1614              X:= X - (LongInt(rightX) - LongInt(leftX))
       
  1615     else if WorldEdge = weBounce then
       
  1616         if X - radius < LongInt(leftX) then
       
  1617             X:= LongInt(leftX) + radius
       
  1618         else if X + radius > LongInt(rightX) then
       
  1619             X:= LongInt(rightX) - radius;
       
  1620     CalcWorldWrap:= X;
       
  1621 end;
       
  1622 
  1601 procedure AddBounceEffectForGear(Gear: PGear);
  1623 procedure AddBounceEffectForGear(Gear: PGear);
  1602 var boing: PVisualGear;
  1624 var boing: PVisualGear;
  1603 begin
  1625 begin
  1604     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1626     boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
  1605     if boing <> nil then
  1627     if boing <> nil then