Skip to content

Commit 8a748e0

Browse files
committed
completed game
1 parent 0578318 commit 8a748e0

File tree

4 files changed

+129
-86
lines changed

4 files changed

+129
-86
lines changed

assets/sounds/bgm-07.mp3

215 KB
Binary file not shown.

src/Public/jonny/game23/Basin.ts

+22-31
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Basin extends Phaser.GameObjects.Container {
1818
}
1919

2020
/**
21-
* 淡出
21+
* 淡入
2222
*/
2323
public show():Promise<number>{
2424
return new Promise(resolve=>{
@@ -27,45 +27,48 @@ export class Basin extends Phaser.GameObjects.Container {
2727
alpha:1,
2828
duration:500,
2929
onComplete:()=>{
30-
this.audioPlay(this.name + "Sound");
3130
resolve(1);
3231
}
3332
})
3433
})
3534
}
3635

3736
/**
38-
* 移动到左边
37+
* 淡出
3938
*/
40-
public moveLeft():Promise<number>{
39+
public hide():Promise<number>{
4140
return new Promise(resolve=>{
4241
this.scene.add.tween({
4342
targets:this,
44-
x:91,
43+
alpha:0,
44+
scale:0,
4545
duration:500,
46-
ease:"Sine.easeOut",
4746
onComplete:()=>{
4847
resolve(1);
4948
}
5049
})
51-
})
50+
})
51+
}
52+
53+
/**
54+
* 移动到左边
55+
*/
56+
public moveLeft():Promise<number>{
57+
return this.move(91);
5258
}
5359

5460
/**
5561
* 移动到右边
5662
*/
5763
public moveRight():Promise<number>{
58-
return new Promise(resolve=>{
59-
this.scene.add.tween({
60-
targets:this,
61-
x:761,
62-
duration:500,
63-
ease:"Sine.easeOut",
64-
onComplete:()=>{
65-
resolve(1);
66-
}
67-
})
68-
})
64+
return this.move(761);
65+
}
66+
67+
/**
68+
* 移动到中间
69+
*/
70+
public moveCenter():Promise<number>{
71+
return this.move(492);
6972
}
7073

7174
/**
@@ -85,18 +88,6 @@ export class Basin extends Phaser.GameObjects.Container {
8588
})
8689
}
8790

88-
/**
89-
* 单次播放的音频播放器
90-
*/
91-
private audioPlay(key: string): Promise<number> {
92-
return new Promise<number>(resolve => {
93-
let _tempSound: Phaser.Sound.BaseSound = this.scene.sound.add(key);
94-
_tempSound.on("complete", function (this: Phaser.Sound.BaseSound) {
95-
this.destroy();
96-
resolve(1);
97-
});
98-
_tempSound.play();
99-
})
100-
}
91+
10192

10293
}

src/scenes/Game23/Load.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { get } from '../../lib/http';
99
import { resize } from '../../Public/jonny/core';
1010
import { Game23Data,Assets } from '../../interface/Game23';
1111
import { SellingGold, Particles } from '../../Public/jonny/components';
12+
import TipsParticlesEmitter from '../../Public/TipsParticlesEmitter';
1213

1314
const W = 1024;
1415
const H = 552;
@@ -49,11 +50,15 @@ export default class Game16LoadScene extends Phaser.Scene {
4950
}
5051

5152
preload(): void {
52-
this.load.audio('bgm', 'assets/sounds/bgm-06.mp3');
53+
this.load.audio('bgm', 'assets/sounds/bgm-07.mp3');
5354
this.load.audio('successMp3', 'assets/sounds/successMp3.mp3');
55+
this.load.audio('clickMp3', 'assets/sounds/clickMp3.mp3');
5456
this.load.audio('failMp3', 'assets/sounds/failMp3.mp3');
57+
this.load.audio('right', 'assets/sounds/newJoin/right.mp3');
58+
this.load.audio('wrong', 'assets/sounds/newJoin/wrong.mp3');
5559
SellingGold.loadImg(this);
5660
Particles.loadImg(this);
61+
TipsParticlesEmitter.loadImg(this);
5762
this.assets.forEach((v) => {
5863
this.load.image(v.key, v.url);
5964
})

src/scenes/Game23/Play.ts

+101-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'phaser';
22
import { } from 'rxjs';
3-
import { cover, rotateTips, isHit, Vec2, CONSTANT ,arrDisorder} from '../../Public/jonny/core';
3+
import { cover, rotateTips, isHit, Vec2, CONSTANT, arrDisorder } from '../../Public/jonny/core';
44
import { Button, ButtonMusic, ButtonExit, SellingGold, Gold, SuccessBtn, TryAginListenBtn } from '../../Public/jonny/components';
55
import { Game23Data, Assets } from '../../interface/Game23';
66
import { Basin } from "../../Public/jonny/game23/Basin";
@@ -18,7 +18,7 @@ var goldValue: number = 3; //金币的值
1818

1919
export default class Game23PlayScene extends Phaser.Scene {
2020
private ccData: Array<Game23Data> = [];
21-
private rightTimes:number = 0; //正确的次数
21+
private rightTimes: number = 0; //正确的次数
2222
private times: number = 0; //次数
2323

2424
//静态开始
@@ -31,9 +31,9 @@ export default class Game23PlayScene extends Phaser.Scene {
3131
//静态结束
3232

3333
//动态开始
34-
private toys:Array<Toy> = []; //玩具
35-
private basins:Array<Basin> = []; //盆
36-
private civa:Shooter;
34+
private toys: Array<Toy> = []; //玩具
35+
private basins: Array<Basin> = []; //盆
36+
private civa: Shooter;
3737
private tipsParticlesEmitter: TipsParticlesEmitter;
3838
private sellingGold: SellingGold;
3939

@@ -169,21 +169,22 @@ export default class Game23PlayScene extends Phaser.Scene {
169169
let offsetY = 337 - 145;
170170
let ccDataClone = this.ccData.concat(this.ccData);
171171
ccDataClone = arrDisorder(ccDataClone);
172-
ccDataClone.forEach((v,i)=>{
172+
ccDataClone.forEach((v, i) => {
173173
let initX = 136;
174174
let initY = 145;
175-
let _ix = i%5;
176-
let _iy = Math.floor(i/5);
177-
let x = initX + offsetX*_ix;
178-
let y = initY + offsetY*_iy;
179-
let toy = new Toy(this,x,y,v.questionContent,v.questionContent).init();
175+
let _ix = i % 5;
176+
let _iy = Math.floor(i / 5);
177+
let x = initX + offsetX * _ix;
178+
let y = initY + offsetY * _iy;
179+
let toy = new Toy(this, x, y, v.questionContent, v.questionContent).init();
180180
this.toys.push(toy);
181181
this.layer1.add(toy);
182182
});
183183

184184
//创建盆
185-
this.ccData.forEach((v,i)=>{
186-
let basin = new Basin(this,v.questionContent).init();
185+
console.log(index);
186+
this.ccData.forEach((v, i) => {
187+
let basin = new Basin(this, v.questionContent).init();
187188
this.basins.push(basin);
188189
this.layer2.add(basin);
189190
})
@@ -197,51 +198,102 @@ export default class Game23PlayScene extends Phaser.Scene {
197198
*/
198199
private async gameStart() {
199200
let that = this;
200-
let toyPointerDown = function (toy:Toy){
201+
let toyPointerDown = function (toy: Toy) {
201202
this.checkoutResult(toy)
202-
.then(async value => { //正确
203-
console.log(value);
204-
that.rightTimes+=value;
205-
if(value===1&&that.rightTimes===1){
206-
toy.disableInteractive();
207-
that.audioPlay("successMp3");
208-
await that.basins[index].move(toy.x);
209-
that.audioPlay(toy.name + "Sound");
210-
toy.isRight(that.rightTimes,that.basins[index]);
211-
}else if(value===1&&that.rightTimes===2){
212-
toy.disableInteractive();
213-
that.audioPlay("successMp3");
214-
await that.basins[index].move(toy.x);
215-
that.audioPlay(toy.name + "Sound");
216-
toy.isRight(that.rightTimes,that.basins[index]);
217-
}else if(value===0){
218-
toy.isWrong();
219-
}
220-
})
203+
.then(async (value: number) => { //正确
204+
console.log(value);
205+
that.rightTimes += value;
206+
that.disableToys(true);
207+
if (value === 1 && that.rightTimes === 1) { //当回答正确,且射击次数为1
208+
//toy.disableInteractive();
209+
//that.disableToys(true);
210+
that.audioPlay("successMp3");
211+
await that.basins[index].move(toy.x);
212+
that.audioPlay(toy.name + "Sound");
213+
await toy.isRight(that.rightTimes, that.basins[index]);
214+
that.disableToys(false);
215+
} else if (value === 1 && that.rightTimes === 2) { //当回答正确,且射击次数为2
216+
//that.disableToys(true);
217+
that.audioPlay("successMp3");
218+
await that.basins[index].move(toy.x);
219+
that.audioPlay(toy.name + "Sound");
220+
await toy.isRight(that.rightTimes, that.basins[index]);
221+
await that.basins[index].moveLeft();
222+
console.log(index);
223+
if (index === 2 || index === 3) {
224+
await that.basins[index].moveRight();
225+
} else if (index === 4) {
226+
await that.basins[index].moveCenter();
227+
}
228+
that.isRight();
229+
} else if (value === 0) {
230+
await toy.isWrong();
231+
that.isWrong();
232+
}
233+
})
221234
}
222235

223-
let toyShow:Promise<number>[] = this.toys.map((toy,i)=>{
224-
let delay = 300*i;
225-
toy.on("pointerdown",toyPointerDown.bind(this,toy));
236+
let toyShow: Promise<number>[] = this.toys.map((toy, i) => {
237+
let delay = 300 * i;
238+
toy.on("pointerdown", toyPointerDown.bind(this, toy));
226239
return toy.show(delay);
227240
})
228241

229242
await Promise.all(toyShow);
230243
this.basins[index].show();
244+
this.audioPlay(this.basins[index].name + "Sound");
245+
//this.nextTopic();
246+
}
247+
248+
/**
249+
* 激活或禁止所有玩具的输入事件
250+
*/
251+
private disableToys(yes: boolean) {
252+
if (yes) {
253+
this.toys.forEach(toy => {
254+
toy.disableInteractive();
255+
});
256+
} else if (!yes) {
257+
this.toys.forEach(toy => {
258+
toy.setInteractive();
259+
});
260+
}
261+
262+
}
263+
264+
/**
265+
* 下一题
266+
*/
267+
private nextTopic() {
268+
console.log(index);
269+
index += 1;
270+
if (index > this.ccData.length - 1) {
271+
window.location.href = CONSTANT.INDEX_URL;
272+
}
273+
this.rightTimes = 0;
274+
this.disableToys(false)
275+
this.basins[index].show();
276+
this.audioPlay(this.basins[index].name + "Sound");
277+
}
231278

232-
279+
/**
280+
* 换一道题
281+
*/
282+
private async changeTopic() {
283+
await this.basins[index].hide();
284+
this.nextTopic();
233285
}
234286

235287
/**
236288
* 判断做题结果是否正确
237289
*/
238-
private checkoutResult(toy:Toy): Promise<number> {
239-
let answer:boolean = toy.name === this.basins[index].name;
240-
console.log(toy.name,this.basins[index].name);
290+
private checkoutResult(toy: Toy): Promise<number> {
291+
let answer: boolean = toy.name === this.basins[index].name;
292+
console.log(toy.name, this.basins[index].name);
241293
return new Promise(resolve => {
242-
if(answer){
294+
if (answer) {
243295
resolve(1);
244-
}else{
296+
} else {
245297
resolve(0);
246298
}
247299
});
@@ -286,10 +338,6 @@ export default class Game23PlayScene extends Phaser.Scene {
286338

287339
}
288340

289-
290-
291-
292-
293341
/**
294342
* 正确的结果处理
295343
*/
@@ -299,14 +347,16 @@ export default class Game23PlayScene extends Phaser.Scene {
299347
callback: () => {
300348
this.sellingGold.golds.destroy();
301349
this.setGoldValue(3);
302-
this.nextRound();
350+
;
351+
this.nextTopic();
303352
}
304353
});
305354
this.sellingGold.golds.setDepth(6);
306355
this.tipsParticlesEmitter.success(() => {
307356
this.sellingGold.goodJob(3);
308357
})
309358
}
359+
nextFuc();
310360
}
311361

312362
/**
@@ -332,9 +382,7 @@ export default class Game23PlayScene extends Phaser.Scene {
332382
* 重置开始状态
333383
*/
334384
private resetStart() {
335-
336-
this.successBtn.setAlpha(0);
337-
this.successBtn.interactive = true;
385+
this.disableToys(false);
338386
}
339387

340388
/**
@@ -343,7 +391,7 @@ export default class Game23PlayScene extends Phaser.Scene {
343391
private ohNo() {
344392
this.setGoldValue(-1);
345393
this.tipsParticlesEmitter.error(
346-
this.nextRound,
394+
this.changeTopic,
347395
this.resetStart
348396
)
349397
if (goldValue === 0) {
@@ -358,7 +406,7 @@ export default class Game23PlayScene extends Phaser.Scene {
358406
* 下一道题
359407
*/
360408
private nextRound(): void {
361-
index += 1;
409+
//index += 1;
362410
if (index > this.ccData.length - 1) {
363411
window.location.href = CONSTANT.INDEX_URL;
364412
}
@@ -369,14 +417,13 @@ export default class Game23PlayScene extends Phaser.Scene {
369417
});
370418
}
371419

372-
420+
373421

374422
/**
375423
* 设置金币的动作
376424
*/
377425
private setGoldValue(value: number) {
378426
goldValue += value;
379-
380427
this.gold.setText(goldValue);
381428
}
382429

0 commit comments

Comments
 (0)