hedgewars/uGearsHandlersMess.pas
changeset 9721 1833dadcebf0
parent 9706 5178d2263521
child 9723 31d10d684e90
equal deleted inserted replaced
9720:453a1c29b7e4 9721:1833dadcebf0
   280 var
   280 var
   281     isFalling: boolean;
   281     isFalling: boolean;
   282     //tmp: QWord;
   282     //tmp: QWord;
   283     tX, tdX, tdY: hwFloat;
   283     tX, tdX, tdY: hwFloat;
   284     collV, collH: LongInt;
   284     collV, collH: LongInt;
   285     land: word;
   285     land, xland: word;
   286 begin
   286 begin
   287     tX:= Gear^.X;
   287     tX:= Gear^.X;
   288     if (Gear^.Kind <> gtGenericFaller) and WorldWrap(Gear) and (WorldEdge = weWrap) and (Gear^.AdvBounce <> 0) and
   288     if (Gear^.Kind <> gtGenericFaller) and WorldWrap(Gear) and (WorldEdge = weWrap) and (Gear^.AdvBounce <> 0) and
   289       ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
   289       ((TestCollisionXwithGear(Gear, 1) <> 0) or (TestCollisionXwithGear(Gear, -1) <> 0))  then
   290         begin
   290         begin
   321         land:= TestCollisionYwithGear(Gear, -1);
   321         land:= TestCollisionYwithGear(Gear, -1);
   322         if land <> 0 then
   322         if land <> 0 then
   323             begin
   323             begin
   324             collV := -1;
   324             collV := -1;
   325             if land and lfIce <> 0 then
   325             if land and lfIce <> 0 then
   326                 Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
   326                  Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
   327             else
   327             else Gear^.dX := Gear^.dX * Gear^.Friction;
   328                 Gear^.dX := Gear^.dX * Gear^.Friction;
   328             if land and lfBouncy = 0 then
   329 
   329                  begin
   330             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   330                  Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   331             Gear^.State := Gear^.State or gstCollision
   331                  Gear^.State := Gear^.State or gstCollision
   332             end
   332                  end
   333         else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then
   333             else Gear^.dY := - Gear^.dY * cElastic
   334             collV := 1;
   334             end
       
   335         else if Gear^.AdvBounce = 1 then
       
   336             begin
       
   337             land:= TestCollisionYwithGear(Gear, 1);
       
   338             if land <> 0 then collV := 1
       
   339             end
   335         end
   340         end
   336     else
   341     else
   337         begin // Gear^.dY.isNegative is false
   342         begin // Gear^.dY.isNegative is false
   338         land:= TestCollisionYwithGear(Gear, 1);
   343         land:= TestCollisionYwithGear(Gear, 1);
   339         if land <> 0 then
   344         if land <> 0 then
   343             if land and lfIce <> 0 then
   348             if land and lfIce <> 0 then
   344                 Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
   349                 Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
   345             else
   350             else
   346                 Gear^.dX := Gear^.dX * Gear^.Friction;
   351                 Gear^.dX := Gear^.dX * Gear^.Friction;
   347 
   352 
   348             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
   353             if land and lfBouncy = 0 then
       
   354                  begin
       
   355                  Gear^.dY := - Gear^.dY * Gear^.Elasticity;
       
   356                  Gear^.State := Gear^.State or gstCollision
       
   357                  end
       
   358             else Gear^.dY := - Gear^.dY * cElastic
       
   359             end
       
   360         else
       
   361             begin
       
   362             isFalling := true;
       
   363             if Gear^.AdvBounce = 1 then
       
   364                 begin
       
   365                 land:= TestCollisionYwithGear(Gear, -1);
       
   366                 if land <> 0 then collV := -1
       
   367                 end
       
   368             end
       
   369         end;
       
   370 
       
   371 
       
   372     xland:= TestCollisionXwithGear(Gear, hwSign(Gear^.dX));
       
   373     if xland <> 0 then
       
   374         begin
       
   375         collH := hwSign(Gear^.dX);
       
   376         if xland and lfBouncy = 0 then
       
   377             begin
       
   378             Gear^.dX := - Gear^.dX * Gear^.Elasticity;
       
   379             Gear^.dY :=   Gear^.dY * Gear^.Elasticity;
   349             Gear^.State := Gear^.State or gstCollision
   380             Gear^.State := Gear^.State or gstCollision
   350             end
   381             end
   351         else
   382         else
   352             begin
   383             begin
   353             isFalling := true;
   384             Gear^.dX := - Gear^.dX * cElastic;
   354             if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, -1) <> 0) then
   385             Gear^.dY :=   Gear^.dY * cElastic
   355                 collV := -1
   386             end
   356             end
   387         end
   357         end;
   388     else if Gear^.AdvBounce = 1 then
   358 
   389         begin
   359 
   390         xland:= TestCollisionXwithGear(Gear, -hwSign(Gear^.dX));
   360     if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0 then
   391         if xland <> 0 then collH := -hwSign(Gear^.dX)
   361         begin
   392         end;
   362         collH := hwSign(Gear^.dX);
       
   363         Gear^.dX := - Gear^.dX * Gear^.Elasticity;
       
   364         Gear^.dY :=   Gear^.dY * Gear^.Elasticity;
       
   365         Gear^.State := Gear^.State or gstCollision
       
   366         end
       
   367     else if (Gear^.AdvBounce =1) and (TestCollisionXwithGear(Gear, -hwSign(Gear^.dX)) <> 0) then
       
   368         collH := -hwSign(Gear^.dX);
       
   369     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
   393     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
   370     if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1)
   394     if (collV <> 0) and (collH <> 0) and 
   371     or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)) then
   395        (((Gear^.AdvBounce=1) and ((collV=-1) or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue))) or
   372         begin
   396         ((xland or land) and lfBouncy <> 0)) then
   373         Gear^.dX := tdY*Gear^.Elasticity*Gear^.Friction;
   397         begin
   374         Gear^.dY := tdX*Gear^.Elasticity;
   398         if (xland or land) and lfBouncy = 0 then
   375         //*Gear^.Friction;
   399             begin
       
   400             Gear^.dX := tdY*Gear^.Elasticity*Gear^.Friction;
       
   401             Gear^.dY := tdX*Gear^.Elasticity
       
   402             end
       
   403         else
       
   404             begin
       
   405             Gear^.dX := tdY*cElastic*Gear^.Friction;
       
   406             Gear^.dY := tdX*cElastic
       
   407             end;
       
   408 
   376         Gear^.dY.isNegative := not tdY.isNegative;
   409         Gear^.dY.isNegative := not tdY.isNegative;
   377         isFalling := false;
   410         isFalling := false;
   378         Gear^.AdvBounce := 10;
   411         Gear^.AdvBounce := 10;
   379         end;
   412         end;
   380 
   413 
   395     if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then
   428     if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then
   396         Gear^.State := Gear^.State and (not gstMoving)
   429         Gear^.State := Gear^.State and (not gstMoving)
   397     else
   430     else
   398         Gear^.State := Gear^.State or gstMoving;
   431         Gear^.State := Gear^.State or gstMoving;
   399 
   432 
   400     if (Gear^.nImpactSounds > 0) and
   433     if ((xland or land) and lfBouncy <> 0) and (Gear^.dX.QWordValue < _0_1.QWordValue) and (Gear^.dY.QWordValue < _0_1.QWordValue) then
       
   434         Gear^.State := Gear^.State or gstCollision;
       
   435     
       
   436     if ((xland or land) and lfBouncy <> 0) and
       
   437         (((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) or
       
   438             ((Gear^.Radius >= 3) and
       
   439                 ((Gear^.dX.QWordValue > _0_1.QWordValue) or (Gear^.dY.QWordValue > _0_1.QWordValue)))) then
       
   440         PlaySound(sndMelonImpact, true)
       
   441     else if (Gear^.nImpactSounds > 0) and
   401         (Gear^.State and gstCollision <> 0) and
   442         (Gear^.State and gstCollision <> 0) and
   402         (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0)) or (Gear^.State and gstMoving <> 0)) and
   443         (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0)) or (Gear^.State and gstMoving <> 0)) and
   403         (((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) or
   444         (((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) or
   404             ((Gear^.Radius >= 3) and
   445             ((Gear^.Radius >= 3) and
   405                 ((Gear^.dX.QWordValue > _0_1.QWordValue) or (Gear^.dY.QWordValue > _0_1.QWordValue)))) then
   446                 ((Gear^.dX.QWordValue > _0_1.QWordValue) or (Gear^.dY.QWordValue > _0_1.QWordValue)))) then