hedgewars/uVisualGearsHandlers.pas
changeset 15586 19c85b010144
parent 15585 f8c1492601fe
child 15772 95db10dcad71
equal deleted inserted replaced
15585:f8c1492601fe 15586:19c85b010144
    77 implementation
    77 implementation
    78 uses uCollisions, uVariables, Math, uConsts, uVisualGearsList, uFloat, uSound, uRenderUtils, uWorld, uUtils;
    78 uses uCollisions, uVariables, Math, uConsts, uVisualGearsList, uFloat, uSound, uRenderUtils, uWorld, uUtils;
    79 
    79 
    80 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
    80 procedure doStepFlake(Gear: PVisualGear; Steps: Longword);
    81 var sign: real;
    81 var sign: real;
    82     moved, rising, outside: boolean;
    82     moved, rising, outside, fallingFadeIn: boolean;
    83     vfc, vft, diff: LongWord;
    83     vfc, vft, diff: LongWord;
    84     spawnMargin: LongInt;
    84     spawnMargin: LongInt;
    85 const
    85 const
    86     randMargin = 50;
    86     randMargin = 50;
       
    87     maxFallSpeedForFadeIn = 750;
    87 begin
    88 begin
    88 if SuddenDeathDmg then
    89 if SuddenDeathDmg then
    89     begin
    90     begin
    90     if (vobSDCount = 0) then exit;
    91     if (vobSDCount = 0) then exit;
    91     end
    92     end
   101     if SuddenDeathDmg then
   102     if SuddenDeathDmg then
   102         begin
   103         begin
   103         Y:= Y + (dY + tdY + cGravityf * vobSDFallSpeed) * Steps * Gear^.Scale;
   104         Y:= Y + (dY + tdY + cGravityf * vobSDFallSpeed) * Steps * Gear^.Scale;
   104         vfc:= vobSDFramesCount;
   105         vfc:= vobSDFramesCount;
   105         vft:= vobSDFrameTicks;
   106         vft:= vobSDFrameTicks;
       
   107         fallingFadeIn := vobSDFallSpeed <= maxFallSpeedForFadeIn;
   106         end
   108         end
   107     else
   109     else
   108         begin
   110         begin
   109         Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps * Gear^.Scale;
   111         Y:= Y + (dY + tdY + cGravityf * vobFallSpeed) * Steps * Gear^.Scale;
   110         vfc:= vobFramesCount;
   112         vfc:= vobFramesCount;
   111         vft:= vobFrameTicks;
   113         vft:= vobFrameTicks;
       
   114         fallingFadeIn := vobFallSpeed <= maxFallSpeedForFadeIn;
   112         end;
   115         end;
   113 
   116 
   114     if vft > 0 then
   117     if vft > 0 then
   115         begin
   118         begin
   116         inc(FrameTicks, Steps);
   119         inc(FrameTicks, Steps);
   184 
   187 
   185         // if flake left acceptable vertical area, respawn it opposite side
   188         // if flake left acceptable vertical area, respawn it opposite side
   186         if outside then
   189         if outside then
   187             begin
   190             begin
   188             if rising then
   191             if rising then
       
   192                 // rising flake
   189                 begin
   193                 begin
   190                 if State = 0 then
   194                 if State = 0 then
   191                     begin
   195                     begin
   192                     // fade out rising flake
   196                     // fade out rising flake
   193                     diff:= (LAND_HEIGHT - (cCloudOffset - 110)) - round(Y);
   197                     diff:= (LAND_HEIGHT - (cCloudOffset - 110)) - round(Y);
   194                     diff:= Min(diff*2, $FF);
   198                     diff:= Min(diff*2, $FF);
   195                     if diff >= $FF then
   199                     if diff >= $FF then
   196                         begin
   200                         begin
       
   201                         // end of fade-out
   197                         diff:= $FF;
   202                         diff:= $FF;
   198                         State:= 1;
   203                         State:= 1;
   199                         end;
   204                         end;
   200                     Tint:= (Tint and $FFFFFF00) or ($FF - diff);
   205                     Tint:= (Tint and $FFFFFF00) or ($FF - diff);
   201                     end
   206                     end
   202                 else
   207                 else
   203                     begin
   208                     begin
       
   209                     // reset and move back to bottom
   204                     Y:= LAND_HEIGHT + spawnMargin + random(50);
   210                     Y:= LAND_HEIGHT + spawnMargin + random(50);
   205                     moved:= true;
   211                     moved:= true;
   206                     State:= 0;
   212                     State:= 0;
   207                     Tint:= Tint or $FF;
   213                     Tint:= Tint or $FF;
   208                     end;
   214                     end;
   209                 end
   215                 end
   210             else
   216             else
       
   217                 // falling flake
   211                 begin
   218                 begin
       
   219                 // move back to top
   212                 Y:= Y - (1024 + spawnMargin + random(50));
   220                 Y:= Y - (1024 + spawnMargin + random(50));
   213                 moved:= true;
   221                 moved:= true;
       
   222                 // activate fade-in if not falling too fast
       
   223                 if fallingFadeIn then
       
   224                     begin
       
   225                     State:= $FF;
       
   226                     Tint:= (Tint and $FFFFFF00) or ($FF - State);
       
   227                     end;
   214                 end;
   228                 end;
   215             if moved then
   229             if moved then
   216                 X:= cLeftScreenBorder + random(cScreenSpace);
   230                 X:= cLeftScreenBorder + random(cScreenSpace);
       
   231             end
       
   232         else if (not rising) and (State > 0) then
       
   233             begin
       
   234             // quickly fade in falling flake after appearing at top
       
   235             if State > 16 then
       
   236                 Dec(State, 16)
       
   237             else
       
   238                 State:= 0;
       
   239             Tint:= (Tint and $FFFFFF00) or ($FF - State);
   217             end;
   240             end;
   218 
   241 
   219         if moved then
   242         if moved then
   220             begin
   243             begin
   221             Angle:= random(360);
   244             Angle:= random(360);