DEADSOFTWARE

Player: Add punch animation for berserk
authorStas'M <x86corez@gmail.com>
Sun, 21 Jan 2018 13:11:56 +0000 (16:11 +0300)
committerStas'M <x86corez@gmail.com>
Sun, 21 Jan 2018 13:19:30 +0000 (16:19 +0300)
http://doom2d.org/forum/viewtopic.php?f=12&t=2562

src/game/g_game.pas
src/game/g_player.pas

index 6cbd3e4eddfab3d676657a20e6e71619ce551f12..29348b28c45600e074df7fe18b3dced0bbaa2b61 100644 (file)
@@ -2164,6 +2164,7 @@ begin
   end;
 
   g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
+  g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':TEXTURES\PUNCH', 64, 64, 4, False);
   g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
   g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
   g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
@@ -2240,6 +2241,7 @@ begin
   g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
   g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
   g_Frames_DeleteByName('FRAMES_TELEPORT');
+  g_Frames_DeleteByName('FRAMES_PUNCH');
   g_Sound_Delete('SOUND_GAME_TELEPORT');
   g_Sound_Delete('SOUND_GAME_NOTELEPORT');
   g_Sound_Delete('SOUND_GAME_DOOROPEN');
index ffb5ce93e6aa5eb070dce8dfe2b5aa5c1735d484..a088f2851d2b03c2c3e702f2b83feeb0d6e99cd1 100644 (file)
@@ -176,6 +176,7 @@ type
     FSavedState: TPlayerSavedState;
 
     FModel:     TPlayerModel;
+    FPunchAnim: TAnimation;
     FActionPrior:    Byte;
     FActionAnim:     Byte;
     FActionForce:    Boolean;
@@ -213,6 +214,7 @@ type
     procedure SetAction(Action: Byte; Force: Boolean = False);
     procedure OnDamage(Angle: SmallInt); virtual;
     function firediry(): Integer;
+    procedure DoPunch();
 
     procedure Run(Direction: TDirection);
     procedure NextWeapon();
@@ -2246,6 +2248,8 @@ begin
   FJetSoundOn.Free();
   FJetSoundOff.Free();
   FModel.Free();
+  if FPunchAnim <> nil then
+    FPunchAnim.Free();
 
   inherited;
 end;
@@ -2336,9 +2340,19 @@ var
   ID: DWORD;
   w, h: Word;
   dr: Boolean;
+  Mirror: TMirrorType;
 begin
   if FAlive then
   begin
+    if Direction = TDirection.D_RIGHT then
+      Mirror := TMirrorType.None
+    else
+      Mirror := TMirrorType.Horizontal;
+
+    if FPunchAnim <> nil then
+      FPunchAnim.Draw(FObj.X+IfThen(Direction = TDirection.D_LEFT, 15-FObj.Rect.X, FObj.Rect.X-15),
+                      FObj.Y+FObj.Rect.Y-11, Mirror);
+
     if (FMegaRulez[MR_INVUL] > gTime) and (gPlayerDrawn <> Self) then
       if g_Texture_Get('TEXTURE_PLAYER_INVULPENTA', ID) then
       begin
@@ -2773,6 +2787,17 @@ begin
   e_DrawFillQuad(0, 0, gPlayerScreenSize.X-1, gPlayerScreenSize.Y-1, 150, 200, 150, 255-h*50);
 end;
 
+procedure TPlayer.DoPunch();
+var
+  id: DWORD;
+begin
+  if FPunchAnim = nil then begin
+    g_Frames_Get(id, 'FRAMES_PUNCH');
+    FPunchAnim := TAnimation.Create(id, False, 1);
+  end else
+    FPunchAnim.reset();
+end;
+
 procedure TPlayer.Fire();
 var
   f, DidFire: Boolean;
@@ -2816,6 +2841,8 @@ begin
         locobj.Accel.X := xd-wx;
         locobj.Accel.y := yd-wy;
 
+        DoPunch();
+
         if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
           g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
         else
@@ -4743,6 +4770,9 @@ begin
       FLoss := 0;
     end;
 
+  if FAlive and (FPunchAnim <> nil) then
+    FPunchAnim.Update();
+
   if FAlive and (gFly or FJetpack) then
     FlySmoke();
 
@@ -5268,6 +5298,8 @@ begin
         locobj.Accel.X := xd-wx;
         locobj.Accel.y := yd-wy;
 
+        DoPunch();
+
         if g_Weapon_Hit(@locobj, 50, FUID, HIT_SOME) <> 0 then
           g_Sound_PlayExAt('SOUND_WEAPON_HITBERSERK', FObj.X, FObj.Y)
         else