hedgewars/GSHandlers.inc
changeset 7370 d50b874e7ee8
parent 7341 d70478d265ec
child 7389 15c3fb4882df
equal deleted inserted replaced
7368:20448801e86a 7370:d50b874e7ee8
  3052         end
  3052         end
  3053     else dec(Gear^.Pos)
  3053     else dec(Gear^.Pos)
  3054 end;
  3054 end;
  3055 
  3055 
  3056 
  3056 
  3057 procedure PrevAngle(Gear: PGear; dA: LongInt);
       
  3058 begin
       
  3059     Gear^.Angle := (LongInt(Gear^.Angle) + 4 - dA) mod 4
       
  3060 end;
       
  3061 
       
  3062 procedure NextAngle(Gear: PGear; dA: LongInt);
       
  3063 begin
       
  3064     Gear^.Angle := (LongInt(Gear^.Angle) + 4 + dA) mod 4
       
  3065 end;
       
  3066 
       
  3067 procedure doStepCakeWork(Gear: PGear);
  3057 procedure doStepCakeWork(Gear: PGear);
  3068 
  3058 
  3069 const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
  3059 const dirs: array[0..3] of TPoint =   ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0));
  3070 var 
  3060 var
  3071     xx, yy, xxn, yyn: LongInt;
  3061     xx, yy, xxn, yyn: LongInt;
  3072     dA: LongInt;
  3062     dA: LongInt;
  3073     tdx, tdy: hwFloat;
  3063     tdx, tdy: hwFloat;
  3074 begin
  3064 begin
  3075     AllInactive := false;
  3065     AllInactive := false;
  3076 
  3066 
  3077     inc(Gear^.Tag);
  3067     inc(Gear^.Tag);
  3078     if Gear^.Tag < 7 then
  3068     if Gear^.Tag < 7 then
  3079         exit;
  3069         exit;
  3080 
  3070 
  3081     dA := hwSign(Gear^.dX);
  3071     cakeStep(Gear);
  3082     xx := dirs[Gear^.Angle].x;
       
  3083     yy := dirs[Gear^.Angle].y;
       
  3084     xxn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].x;
       
  3085     yyn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].y;
       
  3086 
       
  3087     if (xx = 0) then
       
  3088         if TestCollisionYwithGear(Gear, yy) <> 0 then
       
  3089             PrevAngle(Gear, dA)
       
  3090     else
       
  3091         begin
       
  3092         Gear^.Tag := 0;
       
  3093         Gear^.Y := Gear^.Y + int2hwFloat(yy);
       
  3094         if not TestCollisionXwithGear(Gear, xxn) then
       
  3095             begin
       
  3096             Gear^.X := Gear^.X + int2hwFloat(xxn);
       
  3097             NextAngle(Gear, dA)
       
  3098             end;
       
  3099         end;
       
  3100 
       
  3101     if (yy = 0) then
       
  3102         if TestCollisionXwithGear(Gear, xx) then
       
  3103             PrevAngle(Gear, dA)
       
  3104     else
       
  3105         begin
       
  3106         Gear^.Tag := 0;
       
  3107         Gear^.X := Gear^.X + int2hwFloat(xx);
       
  3108         if TestCollisionYwithGear(Gear, yyn) = 0 then
       
  3109             begin
       
  3110             Gear^.Y := Gear^.Y + int2hwFloat(yyn);
       
  3111             NextAngle(Gear, dA)
       
  3112             end;
       
  3113         end;
       
  3114 
  3072 
  3115     if Gear^.Tag = 0 then
  3073     if Gear^.Tag = 0 then
  3116         begin
  3074         begin
  3117         CakeI := (CakeI + 1) mod cakeh;
  3075         CakeI := (CakeI + 1) mod cakeh;
  3118         tdx := CakePoints[CakeI].x - Gear^.X;
  3076         tdx := CakePoints[CakeI].x - Gear^.X;