Small animation on bullet impact
authorPalewolf
Sun, 14 Nov 2010 12:57:01 +0100
changeset 4327 224efdd648e1
parent 4325 ca254d2a46ac
child 4329 5e5fbe5337e1
Small animation on bullet impact
hedgewars/GSHandlers.inc
hedgewars/VGSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uVisualGears.pas
share/hedgewars/Data/Graphics/BulletHit.png
share/hedgewars/Data/Graphics/BulletHit.sifz
--- a/hedgewars/GSHandlers.inc	Sun Nov 14 02:38:05 2010 -0500
+++ b/hedgewars/GSHandlers.inc	Sun Nov 14 12:57:01 2010 +0100
@@ -708,7 +708,7 @@
 var 
     i, x, y: LongWord;
     oX, oY: hwFloat;
-    trail: PVisualGear;
+    VGear: PVisualGear;
 begin
     AllInactive := false;
     inc(Gear^.Timer);
@@ -756,27 +756,38 @@
         if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and
            ((GameFlags and gfArtillery) = 0) then cArtillery := false;
         
+        // Bullet Hit
+        if (hwRound(Gear^.X) and LAND_WIDTH_MASK = 0) 
+            and (hwRound(Gear^.Y) and LAND_HEIGHT_MASK = 0) then
+        begin
+            VGear := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBulletHit);
+            if VGear <> nil then
+            begin
+                VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
+            end;
+        end;
+        
         // Bullet trail
-        trail := AddVisualGear(
+        VGear := AddVisualGear(
             hwround(CurrentHedgehog^.Gear^.X) + GetLaunchX(CurrentHedgehog^.CurAmmoType, hwSign(CurrentHedgehog^.Gear^.dX), CurrentHedgehog^.Gear^.Angle), 
             hwround(CurrentHedgehog^.Gear^.Y) + GetLaunchY(CurrentHedgehog^.CurAmmoType, CurrentHedgehog^.Gear^.Angle),
             vgtLineTrail
         );
-        if trail <> nil then
+        if VGear <> nil then
         begin
             // http://mantis.freepascal.org/view.php?id=17714 hits again
-            trail^.dX := Gear^.X.QWordValue / SignAs(_1,_1).QWordValue;
-            trail^.dY := Gear^.Y.QWordValue / SignAs(_1,_1).QWordValue;
+            VGear^.dX := Gear^.X.QWordValue / SignAs(_1,_1).QWordValue;
+            VGear^.dY := Gear^.Y.QWordValue / SignAs(_1,_1).QWordValue;
             
             // reached edge of land. assume infinite beam. Extend it way out past camera
             if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) 
                 or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
             begin
-                trail^.dX := trail^.dX + (CurrentHedgehog^.Gear^.dX * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue;
-                trail^.dY := trail^.dY + (CurrentHedgehog^.Gear^.dY * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue;
+                VGear^.dX := VGear^.dX + (CurrentHedgehog^.Gear^.dX * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue;
+                VGear^.dY := VGear^.dY + (CurrentHedgehog^.Gear^.dY * LAND_WIDTH).QWordValue / SignAs(_1,_1).QWordValue;
             end;
             
-            trail^.Timer := 200;
+            VGear^.Timer := 200;
         end;
         
         Gear^.doStep := @doStepShotIdle
--- a/hedgewars/VGSHandlers.inc	Sun Nov 14 02:38:05 2010 -0500
+++ b/hedgewars/VGSHandlers.inc	Sun Nov 14 12:57:01 2010 +0100
@@ -618,3 +618,12 @@
     DeleteVisualGear(Gear);
     end
 end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword);
+begin
+  if Gear^.FrameTicks <= Steps then
+      DeleteVisualGear(Gear)
+  else
+      dec(Gear^.FrameTicks, Steps);
+end;
--- a/hedgewars/uConsts.pas	Sun Nov 14 02:38:05 2010 -0500
+++ b/hedgewars/uConsts.pas	Sun Nov 14 12:57:01 2010 +0100
@@ -75,7 +75,8 @@
             sprFeather, sprPiano, sprHandSineGun, sprPortalGun, sprPortal,
             sprCheese, sprHandCheese, sprHandFlamethrower, sprChunk, sprNote,
             sprSMineOff, sprSMineOn, sprHandSMine, sprHammer,
-            sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb
+            sprHandResurrector, sprCross, sprAirDrill, sprNapalmBomb,
+            sprBulletHit
             );
 
     // Gears that interact with other Gears and/or Land
@@ -98,7 +99,8 @@
             vgtSteam, vgtAmmo, vgtSmoke, vgtSmokeWhite, vgtHealth, vgtShell,
             vgtDust, vgtSplash, vgtDroplet, vgtSmokeRing, vgtBeeTrace, vgtEgg,
             vgtFeather, vgtHealthTag, vgtSmokeTrace, vgtEvilTrace, vgtExplosion,
-            vgtBigExplosion, vgtChunk, vgtNote, vgtLineTrail);
+            vgtBigExplosion, vgtChunk, vgtNote, vgtLineTrail,
+            vgtBulletHit);
 
     TGearsType = set of TGearType;
 
@@ -836,6 +838,11 @@
             (FileName:  'NapalmBomb'; Path: ptGraphics; AltPath: ptNone;
                 Texture: nil; Surface: nil; Width:  16; Height: 16;
                 imageWidth: 0; imageHeight: 0; saveSurf: false; priority:
+                tpMedium; getDimensions: false; getImageDimensions: true),
+            // sprNapalmBomb
+            (FileName:  'BulletHit'; Path: ptGraphics; AltPath: ptNone;
+                Texture: nil; Surface: nil; Width:  32; Height: 32;
+                imageWidth: 0; imageHeight: 0; saveSurf: false; priority:
                 tpMedium; getDimensions: false; getImageDimensions: true)
             // sprNapalmBomb
             );
--- a/hedgewars/uGears.pas	Sun Nov 14 02:38:05 2010 -0500
+++ b/hedgewars/uGears.pas	Sun Nov 14 12:57:01 2010 +0100
@@ -1424,6 +1424,7 @@
 var t: PGearArray;
     Gear: PGear;
     i, tmpDmg: LongInt;
+    VGear: PVisualGear;
 begin
 t:= CheckGearsCollision(Ammo);
 // Just to avoid hogs on rope dodging fire.
@@ -1445,6 +1446,13 @@
     tmpDmg:= ModifyDamage(Damage, Gear);
     if (Gear^.State and gstNoDamage) = 0 then
         begin
+        
+        VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
+        if VGear <> nil then
+        begin
+            VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
+        end;
+        
         if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then Gear^.FlightTime:= 1;
 
         case Gear^.Kind of
--- a/hedgewars/uVisualGears.pas	Sun Nov 14 02:38:05 2010 -0500
+++ b/hedgewars/uVisualGears.pas	Sun Nov 14 12:57:01 2010 +0100
@@ -118,7 +118,8 @@
             @doStepBigExplosion,
             @doStepChunk,
             @doStepNote,
-            @doStepLineTrail
+            @doStepLineTrail,
+            @doStepBulletHit
         );
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
@@ -317,6 +318,13 @@
                 Frame:= random(4);
                 FrameTicks:= random(2000) + 1500;
                 end;
+  vgtBulletHit: begin
+                dx:= 0;
+                dy:= 0;
+                FrameTicks:= 350;
+                Frame:= 7;
+                Angle := 0;
+                end;
         end;
 
 if State <> 0 then gear^.State:= State;
@@ -479,6 +487,7 @@
                             end;
                 vgtChunk: DrawRotatedF(sprChunk, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
                  vgtNote: DrawRotatedF(sprNote, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
+                vgtBulletHit: DrawRotatedF(sprBulletHit, round(Gear^.X) + WorldDx - 0, round(Gear^.Y) + WorldDy - 0, 7 - (Gear^.FrameTicks div 50), 1, Gear^.Angle);
             end;
         case Gear^.Kind of
             vgtSmallDamageTag: DrawCentered(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Tex);
Binary file share/hedgewars/Data/Graphics/BulletHit.png has changed
Binary file share/hedgewars/Data/Graphics/BulletHit.sifz has changed