|
|
@ -64,6 +64,7 @@ class PlayScene extends Phaser.Scene { |
|
|
platform.setImmovable(true); |
|
|
platform.setImmovable(true); |
|
|
platform.displayWidth = blockWidth; |
|
|
platform.displayWidth = blockWidth; |
|
|
platform.displayHeight = blockHeight; |
|
|
platform.displayHeight = blockHeight; |
|
|
|
|
|
platform.body.checkCollision.left = true; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
@ -82,23 +83,22 @@ class PlayScene extends Phaser.Scene { |
|
|
platform.setImmovable(true); |
|
|
platform.setImmovable(true); |
|
|
platform.displayWidth = blockWidth; |
|
|
platform.displayWidth = blockWidth; |
|
|
platform.displayHeight = blockHeight; |
|
|
platform.displayHeight = blockHeight; |
|
|
|
|
|
|
|
|
const number = Math.floor(Math.random() * 3 + 1); |
|
|
const number = Math.floor(Math.random() * 3 + 1); |
|
|
platform.name = number; |
|
|
platform.name = number; |
|
|
|
|
|
if (number === 2 || number === 1) platform.body.checkCollision.left = true; |
|
|
this.attachSidekick(platform, number); |
|
|
this.attachSidekick(platform, number); |
|
|
} |
|
|
} |
|
|
create() { |
|
|
create() { |
|
|
|
|
|
this.physics.world.setFPS(30); |
|
|
this.platformGroup = this.physics.add.group(); |
|
|
this.platformGroup = this.physics.add.group(); |
|
|
this.bgGroup = this.physics.add.group(); |
|
|
|
|
|
for (let i = 0; i < 2; i++) { |
|
|
|
|
|
let bg = this.bgGroup.create( |
|
|
|
|
|
this.game.config.width * (i + 1 / 2), |
|
|
|
|
|
this.game.config.height / 2, |
|
|
|
|
|
"bg" |
|
|
|
|
|
); |
|
|
|
|
|
bg.setImmovable(true); |
|
|
|
|
|
bg.displayWidth = this.game.config.width; |
|
|
|
|
|
bg.displayHeight = this.game.config.height; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const bg = this.add.image( |
|
|
|
|
|
this.game.config.width / 2, |
|
|
|
|
|
this.game.config.height / 2, |
|
|
|
|
|
"bg" |
|
|
|
|
|
); |
|
|
|
|
|
bg.displayWidth = this.game.config.width; |
|
|
|
|
|
bg.displayHeight = this.game.config.height; |
|
|
this.ball = this.physics.add.sprite( |
|
|
this.ball = this.physics.add.sprite( |
|
|
this.game.config.width * gameOptions.ballPosition, |
|
|
this.game.config.width * gameOptions.ballPosition, |
|
|
(this.game.config.height / 4) * 3 - gameOptions.bounceHeight, |
|
|
(this.game.config.height / 4) * 3 - gameOptions.bounceHeight, |
|
|
@ -109,16 +109,16 @@ class PlayScene extends Phaser.Scene { |
|
|
this.ball.body.checkCollision.down = true; |
|
|
this.ball.body.checkCollision.down = true; |
|
|
this.ball.body.checkCollision.up = false; |
|
|
this.ball.body.checkCollision.up = false; |
|
|
this.ball.body.checkCollision.left = false; |
|
|
this.ball.body.checkCollision.left = false; |
|
|
this.ball.body.checkCollision.right = false; |
|
|
|
|
|
|
|
|
this.ball.body.checkCollision.right = true; |
|
|
this.ball.displayWidth = 120; |
|
|
this.ball.displayWidth = 120; |
|
|
this.ball.displayHeight = 120; |
|
|
this.ball.displayHeight = 120; |
|
|
this.ball.setSize(160, 250, true); |
|
|
this.ball.setSize(160, 250, true); |
|
|
// this.ball.setScale(0.5);
|
|
|
// this.ball.setScale(0.5);
|
|
|
let platformX = this.ball.x; |
|
|
|
|
|
|
|
|
this.platformX = this.ball.x; |
|
|
|
|
|
|
|
|
for (let i = 0; i < 4; i++) { |
|
|
for (let i = 0; i < 4; i++) { |
|
|
this.newPlatForm(platformX); |
|
|
|
|
|
platformX += Phaser.Math.Between( |
|
|
|
|
|
|
|
|
this.newPlatForm(this.platformX); |
|
|
|
|
|
this.platformX += Phaser.Math.Between( |
|
|
gameOptions.platformDistanceRange[0], |
|
|
gameOptions.platformDistanceRange[0], |
|
|
gameOptions.platformDistanceRange[1] |
|
|
gameOptions.platformDistanceRange[1] |
|
|
); |
|
|
); |
|
|
@ -137,19 +137,20 @@ class PlayScene extends Phaser.Scene { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
movePlatforms() { |
|
|
movePlatforms() { |
|
|
// this.bgGroup.setVelocityX(-gameOptions.platformSpeed * 0.5);
|
|
|
|
|
|
this.platformGroup.setVelocityX(-gameOptions.platformSpeed); |
|
|
this.platformGroup.setVelocityX(-gameOptions.platformSpeed); |
|
|
} |
|
|
} |
|
|
stopPlatforms() { |
|
|
stopPlatforms() { |
|
|
this.bgGroup.setVelocityX(0); |
|
|
|
|
|
this.platformGroup.setVelocityX(0); |
|
|
this.platformGroup.setVelocityX(0); |
|
|
} |
|
|
} |
|
|
getRightmostPlatform() { |
|
|
getRightmostPlatform() { |
|
|
let rightmostPlatform = 0; |
|
|
|
|
|
this.platformGroup.getChildren().forEach((platform) => { |
|
|
|
|
|
rightmostPlatform = Math.max(rightmostPlatform, platform.x); |
|
|
|
|
|
}); |
|
|
|
|
|
return rightmostPlatform; |
|
|
|
|
|
|
|
|
return this.platformGroup |
|
|
|
|
|
.getChildren() |
|
|
|
|
|
.filter(({ name }) => name) |
|
|
|
|
|
.reduce( |
|
|
|
|
|
(rightmostPlatform, platform) => |
|
|
|
|
|
Math.max(rightmostPlatform, platform.x), |
|
|
|
|
|
0 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
update() { |
|
|
update() { |
|
|
const result = this.physics.world.collide(this.platformGroup, this.ball); |
|
|
const result = this.physics.world.collide(this.platformGroup, this.ball); |
|
|
@ -164,26 +165,21 @@ class PlayScene extends Phaser.Scene { |
|
|
children.forEach((platform) => { |
|
|
children.forEach((platform) => { |
|
|
if (platform.getBounds().right < 0) { |
|
|
if (platform.getBounds().right < 0) { |
|
|
if (platform.name) { |
|
|
if (platform.name) { |
|
|
this.updateScore(1); |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
this.newPlatForm( |
|
|
|
|
|
this.getRightmostPlatform() - |
|
|
|
|
|
Number(platform.name) * blockWidth + |
|
|
|
|
|
Phaser.Math.Between( |
|
|
|
|
|
gameOptions.platformDistanceRange[0], |
|
|
|
|
|
gameOptions.platformDistanceRange[1] |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
this.updateScore(3 - Number(platform.name)); |
|
|
|
|
|
this.stopPlatforms(); |
|
|
|
|
|
const platformX = |
|
|
|
|
|
this.getRightmostPlatform() + |
|
|
|
|
|
Phaser.Math.Between( |
|
|
|
|
|
gameOptions.platformDistanceRange[0], |
|
|
|
|
|
gameOptions.platformDistanceRange[1] |
|
|
); |
|
|
); |
|
|
}); |
|
|
|
|
|
|
|
|
this.newPlatForm(platformX); |
|
|
|
|
|
this.movePlatforms(); |
|
|
} |
|
|
} |
|
|
this.platformGroup.remove(platform, true, true); |
|
|
this.platformGroup.remove(platform, true, true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
this.bgGroup.getChildren().forEach((bg) => { |
|
|
|
|
|
if (bg.getBounds().right < 0) { |
|
|
|
|
|
bg.x += this.game.config.width * 2; |
|
|
|
|
|
} |
|
|
|
|
|
}, this); |
|
|
|
|
|
|
|
|
|
|
|
if (this.ball.y > this.game.config.height) { |
|
|
if (this.ball.y > this.game.config.height) { |
|
|
this.game.onLose && this.game.onLose(); |
|
|
this.game.onLose && this.game.onLose(); |
|
|
this.scene.pause(); |
|
|
this.scene.pause(); |
|
|
|