MCPcopy
hub / github.com/feichao93/battle-city / isTankCollidedWithOtherTanks

Function isTankCollidedWithOtherTanks

app/utils/canTankMove.ts:74–96  ·  view source on GitHub ↗
(
  activeTanks: TanksMap,
  tank: TankRecord,
  tankTarget: Rect,
  threshhold: number,
)

Source from the content-addressed store, hash-verified

72}
73
74function 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
98export default function canTankMove(state: State, tank: TankRecord, threshhold = -0.01) {
99 const {

Callers 1

canTankMoveFunction · 0.85

Calls 4

testCollideFunction · 0.90
asRectFunction · 0.90
isInFrontFunction · 0.85
useReservedXYMethod · 0.80

Tested by

no test coverage detected