hedgewars/uGearsUtils.pas
changeset 12446 48ee3777e42e
parent 12445 28bf941e13a0
child 12448 8b89fe2115ad
equal deleted inserted replaced
12445:28bf941e13a0 12446:48ee3777e42e
   699                 CheckGearDrowning := false;
   699                 CheckGearDrowning := false;
   700 
   700 
   701                 // check if surface was penetrated
   701                 // check if surface was penetrated
   702 
   702 
   703                 // no penetration if center's water distance not smaller than radius
   703                 // no penetration if center's water distance not smaller than radius
   704                 if  abs(dist2Water + Gear^.Radius) >= Gear^.Radius then
   704                 if  ((dist2Water + Gear^.Radius div 2) < 0) or (abs(dist2Water + Gear^.Radius) >= Gear^.Radius) then
   705                     isImpact:= false
   705                     isImpact:= false
   706                 else
   706                 else
   707                     begin
   707                     begin
   708                     // get distance to water of last tick
   708                     // get distance to water of last tick
   709                     if isDirH then
   709                     if isDirH then
   710                         begin
   710                         begin
   711                         tmp:= hwRound(Gear^.X - Gear^.dX);
   711                         tmp:= hwRound(Gear^.X - Gear^.dX);
   712                         tmp:= abs(min(tmp - leftX, rightX - tmp));
   712                         if abs(tmp - leftX) < abs(tmp - rightX) then  // left edge
       
   713                             isImpact:= (abs(tmp-leftX) >= Gear^.Radius) and (Gear^.dX.isNegative)
       
   714                         else
       
   715                             isImpact:= (abs(tmp-rightX) >= Gear^.Radius) and (not Gear^.dX.isNegative);
   713                         end
   716                         end
   714                     else
   717                     else
   715                         begin
   718                         begin
   716                         tmp:= hwRound(Gear^.Y - Gear^.dY);
   719                         tmp:= hwRound(Gear^.Y - Gear^.dY);
   717                         tmp:= abs(cWaterLine - tmp);
   720                         tmp:= abs(cWaterLine - tmp);
       
   721                         // there was an impact if distance was >= radius
       
   722                         isImpact:= (tmp >= Gear^.Radius) and (not Gear^.dY.isNegative);
   718                         end;
   723                         end;
   719 
   724 
   720                     // there was an impact if distance was >= radius
       
   721                     isImpact:= (tmp >= Gear^.Radius)
       
   722                     end;
   725                     end;
   723                 end; // end of submersible
   726                 end; // end of submersible
   724             end; // end of not skipping
   727             end; // end of not skipping
   725 
   728 
   726         // splash sound animation and droplets
   729         // splash sound animation and droplets