Add bounce effect to cake when it touches bounce edge
authorWuzzy <Wuzzy2@mail.ru>
Mon, 06 Aug 2018 15:56:03 +0200
changeset 13609 13f68f3e7153
parent 13608 92b87845beeb
child 13610 f1b6070a6e14
Add bounce effect to cake when it touches bounce edge
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsHandlersMess.pas	Mon Aug 06 15:20:25 2018 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Mon Aug 06 15:56:03 2018 +0200
@@ -3568,6 +3568,10 @@
         Gear^.Angle := (LongInt(Gear^.Angle) + 2) and 3;
         Gear^.Karma := 0;
 
+        // Bounce effect
+        if (Gear^.Radius > 2) then
+            AddBounceEffectForGear(Gear, 0.55);
+
         // Reset CakePoints to fix cake angle
         cakeData:= PCakeData(Gear^.Data);
         with cakeData^ do
--- a/hedgewars/uGearsUtils.pas	Mon Aug 06 15:20:25 2018 +0200
+++ b/hedgewars/uGearsUtils.pas	Mon Aug 06 15:56:03 2018 +0200
@@ -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; imageScale: Single);
 procedure AddBounceEffectForGear(Gear: PGear);
 
 function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
@@ -1723,7 +1724,16 @@
     end;
 end;
 
+
+// Add an audiovisual bounce effect for gear after it bounced from bouncy material.
+// Graphical effect is based on speed.
 procedure AddBounceEffectForGear(Gear: PGear);
+begin
+    AddBounceEffectForGear(Gear, hwFloat2Float(Gear^.Density * hwAbs(Gear^.dY) + hwAbs(Gear^.dX)) / 1.5);
+end;
+
+// Same as above, but can specify the size of bounce image with imageScale manually.
+procedure AddBounceEffectForGear(Gear: PGear; imageScale: Single);
 var boing: PVisualGear;
 begin
     if Gear^.Density < _0_01 then
@@ -1736,7 +1746,7 @@
             dx:= 0;
             dy:= 0;
             FrameTicks:= 200;
-            Scale:= hwFloat2Float(Gear^.Density * hwAbs(Gear^.dY) + hwAbs(Gear^.dX)) / 1.5;
+            Scale:= imageScale;
             State:= ord(sprBoing)
             end;
     if Gear^.Kind = gtDuck then