( item: BulletRecord | TankRecord | EagleRecord | PowerUpRecord, enlargement = 0, )
| 63 | |
| 64 | // 将BulletRecord/TankRecord/Eagle/PowerUpRecord转换为Rect类型对象 |
| 65 | export 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 | |
| 103 | type UpdaterMaker = (amount: number) => (x: number) => number |
| 104 | export const inc: UpdaterMaker = amount => x => x + amount |
no outgoing calls
no test coverage detected