张延森 3 년 전
부모
커밋
dca94e0a00
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5
    2
      src/game.js

+ 5
- 2
src/game.js 파일 보기

@@ -135,8 +135,8 @@ export default function game({ el, onError, onSuccess }) {
135 135
   // 射击
136 136
   const shooting = () => {
137 137
     isShooting = true
138
-    const { left, width, top } = currentBullet.getBoundingClientRect()
139
-    currentBullet.position = new Two.Vector(left + width / 2, top + speed)
138
+    const { top } = currentBullet.getBoundingClientRect()
139
+    currentBullet.position = new Two.Vector(currentBullet.position.x, top + speed)
140 140
 
141 141
     const hitted = isHit(currentBullet)
142 142
     if (hitted === 'error') {
@@ -171,6 +171,9 @@ export default function game({ el, onError, onSuccess }) {
171 171
 
172 172
     const cage = cageList.filter((it) => {
173 173
       const rect1 = it.getBoundingClientRect();
174
+
175
+      // 如果当前子弹的中心点位于目标轿厢矩形范围内
176
+      // 则代表击中
174 177
       return x >= rect1.left && x <= rect1.right &&
175 178
           y >= rect1.top && y <= rect1.bottom;
176 179
     })[0]