Przeglądaj źródła

Merge branch 'master' of http://git.ycjcjy.com/honghe/roundabout

[baozhangchao] 3 lat temu
rodzic
commit
a472a9ee28

+ 37
- 7
src/components/FireWork.vue Wyświetl plik

11
       <div class="drops-grp">
11
       <div class="drops-grp">
12
         <span
12
         <span
13
           class="drop drop-1"
13
           class="drop drop-1"
14
+          :style="dropStyle"
14
           @animationend="handleAnimationEnd"
15
           @animationend="handleAnimationEnd"
15
         />
16
         />
16
-        <span class="drop drop-2" />
17
-        <span class="drop drop-3" />
18
-        <span class="drop drop-4" />
17
+        <span
18
+          class="drop drop-2"
19
+          :style="dropStyle"
20
+        />
21
+        <span
22
+          class="drop drop-3"
23
+          :style="dropStyle"
24
+        />
25
+        <span
26
+          class="drop drop-4"
27
+          :style="dropStyle"
28
+        />
19
       </div>
29
       </div>
20
       <div class="drops-grp drops-grp2">
30
       <div class="drops-grp drops-grp2">
21
-        <span class="drop drop-1" />
22
-        <span class="drop drop-2" />
23
-        <span class="drop drop-3" />
24
-        <span class="drop drop-4" />
31
+        <span
32
+          class="drop drop-1"
33
+          :style="dropStyle"
34
+        />
35
+        <span
36
+          class="drop drop-2"
37
+          :style="dropStyle"
38
+        />
39
+        <span
40
+          class="drop drop-3"
41
+          :style="dropStyle"
42
+        />
43
+        <span
44
+          class="drop drop-4"
45
+          :style="dropStyle"
46
+        />
25
       </div>
47
       </div>
26
     </div>
48
     </div>
27
   </div>
49
   </div>
52
 		type: Boolean,
74
 		type: Boolean,
53
 		default: false
75
 		default: false
54
 	},
76
 	},
77
+	duration: {
78
+    type: Number,
79
+    default: 1.2
80
+	},
55
 })
81
 })
56
 
82
 
57
 const grpStyle = computed(() => ({
83
 const grpStyle = computed(() => ({
64
     transform: `scale(${props.scale})`,
90
     transform: `scale(${props.scale})`,
65
   }))
91
   }))
66
 
92
 
93
+const dropStyle = computed(() => ({
94
+	animationDuration: `${props.duration}s`,
95
+}))
96
+
67
 const handleAnimationEnd = () => {
97
 const handleAnimationEnd = () => {
68
 	emit('end')
98
 	emit('end')
69
 }
99
 }

+ 8
- 2
src/components/FireWorkList.vue Wyświetl plik

8
       :top="calcTop(it)"
8
       :top="calcTop(it)"
9
       :scale="clacScale()"
9
       :scale="clacScale()"
10
       :visible="!isFinished"
10
       :visible="!isFinished"
11
+      :duration="duration"
11
       @end="handleEnd"
12
       @end="handleEnd"
12
     />
13
     />
13
   </div>
14
   </div>
44
 
45
 
45
 const fireNum = ref(12)
46
 const fireNum = ref(12)
46
 const isFinished = ref(true)
47
 const isFinished = ref(true)
48
+const duration = ref(0.8)
47
 
49
 
48
 const calcLeft = (inx) => {
50
 const calcLeft = (inx) => {
49
   let start, end
51
   let start, end
70
   const r = Math.random()
72
   const r = Math.random()
71
 
73
 
72
   if (r < 0.1) return 0.1
74
   if (r < 0.1) return 0.1
73
-  if (r > 0.5) return 0.5
75
+  if (r > 0.9) return 1
74
   return r
76
   return r
75
 }
77
 }
76
 
78
 
85
 }
87
 }
86
 
88
 
87
 defineExpose({
89
 defineExpose({
88
-  toggle: () => (isFinished.value = false)
90
+  toggle: () => {
91
+    const t = setInterval(() => {
92
+      isFinished.value = false
93
+    }, duration.value * 1000)
94
+  }
89
 })
95
 })
90
 </script>
96
 </script>

+ 25
- 9
src/pages/game/game.js Wyświetl plik

108
     const lightTexture = two.makeTexture(lightImage);
108
     const lightTexture = two.makeTexture(lightImage);
109
     lightArc.noStroke();
109
     lightArc.noStroke();
110
     lightArc.fill = lightTexture;
110
     lightArc.fill = lightTexture;
111
+    lightArc.opacity = 0; // 默认不显示
111
     lightTexture.bind('load', () => {
112
     lightTexture.bind('load', () => {
112
       lightArc.radius = lightTexture.image.naturalWidth / 2;
113
       lightArc.radius = lightTexture.image.naturalWidth / 2;
113
       lightArc.scale = scale;
114
       lightArc.scale = scale;
114
     })
115
     })
115
-    lightArc.bind('update', () => {
116
-      console.log('-----------lightArc----------')
117
-    })
118
 
116
 
119
     // 绘制辅助扇形区域
117
     // 绘制辅助扇形区域
120
     const arcList = Array(cageNum).fill().map((_, inx) => {
118
     const arcList = Array(cageNum).fill().map((_, inx) => {
150
   const roundAbout = drawRoundAbout()
148
   const roundAbout = drawRoundAbout()
151
 
149
 
152
   // 成功之后的特效
150
   // 成功之后的特效
153
-  const successEffect = () => {
151
+  let shakeTimes = 0;
152
+  const successShake = () => {
153
+    if (shakeTimes >= 10) {
154
+      return
155
+    }
154
 
156
 
157
+    if (!isError) {
158
+      const opStep = shakeTimes % 2 === 1 ? -0.04 : 0.04
159
+      lightArc.opacity += opStep;
160
+      if (lightArc.opacity >= 1 || lightArc.opacity <= 0) {
161
+        shakeTimes += 1;
162
+      }
163
+    }
155
   }
164
   }
156
 
165
 
157
   // 旋转
166
   // 旋转
332
   }
341
   }
333
   
342
   
334
   // 重复绘制内容
343
   // 重复绘制内容
335
-  two.bind('update', () => {
344
+  two.bind('update', () => {    
345
+    rotate()
336
     if (!isFinished) {
346
     if (!isFinished) {
337
-      rotate()
338
-
339
       if (isShooting) {
347
       if (isShooting) {
340
         shooting()
348
         shooting()
341
       }
349
       }
350
+    } else {
351
+      successShake()
342
     }
352
     }
343
   })
353
   })
344
 
354
 
345
   // 绑定 dom click 事件 触发子弹发射
355
   // 绑定 dom click 事件 触发子弹发射
346
-  el.addEventListener('click', () => {
356
+  const handleClick = () => {
347
     if (!isFinished && !isShooting) {
357
     if (!isFinished && !isShooting) {
348
       isShooting = true
358
       isShooting = true
349
       // 启动绳子效果
359
       // 启动绳子效果
353
         currentBullet.visible = true
363
         currentBullet.visible = true
354
       }
364
       }
355
     }
365
     }
356
-  })
366
+  }
367
+  el.addEventListener('click', handleClick);
357
 
368
 
358
   return {
369
   return {
370
+    two,
371
+    raduis,
359
     start: () => {
372
     start: () => {
360
       isFinished = false;
373
       isFinished = false;
361
     },
374
     },
365
     destroy: () => {    
378
     destroy: () => {    
366
       two.unbind('update');
379
       two.unbind('update');
367
       two.pause();
380
       two.pause();
381
+      two.clear();
368
       el.removeChild(two.renderer.domElement);
382
       el.removeChild(two.renderer.domElement);
383
+      el.removeEventListener('click', handleClick);
369
       two = null;
384
       two = null;
385
+      Two.Instances.pop()
370
     }
386
     }
371
   }
387
   }
372
 }
388
 }

+ 15
- 12
src/pages/game/index.vue Wyświetl plik

5
 
5
 
6
 <script setup>
6
 <script setup>
7
   import { onBeforeUnmount, onMounted, ref } from 'vue';
7
   import { onBeforeUnmount, onMounted, ref } from 'vue';
8
-import { useRouter, onBeforeRouteUpdate, onBeforeRouteLeave } from 'vue-router';
8
+  import { useRouter } from 'vue-router';
9
   import FireWorkListVue from '@/components/FireWorkList.vue';
9
   import FireWorkListVue from '@/components/FireWorkList.vue';
10
   import game from "./game.js";
10
   import game from "./game.js";
11
 
11
 
12
+  // // 修复一个 two-js bug ,当页面返回的时候, 不能正常渲染
13
+  // // 所以这边判断如果第二次进入页面就强制刷新
14
+  // const loadSign = localStorage.getItem('loadSign');
15
+  // if (loadSign) {
16
+  //   localStorage.removeItem('loadSign');
17
+  //   window.location.href = window.location.href;
18
+  // }
19
+
12
   const el = ref()
20
   const el = ref()
13
   const destroyRef = ref()
21
   const destroyRef = ref()
14
   const firesRef = ref()
22
   const firesRef = ref()
15
   const router = useRouter()
23
   const router = useRouter()
24
+  const raduis = ref(150)
16
 
25
 
17
   const center = {
26
   const center = {
18
         x: document.body.offsetWidth / 2,
27
         x: document.body.offsetWidth / 2,
19
         y: document.body.offsetHeight / 2,
28
         y: document.body.offsetHeight / 2,
20
       }
29
       }
21
 
30
 
22
-
23
   const gameInit = () => {
31
   const gameInit = () => {
24
     destroyRef.value = game({
32
     destroyRef.value = game({
25
       el: el.value,
33
       el: el.value,
27
       onError: () => {
35
       onError: () => {
28
         alert('oo ~')
36
         alert('oo ~')
29
         const t = setTimeout(() => {
37
         const t = setTimeout(() => {
38
+          localStorage.setItem('loadSign', '1');
30
           router.push('/OverPage?type=lose')
39
           router.push('/OverPage?type=lose')
31
           clearTimeout(t)
40
           clearTimeout(t)
32
         }, 1000)
41
         }, 1000)
33
       },
42
       },
34
       onSuccess: () => {
43
       onSuccess: () => {
44
+        firesRef.value.toggle()
35
         alert('你真牛逼')
45
         alert('你真牛逼')
36
         const t = setTimeout(() => {
46
         const t = setTimeout(() => {
47
+          localStorage.setItem('loadSign', '1');
37
           router.push('/OverPage?type=win')
48
           router.push('/OverPage?type=win')
38
           clearTimeout(t)
49
           clearTimeout(t)
39
         }, 1000)
50
         }, 1000)
40
       },
51
       },
41
       onBingo: () => {
52
       onBingo: () => {
42
-        firesRef.value.toggle()
43
       }
53
       }
44
     })
54
     })
45
-  }
46
 
55
 
47
-  onBeforeRouteUpdate(() => {
48
-    console.log('--------ref----<', el)
49
-  })
56
+    raduis.value = destroyRef.value.raduis
57
+  }
50
 
58
 
51
-  onBeforeRouteLeave(() => {
52
-    console.log('--------onBeforeRouteLeave----<')
53
-  })
54
 
59
 
55
   onMounted(() => {
60
   onMounted(() => {
56
     gameInit()
61
     gameInit()
57
-    console.log('--------onMounted----<', el)
58
   })
62
   })
59
 
63
 
60
   onBeforeUnmount(() => {
64
   onBeforeUnmount(() => {
61
-    console.log('--------onBeforeUnmount----<', el)
62
     if (destroyRef.value) {
65
     if (destroyRef.value) {
63
       destroyRef.value.destroy();
66
       destroyRef.value.destroy();
64
     }
67
     }

+ 3
- 3
src/router/index.js Wyświetl plik

1
-import { createRouter, createWebHistory } from 'vue-router'
1
+import { createRouter, createWebHashHistory } from 'vue-router'
2
 import homePage from '@/pages/homePage.vue'
2
 import homePage from '@/pages/homePage.vue'
3
 import OverPage from '@/pages/OverPage.vue'
3
 import OverPage from '@/pages/OverPage.vue'
4
 import TopRulePage from '@/pages/TopRulePage.vue'
4
 import TopRulePage from '@/pages/TopRulePage.vue'
5
 import GamePage from '@/pages/game'
5
 import GamePage from '@/pages/game'
6
-const routerHistory = createWebHistory()
6
+
7
 const routes = [
7
 const routes = [
8
   {
8
   {
9
     path: '/',
9
     path: '/',
25
 
25
 
26
 
26
 
27
 const router = createRouter({
27
 const router = createRouter({
28
-  history: routerHistory,
28
+  history: createWebHashHistory(),
29
   routes
29
   routes
30
 })
30
 })
31
 export default router
31
 export default router

+ 1
- 0
vue.config.js Wyświetl plik

2
 const path = require('path');
2
 const path = require('path');
3
 
3
 
4
 module.exports = defineConfig({
4
 module.exports = defineConfig({
5
+  publicPath: '.',
5
   transpileDependencies: true,
6
   transpileDependencies: true,
6
   chainWebpack: (config)=>{
7
   chainWebpack: (config)=>{
7
     config.resolve.alias
8
     config.resolve.alias