张延森 3 år sedan
förälder
incheckning
0432f170d9

+ 3
- 3
src/pages/game/algorithm/bullet.js Visa fil

@@ -48,10 +48,10 @@ export default ({two, center, speed, getGameState}) => {
48 48
   }
49 49
   
50 50
   // 子弹飞行
51
-  function fly() {
51
+  function fly(_, timeDelay) {
52 52
     if (!current) return;
53
-    const { top, height } = current.getBoundingClientRect()
54
-    current.position = new Two.Vector(current.position.x, current.position.y + speed)
53
+    // const { top, height } = current.getBoundingClientRect()
54
+    current.position = new Two.Vector(current.position.x, current.position.y +  (speed * timeDelay / 1000))
55 55
 
56 56
     // 子弹飞行事件
57 57
     _event.dispatchEvent('shooting', { 

+ 2
- 3
src/pages/game/algorithm/cage.js Visa fil

@@ -62,9 +62,8 @@ export function drawTargeCages({ two, center }) {
62 62
     // 可接受校验偏差范围
63 63
     const offset = cageRadius / 3;
64 64
 
65
-    const rect2 = bullet.getBoundingClientRect();
66
-    const x = rect2.left + rect2.width / 2;
67
-    const y = rect2.top + rect2.height / 2;
65
+    const x = bullet.position.x;
66
+    const y = bullet.position.y;
68 67
 
69 68
     // 如果子弹 y 坐标超过警戒线
70 69
     if (y < center.y + wheelRaduis + offset) {

+ 3
- 20
src/pages/game/algorithm/index.js Visa fil

@@ -8,14 +8,11 @@ import { drawPedestal } from './pedestal';
8 8
 import drawBullets from './bullet';
9 9
 import { drawCounter } from './counter';
10 10
 
11
-export default ({ el, center, rotateSpeed = 0.045, speed = -12 }) => {
11
+export default ({ el, center, rotateSpeed = 2, speed = -360 }) => {
12 12
     
13 13
   // 修复一个单页面应用, 不能重复加载图片的bug
14 14
   Two.Texture.ImageRegistry = new Two.Registry();
15 15
 
16
-  // 30FPS
17
-  const FRAMERATE = 1000 / 30;
18
-
19 16
   // 初始化
20 17
   const two = new Two({
21 18
     type: Two.Types.svg,
@@ -52,8 +49,6 @@ export default ({ el, center, rotateSpeed = 0.045, speed = -12 }) => {
52 49
 
53 50
   // 整体绘制结束  
54 51
   two.update();
55
-  // 页面刷新定时器
56
-  let frameRateInterval = null;
57 52
 
58 53
   // 下面是业务逻辑部分
59 54
 
@@ -114,28 +109,16 @@ export default ({ el, center, rotateSpeed = 0.045, speed = -12 }) => {
114 109
       status = 1; // 游戏开始
115 110
       clip.bulletLoad() // 先上膛一颗子弹
116 111
       wheel.rotate();
117
-      // two.play();
118
-
119
-      console.log('----------FRAME RATE---------', FRAMERATE)
120
-
121
-      if (frameRateInterval) {
122
-        clearInterval(frameRateInterval)
123
-      } else {
124
-        setInterval(function() {
125
-          two.update();
126
-        }, FRAMERATE);
127
-      }
112
+      two.play();
128 113
     },
129 114
     pause: () => {
130 115
       wheel.stop();
131
-      // two.pause();
132
-      clearInterval(frameRateInterval)
116
+      two.pause();
133 117
     },
134 118
     destroy: () => {
135 119
       two.unbind('update');
136 120
       two.pause();
137 121
       el.removeChild(two.renderer.domElement);
138
-      clearInterval(frameRateInterval);
139 122
     }
140 123
   }
141 124
 }

+ 1
- 1
src/pages/game/algorithm/pedestal.js Visa fil

@@ -34,7 +34,7 @@ export function drawPedestal ({ two, center }) {
34 34
   pedestalBox.scale = scale;
35 35
 
36 36
   // 绘制底座上的绳子
37
-  const ropeSequence = two.makeImageSequence(ropeImageList, x, y, 30); // 40 是不断调式出来的频率, 需要跟 speed 匹配
37
+  const ropeSequence = two.makeImageSequence(ropeImageList, x, y, 40); // 40 是不断调式出来的频率, 需要跟 speed 匹配
38 38
   ropeSequence.scale = new Two.Vector(scale, scale);
39 39
 
40 40
   return {

+ 3
- 2
src/pages/game/algorithm/wheel.js Visa fil

@@ -18,9 +18,10 @@ export function drawWheel({ two, center, rotateSpeed, cages }) {
18 18
   // 摩天轮与轿厢旋转
19 19
   let _count = 0;
20 20
   let rotateAngle = 0;
21
-  const wheelRotate = () => {
21
+  const wheelRotate = (_, timeDelay) => {
22 22
     _count += 1;
23
-    rotateAngle += rotateSpeed
23
+    // rotateAngle += rotateSpeed
24
+    rotateAngle += rotateSpeed * timeDelay / 1000
24 25
     wheelArc.rotation = rotateAngle
25 26
     cages.forEach(cage => {
26 27
       const angle = cage.__$angle + rotateAngle + perAngle / 2  // 除以2是为了视觉上轿厢与摩天轮的轴对齐