hedgewars/uVisualGearsHandlers.pas
changeset 14548 78363dbfd5dc
parent 13240 9f5023a5f9e1
child 14577 34e810295d08
equal deleted inserted replaced
14547:e68b91abbcf5 14548:78363dbfd5dc
   898 ////////////////////////////////////////////////////////////////////////////////
   898 ////////////////////////////////////////////////////////////////////////////////
   899 var
   899 var
   900     currwindbar: PVisualGear = nil;
   900     currwindbar: PVisualGear = nil;
   901 
   901 
   902 procedure doStepSmoothWindBarWork(Gear: PVisualGear; Steps: Longword);
   902 procedure doStepSmoothWindBarWork(Gear: PVisualGear; Steps: Longword);
       
   903 const maxWindBarWidth = 73;
   903 begin
   904 begin
   904     if currwindbar = Gear then
   905     if currwindbar = Gear then
   905     begin
   906     begin
   906     inc(Gear^.Timer, Steps);
   907     inc(Gear^.Timer, Steps);
   907 
   908 
   910         dec(Gear^.Timer, 10);
   911         dec(Gear^.Timer, 10);
   911         if WindBarWidth < Gear^.Tag then
   912         if WindBarWidth < Gear^.Tag then
   912             inc(WindBarWidth)
   913             inc(WindBarWidth)
   913         else if WindBarWidth > Gear^.Tag then
   914         else if WindBarWidth > Gear^.Tag then
   914             dec(WindBarWidth);
   915             dec(WindBarWidth);
       
   916         // Prevent wind bar from overflowing
       
   917         if WindBarWidth > maxWindBarWidth then
       
   918             WindBarWidth:= maxWindBarWidth;
       
   919         if WindBarWidth < - maxWindBarWidth then
       
   920             WindBarWidth:= - maxWindBarWidth;
   915         end;
   921         end;
   916     if cWindspeedf > Gear^.dAngle then
   922     if cWindspeedf > Gear^.dAngle then
   917         begin
   923         begin
   918         cWindspeedf := cWindspeedf - Gear^.Angle*Steps;
   924         cWindspeedf := cWindspeedf - Gear^.Angle*Steps;
   919         if cWindspeedf < Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
   925         if cWindspeedf < Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
   923         cWindspeedf := cWindspeedf + Gear^.Angle*Steps;
   929         cWindspeedf := cWindspeedf + Gear^.Angle*Steps;
   924         if cWindspeedf > Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
   930         if cWindspeedf > Gear^.dAngle then cWindspeedf:= Gear^.dAngle;
   925         end;
   931         end;
   926     end;
   932     end;
   927 
   933 
   928     if ((WindBarWidth = Gear^.Tag) and (cWindspeedf = Gear^.dAngle)) or (currwindbar <> Gear) then
   934     if (((WindBarWidth = Gear^.Tag) or (Abs(WindBarWidth) >= maxWindBarWidth)) and (cWindspeedf = Gear^.dAngle)) or (currwindbar <> Gear) then
   929     begin
   935     begin
   930         if currwindbar = Gear then currwindbar:= nil;
   936         if currwindbar = Gear then currwindbar:= nil;
   931         DeleteVisualGear(Gear)
   937         DeleteVisualGear(Gear)
   932     end
   938     end
   933 end;
   939 end;