7172 Gear^.doStep := @doStepBulletWork |
7172 Gear^.doStep := @doStepBulletWork |
7173 end; |
7173 end; |
7174 |
7174 |
7175 //////////////////////////////////////////////////////////////////////////////// |
7175 //////////////////////////////////////////////////////////////////////////////// |
7176 |
7176 |
|
7177 function MakeSentryStep(Sentry: PGear; maxYStep: LongInt): Boolean; |
|
7178 var x, y, offset, direction: LongInt; |
|
7179 begin |
|
7180 MakeSentryStep := false; |
|
7181 x := hwRound(Sentry^.X); |
|
7182 y := hwRound(Sentry^.Y); |
|
7183 direction := hwSign(Sentry^.dX); |
|
7184 |
|
7185 for offset := -maxYStep - 1 to maxYStep + 1 do |
|
7186 begin |
|
7187 if TestCollisionYImpl(x + direction, y + offset, Sentry^.Radius, 1, Sentry^.CollisionMask) <> 0 then |
|
7188 break; |
|
7189 end; |
|
7190 |
|
7191 if (offset >= -maxYStep) and (offset <= maxYStep) then |
|
7192 begin |
|
7193 Sentry^.X := Sentry^.X + signAs(_1, Sentry^.dX); |
|
7194 Sentry^.Y := Sentry^.Y + int2hwFloat(offset); |
|
7195 MakeSentryStep := true |
|
7196 end |
|
7197 end; |
|
7198 |
7177 procedure doStepSentry(Gear: PGear); |
7199 procedure doStepSentry(Gear: PGear); |
7178 var HHGear, bullet: PGear; |
7200 var HHGear, bullet: PGear; |
7179 distX, distY, invDistance: HwFloat; |
7201 distX, distY, invDistance: HwFloat; |
7180 const sentry_Idle = 0; |
7202 const sentry_Idle = 0; |
7181 sentry_Walking = 1; |
7203 sentry_Walking = 1; |
7203 if Gear^.Tag = sentry_Idle then |
7225 if Gear^.Tag = sentry_Idle then |
7204 begin |
7226 begin |
7205 Gear^.Tag := sentry_Walking; |
7227 Gear^.Tag := sentry_Walking; |
7206 Gear^.Timer := 1000 + GetRandom(3000); |
7228 Gear^.Timer := 1000 + GetRandom(3000); |
7207 Gear^.dX.isNegative := GetRandom(2) = 1; |
7229 Gear^.dX.isNegative := GetRandom(2) = 1; |
7208 if TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0 then |
|
7209 Gear^.dX.isNegative := not Gear^.dX.isNegative; |
|
7210 end |
7230 end |
7211 else if Gear^.Tag in [sentry_Walking, sentry_Reloading] then |
7231 else if Gear^.Tag in [sentry_Walking, sentry_Reloading] then |
7212 begin |
7232 begin |
7213 Gear^.Tag := sentry_Idle; |
7233 Gear^.Tag := sentry_Idle; |
7214 Gear^.Timer := 1000 + GetRandom(1000); |
7234 Gear^.Timer := 1000 + GetRandom(1000); |
7255 end; |
7275 end; |
7256 end; |
7276 end; |
7257 |
7277 |
7258 if (Gear^.Tag = sentry_Walking) and ((GameTicks and $1F) = 0) then |
7278 if (Gear^.Tag = sentry_Walking) and ((GameTicks and $1F) = 0) then |
7259 begin |
7279 begin |
7260 MakeHedgehogsStep(Gear); |
7280 if not MakeSentryStep(Gear, 6) then |
7261 if TestCollisionX(Gear, hwSign(Gear^.dX)) <> 0 then |
|
7262 Gear^.Timer := 0 |
7281 Gear^.Timer := 0 |
7263 end; |
7282 end; |
7264 |
7283 |
7265 if ((GameTicks and $FF) = 0) |
7284 if ((GameTicks and $FF) = 0) |
7266 and (Gear^.Tag in [sentry_Idle, sentry_Walking]) |
7285 and (Gear^.Tag in [sentry_Idle, sentry_Walking]) |
7270 begin |
7289 begin |
7271 HHGear := CurrentHedgehog^.Gear; |
7290 HHGear := CurrentHedgehog^.Gear; |
7272 distX := HHGear^.X - Gear^.X; |
7291 distX := HHGear^.X - Gear^.X; |
7273 distY := HHGear^.Y - Gear^.Y; |
7292 distY := HHGear^.Y - Gear^.Y; |
7274 if (distX.isNegative = Gear^.dX.isNegative) |
7293 if (distX.isNegative = Gear^.dX.isNegative) |
7275 and (distX.Round > 32) |
7294 and (distX.Round > 24) |
7276 and (distX.Round < 500) |
7295 and (distX.Round < 500) |
7277 and (hwAbs(distY) < hwAbs(distX)) then |
7296 and (hwAbs(distY) < hwAbs(distX)) then |
7278 begin |
7297 begin |
7279 Gear^.Target.X := hwRound(HHGear^.X); |
7298 Gear^.Target.X := hwRound(HHGear^.X); |
7280 Gear^.Target.Y := hwRound(HHGear^.Y); |
7299 Gear^.Target.Y := hwRound(HHGear^.Y); |