hedgewars/uGearsHandlersRope.pas
changeset 7605 10e88fbb5fdb
parent 7604 c143c942b5fe
child 7606 adb1198ade36
equal deleted inserted replaced
7604:c143c942b5fe 7605:10e88fbb5fdb
    71         Gear^.State := Gear^.State and (not gsttmpflag);
    71         Gear^.State := Gear^.State and (not gsttmpflag);
    72         Gear^.doStep := @doStepRope;
    72         Gear^.doStep := @doStepRope;
    73         end
    73         end
    74 end;
    74 end;
    75 
    75 
       
    76 procedure unstickHog(Gear, HHGear: PGear);
       
    77 var i: LongInt;
       
    78     stuck: Boolean;
       
    79 begin
       
    80     if (TestCollisionYwithGear(HHGear, 1) <> 0) and (TestCollisionYwithGear(HHGear, -1) = 0) then
       
    81         begin
       
    82         i:= 1;
       
    83         repeat
       
    84             begin
       
    85             inc(i);
       
    86             stuck:= TestCollisionYwithGear(HHGear, i) <> 0
       
    87             end
       
    88         until (i = 8) or not stuck;
       
    89         HHGear^.Y:= HHGear^.Y-int2hwFloat(pred(i));
       
    90         // experiment in simulating something the shoppa players apparently expect
       
    91         if Gear^.Message and gmDown <> 0 then
       
    92             HHGear^.dY.QWordValue:= 0
       
    93         end
       
    94     else if (TestCollisionYwithGear(HHGear, -1) <> 0) and (TestCollisionYwithGear(HHGear, 1) = 0) then
       
    95         begin
       
    96         i:= -1;
       
    97         repeat
       
    98             begin
       
    99             dec(i);
       
   100             stuck:= TestCollisionYwithGear(HHGear, i) <> 0
       
   101             end
       
   102         until (i = -8) or not stuck;
       
   103         HHGear^.Y:= HHGear^.Y-int2hwFloat(succ(i));
       
   104         if Gear^.Message and gmDown <> 0 then
       
   105             HHGear^.dY.QWordValue:= 0
       
   106         end;
       
   107     if TestCollisionXwithGear(HHGear, 1) and not TestCollisionXwithGear(HHGear, -1) then
       
   108         begin
       
   109         i:= 1;
       
   110         repeat
       
   111             begin
       
   112             inc(i);
       
   113             stuck:= TestCollisionXwithGear(HHGear, i)
       
   114             end
       
   115         until (i = 8) or not stuck;
       
   116         HHGear^.X:= HHGear^.X-int2hwFloat(pred(i));
       
   117         if Gear^.Message and gmDown <> 0 then
       
   118             HHGear^.dX.QWordValue:= 0
       
   119         end
       
   120     else if TestCollisionXwithGear(HHGear, -1) and not TestCollisionXwithGear(HHGear, 1) then
       
   121         begin
       
   122         i:= -1;
       
   123         repeat
       
   124             begin
       
   125             dec(i);
       
   126             stuck:= TestCollisionXwithGear(HHGear, i)
       
   127             end
       
   128         until (i = -8) or not stuck;
       
   129         HHGear^.X:= HHGear^.X-int2hwFloat(succ(i));
       
   130         if Gear^.Message and gmDown <> 0 then
       
   131             HHGear^.dX.QWordValue:= 0
       
   132         end
       
   133 end;
       
   134 
    76 procedure RopeDeleteMe(Gear, HHGear: PGear);
   135 procedure RopeDeleteMe(Gear, HHGear: PGear);
    77 begin
   136 begin
    78     PlaySound(sndRopeRelease);
   137     PlaySound(sndRopeRelease);
    79     HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
   138     HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
    80     HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;
   139     HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;
    81     with HHGear^ do
   140     with HHGear^ do
    82         begin
   141         begin
    83         Message := Message and (not gmAttack);
   142         Message := Message and (not gmAttack);
    84         State := (State or gstMoving) and (not gstWinner);
   143         State := (State or gstMoving) and (not gstWinner);
    85         end;
   144         end;
       
   145     unstickHog(Gear, HHGear);
    86     DeleteGear(Gear)
   146     DeleteGear(Gear)
    87 end;
   147 end;
    88 
   148 
    89 procedure RopeWaitCollision(Gear, HHGear: PGear);
   149 procedure RopeWaitCollision(Gear, HHGear: PGear);
    90 var i: LongInt;
       
    91     stuck: Boolean;
       
    92 begin
   150 begin
    93     PlaySound(sndRopeRelease);
   151     PlaySound(sndRopeRelease);
    94     with HHGear^ do
   152     with HHGear^ do
    95         begin
   153         begin
    96         Message := Message and (not gmAttack);
   154         Message := Message and (not gmAttack);
    97         State := State or gstMoving;
   155         State := State or gstMoving;
    98         end;
   156         end;
    99     if (TestCollisionYwithGear(HHGear, 1) <> 0) and (TestCollisionYwithGear(HHGear, -1) = 0) then
   157     unstickHog(Gear, HHGear);
   100         begin
       
   101         i:= 1;
       
   102         repeat
       
   103             begin
       
   104             inc(i);
       
   105             stuck:= TestCollisionYwithGear(HHGear, i) <> 0
       
   106             end
       
   107         until (i = 8) or not stuck;
       
   108         HHGear^.Y:= HHGear^.Y-int2hwFloat(pred(i))
       
   109         end;
       
   110     RopePoints.Count := 0;
   158     RopePoints.Count := 0;
   111     Gear^.Elasticity := _0;
   159     Gear^.Elasticity := _0;
   112     Gear^.doStep := @doStepRopeAfterAttack;
   160     Gear^.doStep := @doStepRopeAfterAttack;
   113     HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
   161     HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq;
   114     HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;
   162     HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq;