hedgewars/GSHandlers.inc
changeset 344 a98ade8c99b6
parent 343 8a91d153f787
child 345 fa39c61be4de
equal deleted inserted replaced
343:8a91d153f787 344:a98ade8c99b6
   521    DeleteMe;
   521    DeleteMe;
   522    exit
   522    exit
   523    end;
   523    end;
   524 Gear.dX:= HHGear.X - Gear.X;
   524 Gear.dX:= HHGear.X - Gear.X;
   525 Gear.dY:= HHGear.Y - Gear.Y;
   525 Gear.dY:= HHGear.Y - Gear.Y;
   526 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 1: (' + floattostr(HHGear.X) + ',' + floattostr(HHGear.Y) + ')');
   526 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 1: (' + floattostr(HHGear.X) + ',' + floattostr(HHGear.Y) + ')');
   527 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 2: (' + floattostr(Gear.dX) + ',' + floattostr(Gear.dY) + ')');
   527 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 2: (' + floattostr(Gear.dX) + ',' + floattostr(Gear.dY) + ')');
   528 
   528 
   529 if (Gear.Message and gm_Left  <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else
   529 if (Gear.Message and gm_Left  <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else
   530 if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002;
   530 if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002;
   531 
   531 
   532 if not TestCollisionYwithGear(HHGear, 1) then
   532 if not TestCollisionYwithGear(HHGear, 1) then
   533    begin
   533    begin
   534    HHGear.dY:= HHGear.dY + cGravity;
   534    HHGear.dY:= HHGear.dY + cGravity;
   535    if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 4: free fall');
   535    if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 4: free fall');
   536    end;
   536    end;
   537 
   537 
   538 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 3: ' + floattostr(HHGear.dY));
   538 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 3: ' + floattostr(HHGear.dY));
   539 
   539 
   540 cs:= Gear.dY + HHGear.dY;
   540 cs:= Gear.dY + HHGear.dY;
   541 cc:= Gear.dX + HHGear.dX;
   541 cc:= Gear.dX + HHGear.dX;
   542 len:= 1 / sqrt(sqr(cc)+sqr(cs));
   542 len:= 1 / sqrt(sqr(cc)+sqr(cs));
   543 cc:= cc * len;
   543 cc:= cc * len;
   544 cs:= cs * len;
   544 cs:= cs * len;
   545 
   545 
   546 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 5: (' + floattostr(cc) + ',' + floattostr(cs) + ')');
   546 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 5: (' + floattostr(cc) + ',' + floattostr(cs) + ')');
   547 
   547 
   548 flCheck:= not flCheck;
   548 flCheck:= not flCheck;
   549 if flCheck then  // check whether rope needs dividing
   549 if flCheck then  // check whether rope needs dividing
   550    begin
   550    begin
   551    len:= Gear.Elasticity - 20;
   551    len:= Gear.Elasticity - 20;
   553          begin
   553          begin
   554          tx:= cc*len;
   554          tx:= cc*len;
   555          ty:= cs*len;
   555          ty:= cs*len;
   556          lx:= round(Gear.X + tx) + hwSign(HHGear.dX);
   556          lx:= round(Gear.X + tx) + hwSign(HHGear.dX);
   557          ly:= round(Gear.Y + ty) + hwSign(HHGear.dY);
   557          ly:= round(Gear.Y + ty) + hwSign(HHGear.dY);
   558          if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope b: (' + inttostr(lx) + ',' + inttostr(ly) + ')');
   558          if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope b: (' + inttostr(lx) + ',' + inttostr(ly) + ')');
   559          if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
   559          if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
   560            begin
   560            begin
   561            if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope b: !!');
   561            if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope b: !!');
   562            with RopePoints.ar[RopePoints.Count] do
   562            with RopePoints.ar[RopePoints.Count] do
   563                 begin
   563                 begin
   564                 X:= Gear.X;
   564                 X:= Gear.X;
   565                 Y:= Gear.Y;
   565                 Y:= Gear.Y;
   566                 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX);
   566                 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle32(Gear.dY, Gear.dX);
   567                 b:= (cc * HHGear.dY) > (cs * HHGear.dX);
   567                 b:= (cc * HHGear.dY) > (cs * HHGear.dX);
       
   568                 AddFileLog('Rope: b = ' + inttostr(ord(b)));
   568                 dLen:= len
   569                 dLen:= len
   569                 end;
   570                 end;
   570            Gear.X:= Gear.X + tx;
   571            Gear.X:= Gear.X + tx;
   571            Gear.Y:= Gear.Y + ty;
   572            Gear.Y:= Gear.Y + ty;
   572            inc(RopePoints.Count);
   573            inc(RopePoints.Count);
   579    end else
   580    end else
   580    if RopePoints.Count > 0 then // check whether the last dividing point could be removed
   581    if RopePoints.Count > 0 then // check whether the last dividing point could be removed
   581       begin
   582       begin
   582       tx:= RopePoints.ar[Pred(RopePoints.Count)].X;
   583       tx:= RopePoints.ar[Pred(RopePoints.Count)].X;
   583       ty:= RopePoints.ar[Pred(RopePoints.Count)].Y;
   584       ty:= RopePoints.ar[Pred(RopePoints.Count)].Y;
   584       if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope a: (' + floattostr(tx) + ',' + floattostr(ty) + ')');
   585       if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope a: (' + floattostr(tx) + ',' + floattostr(ty) + ')');
       
   586       if GameTicks = 189245 then AddFileLog('Rope A: ' + inttostr(ord((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y))));
   585       if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then
   587       if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear.X) * (ty - HHGear.Y) > (tx - HHGear.X) * (ty - Gear.Y)) then
   586          begin
   588          begin
   587          dec(RopePoints.Count);
   589          dec(RopePoints.Count);
   588          Gear.X:=RopePoints.ar[RopePoints.Count].X;
   590          Gear.X:=RopePoints.ar[RopePoints.Count].X;
   589          Gear.Y:=RopePoints.ar[RopePoints.Count].Y;
   591          Gear.Y:=RopePoints.ar[RopePoints.Count].Y;
   593       end;
   595       end;
   594 
   596 
   595 Gear.dX:= HHGear.X - Gear.X;
   597 Gear.dX:= HHGear.X - Gear.X;
   596 Gear.dY:= HHGear.Y - Gear.Y;
   598 Gear.dY:= HHGear.Y - Gear.Y;
   597 
   599 
   598 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 6: (' + floattostr(Gear.dX) + ',' + floattostr(Gear.dY) + ')');
   600 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 6: (' + floattostr(Gear.dX) + ',' + floattostr(Gear.dY) + ')');
   599 
   601 
   600 cs:= Gear.dY + HHGear.dY;
   602 cs:= Gear.dY + HHGear.dY;
   601 cc:= Gear.dX + HHGear.dX;
   603 cc:= Gear.dX + HHGear.dX;
   602 len:= 1 / sqrt(sqr(cc)+sqr(cs));
   604 len:= 1 / sqrt(sqr(cc)+sqr(cs));
   603 cc:= cc * len;
   605 cc:= cc * len;
   618 HHGear.Y:= Gear.Y + cs*Gear.Elasticity;
   620 HHGear.Y:= Gear.Y + cs*Gear.Elasticity;
   619 
   621 
   620 HHGear.dX:= HHGear.X - HHGear.dX;
   622 HHGear.dX:= HHGear.X - HHGear.dX;
   621 HHGear.dY:= HHGear.Y - HHGear.dY;
   623 HHGear.dY:= HHGear.Y - HHGear.dY;
   622 
   624 
   623 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 7: (' + floattostr(HHGear.dX) + ',' + floattostr(HHGear.dY) + ')');
   625 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 7: (' + floattostr(HHGear.dX) + ',' + floattostr(HHGear.dY) + ')');
   624 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 8: (' + floattostr(HHGear.X) + ',' + floattostr(HHGear.Y) + ')');
   626 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 8: (' + floattostr(HHGear.X) + ',' + floattostr(HHGear.Y) + ')');
   625 
   627 
   626 if TestCollisionXwithGear(HHGear, hwSign(HHGear.dX)) then
   628 if TestCollisionXwithGear(HHGear, hwSign(HHGear.dX)) then
   627    HHGear.dX:= -0.6 * HHGear.dX;
   629    HHGear.dX:= -0.6 * HHGear.dX;
   628 if TestCollisionYwithGear(HHGear, hwSign(HHGear.dY)) then
   630 if TestCollisionYwithGear(HHGear, hwSign(HHGear.dY)) then
   629    HHGear.dY:= -0.6 * HHGear.dY;
   631    HHGear.dY:= -0.6 * HHGear.dY;
   630 
   632 
   631 if (GameTicks > 189200)and(GameTicks < 189500) then AddFileLog('Rope 9: (' + floattostr(HHGear.dX) + ',' + floattostr(HHGear.dY) + ')');
   633 if (GameTicks > 189200)and(GameTicks < 189300) then AddFileLog('Rope 9: (' + floattostr(HHGear.dX) + ',' + floattostr(HHGear.dY) + ')');
   632 
   634 
   633 if (Gear.Message and gm_Attack) <> 0 then
   635 if (Gear.Message and gm_Attack) <> 0 then
   634    if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else
   636    if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else
   635 else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
   637 else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
   636 end;
   638 end;