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

Function canTankMove

app/utils/canTankMove.ts:98–137  ·  view source on GitHub ↗
(state: State, tank: TankRecord, threshhold = -0.01)

Source from the content-addressed store, hash-verified

96}
97
98export default function canTankMove(state: State, tank: TankRecord, threshhold = -0.01) {
99 const {
100 tanks,
101 map: { bricks, steels, rivers, eagle, restrictedAreas },
102 } = state
103 const tankRect = asRect(tank)
104
105 // 判断是否位于战场内
106 if (!isInField(tankRect)) {
107 return false
108 }
109
110 // 判断是否与地形相碰撞
111 if (isTankCollidedWithEagle(eagle, tankRect, threshhold)) {
112 return false
113 }
114 if (isTankCollidedWithBricks(bricks, tankRect, threshhold)) {
115 return false
116 }
117 if (isTankCollidedWithSteels(steels, tankRect, threshhold)) {
118 return false
119 }
120 if (isTankCollidedWithRivers(rivers, tankRect, threshhold)) {
121 return false
122 }
123
124 // 判断是否与保留区域有碰撞
125 if (isTankCollidedWithRestrictedAreas(restrictedAreas, tankRect, threshhold)) {
126 return false
127 }
128
129 // 判断是否与其他坦克相碰撞
130 const activeTanks = tanks.filter(t => t.alive)
131 if (isTankCollidedWithOtherTanks(activeTanks, tank, tankRect, threshhold)) {
132 return false
133 }
134
135 // 与其他物品都没有相撞, 则表示可以进行移动
136 return true
137}

Callers

nothing calls this directly

Calls 8

asRectFunction · 0.90
isInFieldFunction · 0.90
isTankCollidedWithEagleFunction · 0.85
isTankCollidedWithBricksFunction · 0.85
isTankCollidedWithSteelsFunction · 0.85
isTankCollidedWithRiversFunction · 0.85

Tested by

no test coverage detected