add bounce effect to bouncy world edges
authorsheepluva
Sun, 16 Nov 2014 17:56:27 +0100
changeset 10508 1a91c1fcba0d
parent 10507 ed5df9cd251f
child 10509 d62d3c706947
add bounce effect to bouncy world edges
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsHandlersMess.pas	Sun Nov 16 17:23:58 2014 +0100
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Nov 16 17:56:27 2014 +0100
@@ -310,7 +310,6 @@
     tX, tdX, tdY: hwFloat;
     collV, collH, gX, gY: LongInt;
     land, xland: word;
-    boing: PVisualGear;
 begin
     tX:= Gear^.X;
     gX:= hwRound(Gear^.X);
@@ -467,20 +466,7 @@
     if ((xland or land) and lfBouncy <> 0) and (Gear^.Radius >= 3) and
        ((Gear^.dX.QWordValue > _0_15.QWordValue) or (Gear^.dY.QWordValue > _0_15.QWordValue)) then
         begin
-        boing:= AddVisualGear(gX, gY, vgtStraightShot, 0, false, 1);
-        if boing <> nil then
-            with boing^ do
-                begin
-                Angle:= random(360);
-                dx:= 0;
-                dy:= 0;
-                FrameTicks:= 200;
-                tX:= _0;
-                tX.QWordValue:= Gear^.dY.QWordValue + Gear^.dX.QWordValue;
-                Scale:= hwFloat2Float(Gear^.Density * tX) / 1.5;
-                State:= ord(sprBoing)
-                end;
-        PlaySound(sndMelonImpact, true)
+        AddBounceEffectForGear(Gear);
         end
     else if (Gear^.nImpactSounds > 0) and
         (Gear^.State and gstCollision <> 0) and
--- a/hedgewars/uGearsUtils.pas	Sun Nov 16 17:23:58 2014 +0100
+++ b/hedgewars/uGearsUtils.pas	Sun Nov 16 17:56:27 2014 +0100
@@ -25,6 +25,7 @@
 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword); inline;
 procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
 procedure AddSplashForGear(Gear: PGear; justSkipping: boolean);
+procedure AddBounceEffectForGear(Gear: PGear);
 
 function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
 procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
@@ -1441,7 +1442,7 @@
             Gear^.X:= int2hwfloat(rightX-Gear^.Radius)
             end;
         if (Gear^.Radius > 2) and (Gear^.dX.QWordValue > _0_001.QWordValue) then
-            PlaySound(sndMelonImpact)
+            AddBounceEffectForGear(Gear);
         end{
     else if WorldEdge = weSea then
         begin
@@ -1476,4 +1477,21 @@
     end;
 end;
 
+procedure AddBounceEffectForGear(Gear: PGear);
+var boing: PVisualGear;
+begin
+    boing:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtStraightShot, 0, false, 1);
+    if boing <> nil then
+        with boing^ do
+            begin
+            Angle:= random(360);
+            dx:= 0;
+            dy:= 0;
+            FrameTicks:= 200;
+            Scale:= hwFloat2Float(Gear^.Density * hwAbs(Gear^.dY) + hwAbs(Gear^.dX)) / 1.5;
+            State:= ord(sprBoing)
+            end;
+    PlaySound(sndMelonImpact, true)
+end;
+
 end.