Skip to content

Commit f7d39ba

Browse files
committedNov 10, 2017
🎛️游戏音效
1 parent f039786 commit f7d39ba

13 files changed

+153
-34
lines changed
 

‎assets/Prefab/doubleBullet.prefab

+5-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@
123123
},
124124
"_enabled": true,
125125
"speedMax": 100,
126-
"speedMin": 50
126+
"speedMin": 50,
127+
"getUfoSound": {
128+
"__uuid__": "98dfafac-8217-41d0-98a1-383e39fd8baa"
129+
}
127130
},
128131
{
129132
"__type__": "cc.PrefabInfo",
130133
"root": {
131134
"__id__": 1
132135
},
133136
"asset": {
134-
"__id__": 0
137+
"__uuid__": "77e7d1b5-05a0-4ec2-8ab1-7db6e8127ee6"
135138
},
136139
"fileId": "16HlBSYkJLE7AfLXaNEzL1",
137140
"sync": false

‎assets/Prefab/enemy1.prefab

+3
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@
174174
"speedMin": 100,
175175
"initSpriteFrame": {
176176
"__uuid__": "8dc1f52f-7d59-4d4d-8230-dc88f1215145"
177+
},
178+
"explosionSound": {
179+
"__uuid__": "a8aa203a-7f35-4e59-a7d8-8da78ded0c6b"
177180
}
178181
},
179182
{

‎assets/Prefab/enemy2.prefab

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@
168168
"speedMin": 100,
169169
"initSpriteFrame": {
170170
"__uuid__": "c01ad25e-56c2-4392-880d-29f66b2b3a19"
171+
},
172+
"explosionSound": {
173+
"__uuid__": "ea17de7d-e42b-43e2-83da-01eae170a6cf"
171174
}
172175
},
173176
{

‎assets/Prefab/enemy3.prefab

+24-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
},
2929
{
3030
"__id__": 5
31+
},
32+
{
33+
"__id__": 6
3134
}
3235
],
3336
"_prefab": {
34-
"__id__": 6
37+
"__id__": 7
3538
},
3639
"_id": "",
3740
"_opacity": 255,
@@ -184,8 +187,28 @@
184187
"speedMin": 50,
185188
"initSpriteFrame": {
186189
"__uuid__": "713dcbc2-f78b-48ea-9359-03bca0a49a2c"
190+
},
191+
"explosionSound": {
192+
"__uuid__": "bc3446db-35d9-4f7e-a710-4b29cbfa799a"
187193
}
188194
},
195+
{
196+
"__type__": "cc.AudioSource",
197+
"_name": "",
198+
"_objFlags": 0,
199+
"node": {
200+
"__id__": 1
201+
},
202+
"_enabled": true,
203+
"_clip": {
204+
"__uuid__": "3359bad6-7fb0-446f-a098-fa124ff21ffb"
205+
},
206+
"_volume": 1,
207+
"_mute": false,
208+
"_loop": true,
209+
"playOnLoad": true,
210+
"preload": false
211+
},
189212
{
190213
"__type__": "cc.PrefabInfo",
191214
"root": {

‎assets/Prefab/tnt.prefab

+5-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@
123123
},
124124
"_enabled": true,
125125
"speedMax": 100,
126-
"speedMin": 50
126+
"speedMin": 50,
127+
"getUfoSound": {
128+
"__uuid__": "88238e91-467b-4c90-a780-01cb6dad0b7a"
129+
}
127130
},
128131
{
129132
"__type__": "cc.PrefabInfo",
130133
"root": {
131134
"__id__": 1
132135
},
133136
"asset": {
134-
"__id__": 0
137+
"__uuid__": "16e85c8d-48c4-40dd-80d0-19dce321f484"
135138
},
136139
"fileId": "1cUt62gelG74kpVLOYbN0u",
137140
"sync": false

‎assets/Scene/End.fire

+3
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@
478478
},
479479
"quitBtn": {
480480
"__id__": 21
481+
},
482+
"buttonSound": {
483+
"__uuid__": "d59f69dd-03ea-46ee-a2a4-9c6b322147fa"
481484
}
482485
},
483486
{

‎assets/Scene/Game.fire

+58-26
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"_active": true,
7070
"_components": [
7171
{
72-
"__id__": 46
72+
"__id__": 47
7373
}
7474
],
7575
"_prefab": null,
@@ -191,23 +191,23 @@
191191
"__id__": 24
192192
},
193193
{
194-
"__id__": 29
194+
"__id__": 30
195195
},
196196
{
197-
"__id__": 36
197+
"__id__": 37
198198
},
199199
{
200-
"__id__": 41
200+
"__id__": 42
201201
}
202202
],
203203
"_tag": -1,
204204
"_active": true,
205205
"_components": [
206206
{
207-
"__id__": 44
207+
"__id__": 45
208208
},
209209
{
210-
"__id__": 45
210+
"__id__": 46
211211
}
212212
],
213213
"_prefab": null,
@@ -590,13 +590,25 @@
590590
"__id__": 23
591591
},
592592
"bulletGroup": {
593-
"__id__": 28
593+
"__id__": 29
594594
},
595595
"enemyGroup": {
596-
"__id__": 35
596+
"__id__": 36
597597
},
598598
"ufoGroup": {
599-
"__id__": 40
599+
"__id__": 41
600+
},
601+
"bgm": {
602+
"__uuid__": "689e6eae-521e-496b-a25a-7e72cc6d5a52"
603+
},
604+
"gameOverSound": {
605+
"__uuid__": "fcb43b7d-d415-4d14-b900-c2253d200d47"
606+
},
607+
"bombSound": {
608+
"__uuid__": "505633b6-748a-44d6-a069-fca67e259eb9"
609+
},
610+
"buttonSound": {
611+
"__uuid__": "d59f69dd-03ea-46ee-a2a4-9c6b322147fa"
600612
}
601613
},
602614
{
@@ -894,7 +906,7 @@
894906
},
895907
"_enabled": true,
896908
"bulletGroup": {
897-
"__id__": 28
909+
"__id__": 29
898910
},
899911
"mainScript": {
900912
"__id__": 14
@@ -922,6 +934,9 @@
922934
},
923935
{
924936
"__id__": 27
937+
},
938+
{
939+
"__id__": 28
925940
}
926941
],
927942
"_prefab": null,
@@ -1122,24 +1137,41 @@
11221137
}
11231138
]
11241139
},
1140+
{
1141+
"__type__": "cc.AudioSource",
1142+
"_name": "",
1143+
"_objFlags": 0,
1144+
"node": {
1145+
"__id__": 24
1146+
},
1147+
"_enabled": true,
1148+
"_volume": 1,
1149+
"_mute": false,
1150+
"_loop": false,
1151+
"playOnLoad": false,
1152+
"preload": false
1153+
},
11251154
{
11261155
"__type__": "3807dSPT35G8ZA8afVANPPV",
11271156
"_name": "",
11281157
"_objFlags": 0,
11291158
"node": {
1130-
"__id__": 29
1159+
"__id__": 30
11311160
},
11321161
"_enabled": true,
11331162
"infiniteBullet": {
1134-
"__id__": 30
1163+
"__id__": 31
11351164
},
11361165
"finiteBullet": [
11371166
{
1138-
"__id__": 32
1167+
"__id__": 33
11391168
}
11401169
],
11411170
"hero": {
11421171
"__id__": 24
1172+
},
1173+
"bulletSound": {
1174+
"__uuid__": "e8428465-8772-429a-938e-f67c4f25fc33"
11431175
}
11441176
},
11451177
{
@@ -1154,7 +1186,7 @@
11541186
"_active": true,
11551187
"_components": [
11561188
{
1157-
"__id__": 28
1189+
"__id__": 29
11581190
}
11591191
],
11601192
"_prefab": null,
@@ -1204,7 +1236,7 @@
12041236
},
12051237
"position": [
12061238
{
1207-
"__id__": 31
1239+
"__id__": 32
12081240
}
12091241
]
12101242
},
@@ -1222,10 +1254,10 @@
12221254
},
12231255
"position": [
12241256
{
1225-
"__id__": 33
1257+
"__id__": 34
12261258
},
12271259
{
1228-
"__id__": 34
1260+
"__id__": 35
12291261
}
12301262
],
12311263
"duration": 90,
@@ -1244,18 +1276,18 @@
12441276
"_name": "",
12451277
"_objFlags": 0,
12461278
"node": {
1247-
"__id__": 36
1279+
"__id__": 37
12481280
},
12491281
"_enabled": true,
12501282
"enemyGroup": [
1251-
{
1252-
"__id__": 37
1253-
},
12541283
{
12551284
"__id__": 38
12561285
},
12571286
{
12581287
"__id__": 39
1288+
},
1289+
{
1290+
"__id__": 40
12591291
}
12601292
],
12611293
"mainScript": {
@@ -1274,7 +1306,7 @@
12741306
"_active": true,
12751307
"_components": [
12761308
{
1277-
"__id__": 35
1309+
"__id__": 36
12781310
}
12791311
],
12801312
"_prefab": null,
@@ -1346,15 +1378,15 @@
13461378
"_name": "",
13471379
"_objFlags": 0,
13481380
"node": {
1349-
"__id__": 41
1381+
"__id__": 42
13501382
},
13511383
"_enabled": true,
13521384
"ufoG": [
13531385
{
1354-
"__id__": 42
1386+
"__id__": 43
13551387
},
13561388
{
1357-
"__id__": 43
1389+
"__id__": 44
13581390
}
13591391
]
13601392
},
@@ -1370,7 +1402,7 @@
13701402
"_active": true,
13711403
"_components": [
13721404
{
1373-
"__id__": 40
1405+
"__id__": 41
13741406
}
13751407
],
13761408
"_prefab": null,

‎assets/Script/End/end.js

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ cc.Class({
1717
quitBtn: {
1818
default: null,
1919
type: cc.Button,
20+
},
21+
buttonSound: {
22+
default: null,
23+
url: cc.AudioClip
2024
}
2125
},
2226

@@ -25,9 +29,11 @@ cc.Class({
2529
this.newScore.string = D.commonState.gameScore ? D.commonState.gameScore.toString() : '0';
2630
},
2731
restartGame: function () {
32+
cc.audioEngine.play(this.buttonSound);
2833
cc.director.loadScene('Game');
2934
},
3035
quitGame: function () {
36+
cc.audioEngine.play(this.buttonSound);
3137
cc.director.loadScene('Start');
3238
},
3339

‎assets/Script/Game/bulletGroup.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ cc.Class({
5252
tooltip: '有限子弹'
5353
},
5454
hero: cc.Node,
55+
bulletSound: {
56+
default: null,
57+
url: cc.AudioClip,
58+
}
5559
}),
5660

5761
onLoad: function () {
@@ -63,6 +67,7 @@ cc.Class({
6367
startAction: function () {
6468
this.startShoot = function () {
6569
this.genNewBullet(this.infiniteBullet);
70+
cc.audioEngine.play(this.bulletSound);
6671
}.bind(this);
6772
// 定时器 发射子弹的就是创建子弹对象
6873
this.schedule(this.startShoot, this.infiniteBullet.rate);
@@ -96,7 +101,8 @@ cc.Class({
96101
for (let i = 0; i < this.finiteBullet.length; i++) {
97102
if (this.finiteBullet[i].ufoBulletName === ufoBulletName) {
98103
let startDoubleShoot = function (i) {
99-
this.genNewBullet(this.finiteBullet[i])
104+
this.genNewBullet(this.finiteBullet[i]);
105+
cc.audioEngine.play(this.bulletSound);
100106
}.bind(this, i);
101107
// 设置一个延时,当一个定时器走完之后,另一个延时结束,开始执行
102108
this.schedule(startDoubleShoot, this.finiteBullet[i].rate, this.finiteBullet[i].duration);

‎assets/Script/Game/enemy.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ cc.Class({
1818
default: null,
1919
type: cc.SpriteFrame,
2020
tooltip: '初始化图像'
21-
}
21+
},
22+
explosionSound: {
23+
default: null,
24+
url: cc.AudioClip
25+
},
2226
},
2327

2428
// use this for initialization
@@ -53,6 +57,8 @@ cc.Class({
5357
}
5458
},
5559
explodingAnim: function () {
60+
// 播放爆炸音效
61+
cc.audioEngine.play(this.explosionSound);
5662
let anim = this.getComponent(cc.Animation);
5763
let animName = this.node.name + '_exploding';
5864
anim.play(animName);

‎assets/Script/Game/main.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ cc.Class({
2626
default: null,
2727
type:require('ufoGroup')
2828
},
29+
bgm: {
30+
default: null,
31+
url: cc.AudioClip
32+
},
33+
gameOverSound: {
34+
default: null,
35+
url: cc.AudioClip
36+
},
37+
bombSound: {
38+
default: null,
39+
url: cc.AudioClip
40+
},
41+
buttonSound: {
42+
default: null,
43+
url: cc.AudioClip
44+
}
2945
}),
3046

3147
// use this for initialization
@@ -34,15 +50,17 @@ cc.Class({
3450
this.enemyGroup.startAction();
3551
this.bulletGroup.startAction();
3652
this.ufoGroup.startAction();
53+
// play bgm
54+
cc.audioEngine.play(this.bgm, true);
3755
},
3856
initState: function () {
3957
D.commonState.pauseState = false;
4058
D.commonState.bombAmount = 0;
4159
D.commonState.gameScore = 0;
42-
4360
},
4461
// 暂停
4562
handlePause: function () {
63+
cc.audioEngine.play(this.buttonSound);
4664
if (D.commonState.pauseState) {
4765
this.pause.normalSprite = this.pauseSprite[0];
4866
this.pause.pressedSprite = this.pauseSprite[1];
@@ -65,6 +83,8 @@ cc.Class({
6583
// 使用tnt炸弹
6684
useBomb: function () {
6785
if (D.commonState.bombAmount > 0) {
86+
// 音效
87+
cc.audioEngine.play(this.bombSound);
6888
// 把当前的node.children 赋值给一个新的对象
6989
let enemy = new Array(...this.enemyGroup.node.children);
7090
for(let i = 0; i < enemy.length; i++) {
@@ -86,6 +106,7 @@ cc.Class({
86106
},
87107
// 游戏结束
88108
gameOver: function () {
109+
cc.audioEngine.play(this.gameOverSound);
89110
cc.director.loadScene('End');
90111
},
91112

‎assets/Script/Game/ufo.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ cc.Class({
44
properties: {
55
speedMax: 0,
66
speedMin: 0,
7+
getUfoSound: {
8+
default: null,
9+
url: cc.AudioClip
10+
}
711
},
812

913
// use this for initialization
@@ -16,6 +20,7 @@ cc.Class({
1620
},
1721
//碰撞检测
1822
onCollisionEnter: function(other, self){
23+
cc.audioEngine.play(this.getUfoSound);
1924
this.ufoGroup.destroyUfo(this.node);
2025
},
2126
// called every frame, uncomment this function to activate update callback

‎assets/Script/Start/start.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ cc.Class({
99
startButton: {
1010
default: null,
1111
type: cc.Button
12+
},
13+
buttonSound: {
14+
default: null,
15+
url: cc.AudioClip
1216
}
1317
},
1418

@@ -20,6 +24,7 @@ cc.Class({
2024
},
2125

2226
startGame: function () {
27+
cc.audioEngine.play(this.buttonSound);
2328
// 转场
2429
cc.director.loadScene('Game');
2530
}

0 commit comments

Comments
 (0)
Please sign in to comment.