张延森 3 年之前
父節點
當前提交
0432f170d9

+ 3
- 3
src/pages/game/algorithm/bullet.js 查看文件

48
   }
48
   }
49
   
49
   
50
   // 子弹飞行
50
   // 子弹飞行
51
-  function fly() {
51
+  function fly(_, timeDelay) {
52
     if (!current) return;
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
     _event.dispatchEvent('shooting', { 
57
     _event.dispatchEvent('shooting', { 

+ 2
- 3
src/pages/game/algorithm/cage.js 查看文件

62
     // 可接受校验偏差范围
62
     // 可接受校验偏差范围
63
     const offset = cageRadius / 3;
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
     // 如果子弹 y 坐标超过警戒线
68
     // 如果子弹 y 坐标超过警戒线
70
     if (y < center.y + wheelRaduis + offset) {
69
     if (y < center.y + wheelRaduis + offset) {

+ 3
- 20
src/pages/game/algorithm/index.js 查看文件

8
 import drawBullets from './bullet';
8
 import drawBullets from './bullet';
9
 import { drawCounter } from './counter';
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
   // 修复一个单页面应用, 不能重复加载图片的bug
13
   // 修复一个单页面应用, 不能重复加载图片的bug
14
   Two.Texture.ImageRegistry = new Two.Registry();
14
   Two.Texture.ImageRegistry = new Two.Registry();
15
 
15
 
16
-  // 30FPS
17
-  const FRAMERATE = 1000 / 30;
18
-
19
   // 初始化
16
   // 初始化
20
   const two = new Two({
17
   const two = new Two({
21
     type: Two.Types.svg,
18
     type: Two.Types.svg,
52
 
49
 
53
   // 整体绘制结束  
50
   // 整体绘制结束  
54
   two.update();
51
   two.update();
55
-  // 页面刷新定时器
56
-  let frameRateInterval = null;
57
 
52
 
58
   // 下面是业务逻辑部分
53
   // 下面是业务逻辑部分
59
 
54
 
114
       status = 1; // 游戏开始
109
       status = 1; // 游戏开始
115
       clip.bulletLoad() // 先上膛一颗子弹
110
       clip.bulletLoad() // 先上膛一颗子弹
116
       wheel.rotate();
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
     pause: () => {
114
     pause: () => {
130
       wheel.stop();
115
       wheel.stop();
131
-      // two.pause();
132
-      clearInterval(frameRateInterval)
116
+      two.pause();
133
     },
117
     },
134
     destroy: () => {
118
     destroy: () => {
135
       two.unbind('update');
119
       two.unbind('update');
136
       two.pause();
120
       two.pause();
137
       el.removeChild(two.renderer.domElement);
121
       el.removeChild(two.renderer.domElement);
138
-      clearInterval(frameRateInterval);
139
     }
122
     }
140
   }
123
   }
141
 }
124
 }

+ 1
- 1
src/pages/game/algorithm/pedestal.js 查看文件

34
   pedestalBox.scale = scale;
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
   ropeSequence.scale = new Two.Vector(scale, scale);
38
   ropeSequence.scale = new Two.Vector(scale, scale);
39
 
39
 
40
   return {
40
   return {

+ 3
- 2
src/pages/game/algorithm/wheel.js 查看文件

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