hedgewars/uVisualGears.pas
changeset 4379 6cd6b77df8b8
parent 4378 91655618a510
child 4380 b78638b36b89
equal deleted inserted replaced
4378:91655618a510 4379:6cd6b77df8b8
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uVisualGears;
    21 unit uVisualGears;
    22 interface
    22 interface
    23 uses uConsts, uFloat, Math, GLunit, uTypes;
    23 uses uConsts, uFloat, GLunit, uTypes;
    24 
    24 
    25 procedure initModule;
    25 procedure initModule;
    26 procedure freeModule;
    26 procedure freeModule;
    27 
    27 
    28 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
    28 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
    32 procedure DeleteVisualGear(Gear: PVisualGear);
    32 procedure DeleteVisualGear(Gear: PVisualGear);
    33 procedure AddClouds;
    33 procedure AddClouds;
    34 procedure AddDamageTag(X, Y, Damage, Color: LongWord);
    34 procedure AddDamageTag(X, Y, Damage, Color: LongWord);
    35 
    35 
    36 implementation
    36 implementation
    37 uses uMisc, uStore, uSound, uMobile, uVariables, uTextures, uRender;
    37 uses uMisc, uStore, uSound, uMobile, uVariables, uTextures, uRender, uUtils, Math;
    38 
    38 
    39 const cExplFrameTicks = 110;
    39 const cExplFrameTicks = 110;
    40 
    40 
    41 {$INCLUDE "VGSHandlers.inc"}
    41 {$INCLUDE "VGSHandlers.inc"}
    42 
    42 
    96         );
    96         );
    97 
    97 
    98 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
    98 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType; State: LongWord = 0): PVisualGear;
    99 var gear: PVisualGear;
    99 var gear: PVisualGear;
   100     t: Longword;
   100     t: Longword;
   101     sp: float;
   101     sp: real;
   102 begin
   102 begin
   103 if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then // we are scrolling now
   103 if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then // we are scrolling now
   104     if Kind <> vgtCloud then
   104     if Kind <> vgtCloud then
   105         begin
   105         begin
   106         AddVisualGear:= nil;
   106         AddVisualGear:= nil;
   122       exit
   122       exit
   123     end;
   123     end;
   124 
   124 
   125 New(gear);
   125 New(gear);
   126 FillChar(gear^, sizeof(TVisualGear), 0);
   126 FillChar(gear^, sizeof(TVisualGear), 0);
   127 gear^.X:= float(X);
   127 gear^.X:= real(X);
   128 gear^.Y:= float(Y);
   128 gear^.Y:= real(Y);
   129 gear^.Kind := Kind;
   129 gear^.Kind := Kind;
   130 gear^.doStep:= doStepHandlers[Kind];
   130 gear^.doStep:= doStepHandlers[Kind];
   131 gear^.State:= 0;
   131 gear^.State:= 0;
   132 gear^.Tint:= $FFFFFFFF;
   132 gear^.Tint:= $FFFFFFFF;
   133 
   133 
   349       begin
   349       begin
   350       Gear:= t;
   350       Gear:= t;
   351       if Gear^.Kind = vgtFlake then
   351       if Gear^.Kind = vgtFlake then
   352           begin
   352           begin
   353           // Damage calc from doMakeExplosion
   353           // Damage calc from doMakeExplosion
   354           dmg:= min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5);
   354           dmg:= Min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5);
   355           if dmg > 1 then
   355           if dmg > 1 then
   356               begin
   356               begin
   357               Gear^.tdX:= 0.02 * dmg + 0.01;
   357               Gear^.tdX:= 0.02 * dmg + 0.01;
   358               if Gear^.X - X < 0 then Gear^.tdX := -Gear^.tdX;
   358               if Gear^.X - X < 0 then Gear^.tdX := -Gear^.tdX;
   359               Gear^.tdY:= 0.02 * dmg + 0.01;
   359               Gear^.tdY:= 0.02 * dmg + 0.01;
   407         begin
   407         begin
   408         Tint(Gear^.Tint);
   408         Tint(Gear^.Tint);
   409         case Gear^.Kind of
   409         case Gear^.Kind of
   410             vgtExplosion: DrawSprite(sprExplosion50, round(Gear^.X) - 32 + WorldDx, round(Gear^.Y) - 32 + WorldDy, Gear^.State);
   410             vgtExplosion: DrawSprite(sprExplosion50, round(Gear^.X) - 32 + WorldDx, round(Gear^.Y) - 32 + WorldDy, Gear^.State);
   411             vgtBigExplosion: begin
   411             vgtBigExplosion: begin
   412                              Tint($FF, $FF, $FF, floor($FF * (1 - power(Gear^.Timer / 250, 4))));
   412                              Tint($FF, $FF, $FF, round($FF * (1 - power(Gear^.Timer / 250, 4))));
   413                              DrawRotatedTextureF(SpritesData[sprBigExplosion].Texture, 0.85 * (-power(2, -10 * Int(Gear^.Timer)/250) + 1) + 0.4, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 385, 385, Gear^.Angle);
   413                              DrawRotatedTextureF(SpritesData[sprBigExplosion].Texture, 0.85 * (-power(2, -10 * Int(Gear^.Timer)/250) + 1) + 0.4, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 385, 385, Gear^.Angle);
   414                              end;
   414                              end;
   415             end;
   415             end;
   416         if (cReducedQuality and rqFancyBoom) = 0 then
   416         if (cReducedQuality and rqFancyBoom) = 0 then
   417             case Gear^.Kind of
   417             case Gear^.Kind of
   422                          else
   422                          else
   423                              DrawTextureF(SpritesData[sprFlame].Texture, Gear^.FrameTicks / 900, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, (RealTicks shr 7 + Gear^.Frame) mod 8, 1, 16, 16);
   423                              DrawTextureF(SpritesData[sprFlame].Texture, Gear^.FrameTicks / 900, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, (RealTicks shr 7 + Gear^.Frame) mod 8, 1, 16, 16);
   424                 vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8);
   424                 vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8);
   425                 vgtSteam: DrawSprite(sprSmokeWhite, round(Gear^.X) + WorldDx - 11, round(Gear^.Y) + WorldDy - 11, 7 - Gear^.Frame);
   425                 vgtSteam: DrawSprite(sprSmokeWhite, round(Gear^.X) + WorldDx - 11, round(Gear^.Y) + WorldDy - 11, 7 - Gear^.Frame);
   426                 vgtAmmo: begin
   426                 vgtAmmo: begin
   427                         Tint($FF, $FF, $FF, floor(Gear^.alpha * $FF));
   427                         Tint($FF, $FF, $FF, round(Gear^.alpha * $FF));
   428                         DrawTextureF(ropeIconTex, Gear^.scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 32, 32);
   428                         DrawTextureF(ropeIconTex, Gear^.scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 32, 32);
   429                         DrawTextureF(SpritesData[sprAMAmmos].Texture, Gear^.scale * 0.90, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame - 1, 1, 32, 32);
   429                         DrawTextureF(SpritesData[sprAMAmmos].Texture, Gear^.scale * 0.90, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame - 1, 1, 32, 32);
   430                         end;
   430                         end;
   431                 vgtHealth:  begin
   431                 vgtHealth:  begin
   432                             case Gear^.Frame div 10 of
   432                             case Gear^.Frame div 10 of
   433                                 0:Tint(0, $FF, 0, floor(Gear^.FrameTicks * $FF / 1000));
   433                                 0:Tint(0, $FF, 0, round(Gear^.FrameTicks * $FF / 1000));
   434                                 1:Tint($FF, 0, 0, floor(Gear^.FrameTicks * $FF / 1000));
   434                                 1:Tint($FF, 0, 0, round(Gear^.FrameTicks * $FF / 1000));
   435                             end;
   435                             end;
   436                             DrawSprite(sprHealth, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, 0);
   436                             DrawSprite(sprHealth, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, 0);
   437                             end;
   437                             end;
   438                 vgtShell: begin
   438                 vgtShell: begin
   439                             if Gear^.FrameTicks < $FF then
   439                             if Gear^.FrameTicks < $FF then
   453                             else
   453                             else
   454                                 Tint($FF, $FF, $FF, $80);
   454                                 Tint($FF, $FF, $FF, $80);
   455                             DrawRotatedF(sprBeeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, (RealTicks shr 4) mod cMaxAngle);
   455                             DrawRotatedF(sprBeeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, (RealTicks shr 4) mod cMaxAngle);
   456                             end;
   456                             end;
   457                 vgtSmokeRing: begin
   457                 vgtSmokeRing: begin
   458                             Tint($FF, $FF, $FF, floor(Gear^.alpha * $FF));
   458                             Tint($FF, $FF, $FF, round(Gear^.alpha * $FF));
   459                             DrawRotatedTextureF(SpritesData[sprSmokeRing].Texture, Gear^.scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 200, 200, Gear^.Angle);
   459                             DrawRotatedTextureF(SpritesData[sprSmokeRing].Texture, Gear^.scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, 0, 1, 200, 200, Gear^.Angle);
   460                             end;
   460                             end;
   461                 vgtChunk: DrawRotatedF(sprChunk, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
   461                 vgtChunk: DrawRotatedF(sprChunk, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
   462                  vgtNote: DrawRotatedF(sprNote, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
   462                  vgtNote: DrawRotatedF(sprNote, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
   463                 vgtBulletHit: DrawRotatedF(sprBulletHit, round(Gear^.X) + WorldDx - 0, round(Gear^.Y) + WorldDy - 0, 7 - (Gear^.FrameTicks div 50), 1, Gear^.Angle);
   463                 vgtBulletHit: DrawRotatedF(sprBulletHit, round(Gear^.X) + WorldDx - 0, round(Gear^.Y) + WorldDy - 0, 7 - (Gear^.FrameTicks div 50), 1, Gear^.Angle);