Browse Source

游戏:小鸟飞,输入验证码后,加“3 2 1 开始”显示

游戏:同色消除,再来一次,分数没有初始化,会出现moves:-X分
master
jiannibang 6 years ago
parent
commit
6186f4af26
  1. 36
      games/game-flipbird/scenes/flipbird/flipbird.js
  2. 2
      games/game-flood-fill/scenes/PlayScene.js

36
games/game-flipbird/scenes/flipbird/flipbird.js

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

2
games/game-flood-fill/scenes/PlayScene.js

@ -57,7 +57,7 @@ class PlayScene extends Phaser.Scene {
this.createIcon(3, 1080 - 184, 272); this.createIcon(3, 1080 - 184, 272);
this.createIcon(4, 1080 - 184, 272 + 252); this.createIcon(4, 1080 - 184, 272 + 252);
this.createIcon(5, 1080 - 184, 272 + 252 * 2); this.createIcon(5, 1080 - 184, 272 + 252 * 2);
this.moves = 25;
// The game is played in a 14x14 grid with 6 different colors // The game is played in a 14x14 grid with 6 different colors
this.grid = []; this.grid = [];

Loading…
Cancel
Save