( activeTanks: TanksMap, tank: TankRecord, tankTarget: Rect, threshhold: number, )
| 72 | } |
| 73 | |
| 74 | function isTankCollidedWithOtherTanks( |
| 75 | activeTanks: TanksMap, |
| 76 | tank: TankRecord, |
| 77 | tankTarget: Rect, |
| 78 | threshhold: number, |
| 79 | ) { |
| 80 | // 判断坦克与其他坦克是否相撞 |
| 81 | for (const otherTank of activeTanks.values()) { |
| 82 | if (tank.tankId === otherTank.tankId) { |
| 83 | continue |
| 84 | } |
| 85 | // 判断坦克相撞时,只需要考虑当前坦克前方的其他坦克 |
| 86 | // 且其他坦克需要使用「预留位置」 |
| 87 | const otherReserved = otherTank.useReservedXY() |
| 88 | if ( |
| 89 | isInFront(otherReserved, tank) && |
| 90 | testCollide(asRect(otherReserved), tankTarget, threshhold) |
| 91 | ) { |
| 92 | return true |
| 93 | } |
| 94 | } |
| 95 | return false |
| 96 | } |
| 97 | |
| 98 | export default function canTankMove(state: State, tank: TankRecord, threshhold = -0.01) { |
| 99 | const { |
no test coverage detected