|
|
|
@ -12,6 +12,7 @@ import bg from "../../assets/flipbird/bg.png"; |
|
|
|
*/ |
|
|
|
const getRandomPipe = () => |
|
|
|
["pipe1", "pipe2", "pipe3"][Math.floor(Math.random() * 3)]; |
|
|
|
const wait1s = () => new Promise((resolve) => setTimeout(resolve, 1000)); |
|
|
|
export default class PlayScene extends Phaser.Scene { |
|
|
|
constructor() { |
|
|
|
super({ key: "flipbird" }); |
|
|
|
@ -50,7 +51,7 @@ export default class PlayScene extends Phaser.Scene { |
|
|
|
frameHeight: 392, |
|
|
|
}); |
|
|
|
} |
|
|
|
create() { |
|
|
|
async create() { |
|
|
|
// this.game.physics.startSystem(Phaser.Physics.P2JS);
|
|
|
|
this.bg = this.add.image( |
|
|
|
this.game.config.width / 2, |
|
|
|
@ -74,7 +75,6 @@ export default class PlayScene extends Phaser.Scene { |
|
|
|
this.pipePool.push(p2); |
|
|
|
this.placePipes(false); |
|
|
|
} |
|
|
|
this.pipeGroup.setVelocityX(-this.gameOptions.birdSpeed); |
|
|
|
this.bird = this.physics.add.sprite( |
|
|
|
150, |
|
|
|
this.game.config.height / 2, |
|
|
|
@ -83,20 +83,46 @@ export default class PlayScene extends Phaser.Scene { |
|
|
|
this.bird.body.setCircle(342 / 2, 0, 25); |
|
|
|
this.bird.setScale(0.5); |
|
|
|
|
|
|
|
this.bird.body.gravity.y = this.gameOptions.birdGravity; |
|
|
|
|
|
|
|
this.anims.create({ |
|
|
|
key: "fly", |
|
|
|
frames: this.anims.generateFrameNumbers("bird", { start: 0, end: 3 }), |
|
|
|
frameRate: 10, |
|
|
|
repeat: -1, |
|
|
|
}); |
|
|
|
this.input.on("pointerdown", this.flap, this); |
|
|
|
|
|
|
|
this.score = 0; |
|
|
|
this.scoreText1 = this.add.text(20, 20, "", { |
|
|
|
fontSize: 20, |
|
|
|
}); |
|
|
|
this.updateScore(this.score); |
|
|
|
this.countDownWrapper = this.add.rectangle( |
|
|
|
this.game.config.width / 2, |
|
|
|
this.game.config.height / 2, |
|
|
|
this.game.config.width, |
|
|
|
this.game.config.height, |
|
|
|
0x000000, |
|
|
|
0.6 |
|
|
|
); |
|
|
|
this.countDown = this.add.text( |
|
|
|
this.game.config.width / 2, |
|
|
|
this.game.config.height / 2, |
|
|
|
"3", |
|
|
|
{ |
|
|
|
fontSize: 110, |
|
|
|
textAlign: "center", |
|
|
|
baseLine: "middle", |
|
|
|
} |
|
|
|
); |
|
|
|
await wait1s(); |
|
|
|
this.countDown.text = 2; |
|
|
|
await wait1s(); |
|
|
|
this.countDown.text = 1; |
|
|
|
await wait1s(); |
|
|
|
this.countDown.destroy(); |
|
|
|
this.countDownWrapper.destroy(); |
|
|
|
this.input.on("pointerdown", this.flap, this); |
|
|
|
this.pipeGroup.setVelocityX(-this.gameOptions.birdSpeed); |
|
|
|
this.bird.body.gravity.y = this.gameOptions.birdGravity; |
|
|
|
} |
|
|
|
updateScore(inc) { |
|
|
|
this.score += inc; |
|
|
|
|