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