1052 Gear:= nil |
1052 Gear:= nil |
1053 end |
1053 end |
1054 end |
1054 end |
1055 end; |
1055 end; |
1056 |
1056 |
|
1057 function CheckGearNearImpl(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt, exclude: PGear): PGear; |
|
1058 begin |
|
1059 var t: PGear; |
|
1060 halfWidth, dX, dY: hwFloat; |
|
1061 isHit: Boolean; |
|
1062 begin |
|
1063 t:= GearsList; |
|
1064 rX:= sqr(rX); |
|
1065 rY:= sqr(rY); |
|
1066 halfWidth:= int2hwFloat(RightX - LeftX) / _2; |
|
1067 |
|
1068 while t <> nil do |
|
1069 begin |
|
1070 if (t <> exclude) and (t^.Kind = Kind) then |
|
1071 begin |
|
1072 dX := X - t^.X; |
|
1073 dY := Y - t^.Y; |
|
1074 isHit := not ((hwSqr(dX) / rX + hwSqr(dY) / rY) > _1); |
|
1075 |
|
1076 if (not isHit) and (WorldEdge = weWrap) then |
|
1077 begin |
|
1078 if (dX > halfWidth) and (not ((hwSqr(dX - halfWidth) / rX + hwSqr(dY) / rY) > _1)) then |
|
1079 isHit := true |
|
1080 else if (dX < -halfWidth) and (not ((hwSqr(dX + halfWidth) / rX + hwSqr(dY) / rY) > _1)) then |
|
1081 isHit := true |
|
1082 end; |
|
1083 |
|
1084 if isHit then |
|
1085 begin |
|
1086 CheckGearNear:= t; |
|
1087 exit; |
|
1088 end; |
|
1089 end; |
|
1090 t:= t^.NextGear |
|
1091 end; |
|
1092 |
|
1093 CheckGearNear:= nil |
|
1094 end; |
|
1095 |
1057 function CheckGearNear(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt): PGear; |
1096 function CheckGearNear(Kind: TGearType; X, Y: hwFloat; rX, rY: LongInt): PGear; |
1058 var t: PGear; |
1097 begin |
1059 width: hwFloat; |
1098 CheckGearNear := CheckGearNearImpl(Kind, X, Y, rX, rY, nil); |
1060 begin |
|
1061 t:= GearsList; |
|
1062 rX:= sqr(rX); |
|
1063 rY:= sqr(rY); |
|
1064 width:= int2hwFloat(RightX-LeftX); |
|
1065 |
|
1066 while t <> nil do |
|
1067 begin |
|
1068 if (t^.Kind = Kind) then |
|
1069 if (not ((hwSqr(X - t^.X) / rX + hwSqr(Y - t^.Y) / rY) > _1)) or |
|
1070 ((WorldEdge = weWrap) and ( |
|
1071 (not ((hwSqr(X - width - t^.X) / rX + hwSqr(Y - t^.Y) / rY) > _1)) or |
|
1072 (not ((hwSqr(X + width - t^.X) / rX + hwSqr(Y - t^.Y) / rY) > _1)))) then |
|
1073 begin |
|
1074 CheckGearNear:= t; |
|
1075 exit; |
|
1076 end; |
|
1077 t:= t^.NextGear |
|
1078 end; |
|
1079 |
|
1080 CheckGearNear:= nil |
|
1081 end; |
1099 end; |
1082 |
1100 |
1083 function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
1101 function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear; |
1084 var t: PGear; |
1102 begin |
1085 width: hwFloat; |
1103 CheckGearNear := CheckGearNearImpl(Kind, Gear^.X, Gear^.Y, rX, rY, Gear); |
1086 begin |
|
1087 t:= GearsList; |
|
1088 rX:= sqr(rX); |
|
1089 rY:= sqr(rY); |
|
1090 width:= int2hwFloat(RightX-LeftX); |
|
1091 |
|
1092 while t <> nil do |
|
1093 begin |
|
1094 if (t <> Gear) and (t^.Kind = Kind) then |
|
1095 if (not ((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)) or |
|
1096 ((WorldEdge = weWrap) and ( |
|
1097 (not ((hwSqr(Gear^.X - width - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)) or |
|
1098 (not ((hwSqr(Gear^.X + width - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1)))) then |
|
1099 begin |
|
1100 CheckGearNear:= t; |
|
1101 exit; |
|
1102 end; |
|
1103 t:= t^.NextGear |
|
1104 end; |
|
1105 |
|
1106 CheckGearNear:= nil |
|
1107 end; |
1104 end; |
1108 |
1105 |
1109 procedure CheckCollision(Gear: PGear); inline; |
1106 procedure CheckCollision(Gear: PGear); inline; |
1110 begin |
1107 begin |
1111 if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0) |
1108 if (TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) <> 0) |