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

Function asRect

app/utils/common.ts:65–101  ·  view source on GitHub ↗
(
  item: BulletRecord | TankRecord | EagleRecord | PowerUpRecord,
  enlargement = 0,
)

Source from the content-addressed store, hash-verified

63
64// 将BulletRecord/TankRecord/Eagle/PowerUpRecord转换为Rect类型对象
65export function asRect(
66 item: BulletRecord | TankRecord | EagleRecord | PowerUpRecord,
67 enlargement = 0,
68): Rect {
69 if (item instanceof BulletRecord) {
70 return {
71 x: item.x - (BULLET_SIZE / 2) * enlargement,
72 y: item.y - (BULLET_SIZE / 2) * enlargement,
73 width: BULLET_SIZE * (1 + enlargement),
74 height: BULLET_SIZE * (1 + enlargement),
75 }
76 } else if (item instanceof TankRecord) {
77 return {
78 x: item.x - (TANK_SIZE / 2) * enlargement,
79 y: item.y - (TANK_SIZE / 2) * enlargement,
80 width: TANK_SIZE * (1 + enlargement),
81 height: TANK_SIZE * (1 + enlargement),
82 }
83 } else if (item instanceof EagleRecord) {
84 return {
85 x: item.x - (BLOCK_SIZE / 2) * enlargement,
86 y: item.y - (BLOCK_SIZE / 2) * enlargement,
87 width: BLOCK_SIZE * (1 + enlargement),
88 height: BLOCK_SIZE * (1 + enlargement),
89 }
90 } else if (item instanceof PowerUpRecord) {
91 DEV.ASSERT && console.assert(enlargement === -0.5)
92 return {
93 x: item.x - (BLOCK_SIZE / 2) * enlargement,
94 y: item.y - (BLOCK_SIZE / 2) * enlargement,
95 width: BLOCK_SIZE * (1 + enlargement),
96 height: BLOCK_SIZE * (1 + enlargement),
97 }
98 } else {
99 throw new Error('Cannot convert to type Rect')
100 }
101}
102
103type UpdaterMaker = (amount: number) => (x: number) => number
104export const inc: UpdaterMaker = amount => x => x + amount

Callers 15

canTankMoveFunction · 0.90
availableSpawnPositionFunction · 0.90
getCollisionRectMethod · 0.90
spreadBulletFunction · 0.90
convertToBricksFunction · 0.90
convertToSteelsFunction · 0.90
handleTankPickPowerUpsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected