|
|
@ -11,14 +11,7 @@ import move_ogg from "../assets/sounds/move.ogg"; |
|
|
import grow_mp3 from "../assets/sounds/grow.mp3"; |
|
|
import grow_mp3 from "../assets/sounds/grow.mp3"; |
|
|
import grow_ogg from "../assets/sounds/grow.ogg"; |
|
|
import grow_ogg from "../assets/sounds/grow.ogg"; |
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
COL, |
|
|
|
|
|
ROW, |
|
|
|
|
|
TILE_SIZE, |
|
|
|
|
|
TILE_SPACING, |
|
|
|
|
|
TWEEN_DURATION, |
|
|
|
|
|
LOCAL_STORAGE_NAME, |
|
|
|
|
|
} from "../constant"; |
|
|
|
|
|
|
|
|
import { COL, ROW, TILE_SIZE, TILE_SPACING, TWEEN_DURATION } from "../constant"; |
|
|
|
|
|
|
|
|
class PlayScene extends Phaser.Scene { |
|
|
class PlayScene extends Phaser.Scene { |
|
|
tileArray = []; |
|
|
tileArray = []; |
|
|
@ -104,7 +97,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 设置层级,越左侧层级越高
|
|
|
// 设置层级,越左侧层级越高
|
|
|
children[i].depth = this.game.config.width - children[i].x; |
|
|
children[i].depth = this.game.config.width - children[i].x; |
|
|
} |
|
|
} |
|
|
console.log("向右"); |
|
|
|
|
|
this.move(0, 1); |
|
|
this.move(0, 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -113,7 +105,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越向右层级越高
|
|
|
// 越向右层级越高
|
|
|
children[i].depth = children[i].x; |
|
|
children[i].depth = children[i].x; |
|
|
} |
|
|
} |
|
|
console.log("向左"); |
|
|
|
|
|
this.move(0, -1); |
|
|
this.move(0, -1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -122,7 +113,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越上面层级越高
|
|
|
// 越上面层级越高
|
|
|
children[i].depth = this.game.config.height - children[i].y; |
|
|
children[i].depth = this.game.config.height - children[i].y; |
|
|
} |
|
|
} |
|
|
console.log("向下"); |
|
|
|
|
|
this.move(1, 0); |
|
|
this.move(1, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -131,7 +121,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越下面层级越高
|
|
|
// 越下面层级越高
|
|
|
children[i].depth = children[i].y; |
|
|
children[i].depth = children[i].y; |
|
|
} |
|
|
} |
|
|
console.log("向上"); |
|
|
|
|
|
this.move(-1, 0); |
|
|
this.move(-1, 0); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -148,7 +137,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越向右层级越高
|
|
|
// 越向右层级越高
|
|
|
children[i].depth = children[i].x; |
|
|
children[i].depth = children[i].x; |
|
|
} |
|
|
} |
|
|
console.log("向左"); |
|
|
|
|
|
|
|
|
|
|
|
// 行为 0,不变化,列为 -1,向左
|
|
|
// 行为 0,不变化,列为 -1,向左
|
|
|
this.move(0, -1); |
|
|
this.move(0, -1); |
|
|
@ -159,7 +147,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 设置层级,越左侧层级越高
|
|
|
// 设置层级,越左侧层级越高
|
|
|
children[i].depth = this.game.config.width - children[i].x; |
|
|
children[i].depth = this.game.config.width - children[i].x; |
|
|
} |
|
|
} |
|
|
console.log("向右"); |
|
|
|
|
|
|
|
|
|
|
|
// 行为 0,不变化,列为 1,向右
|
|
|
// 行为 0,不变化,列为 1,向右
|
|
|
this.move(0, 1); |
|
|
this.move(0, 1); |
|
|
@ -170,8 +157,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越下面层级越高
|
|
|
// 越下面层级越高
|
|
|
children[i].depth = children[i].y; |
|
|
children[i].depth = children[i].y; |
|
|
} |
|
|
} |
|
|
console.log("向上"); |
|
|
|
|
|
|
|
|
|
|
|
// 列为 0,不变化,行为 -1,向上
|
|
|
// 列为 0,不变化,行为 -1,向上
|
|
|
this.move(-1, 0); |
|
|
this.move(-1, 0); |
|
|
break; |
|
|
break; |
|
|
@ -181,7 +166,6 @@ class PlayScene extends Phaser.Scene { |
|
|
// 越上面层级越高
|
|
|
// 越上面层级越高
|
|
|
children[i].depth = this.game.config.height - children[i].y; |
|
|
children[i].depth = this.game.config.height - children[i].y; |
|
|
} |
|
|
} |
|
|
console.log("向下"); |
|
|
|
|
|
|
|
|
|
|
|
// 列为 0,不变化,行为 1,向下
|
|
|
// 列为 0,不变化,行为 1,向下
|
|
|
this.move(1, 0); |
|
|
this.move(1, 0); |
|
|
@ -338,7 +322,7 @@ class PlayScene extends Phaser.Scene { |
|
|
this.transformTile(tile, row, col); |
|
|
this.transformTile(tile, row, col); |
|
|
} |
|
|
} |
|
|
if (this.movingTiles === 0) { |
|
|
if (this.movingTiles === 0) { |
|
|
this.scoreText.setText(this.score); |
|
|
|
|
|
|
|
|
this.scoreText.text = "Game Score: " + this.score; |
|
|
this.resetTiles(); |
|
|
this.resetTiles(); |
|
|
this.addTile(); |
|
|
this.addTile(); |
|
|
} |
|
|
} |
|
|
@ -360,7 +344,7 @@ class PlayScene extends Phaser.Scene { |
|
|
onComplete: () => { |
|
|
onComplete: () => { |
|
|
this.movingTiles--; |
|
|
this.movingTiles--; |
|
|
if (this.movingTiles === 0) { |
|
|
if (this.movingTiles === 0) { |
|
|
this.scoreText.setText(this.score); |
|
|
|
|
|
|
|
|
this.scoreText.text = "Game Score: " + this.score; |
|
|
this.resetTiles(); |
|
|
this.resetTiles(); |
|
|
this.addTile(); |
|
|
this.addTile(); |
|
|
} |
|
|
} |
|
|
@ -401,44 +385,10 @@ class PlayScene extends Phaser.Scene { |
|
|
} |
|
|
} |
|
|
//设置头部
|
|
|
//设置头部
|
|
|
layout_header() { |
|
|
layout_header() { |
|
|
// 添加分数背景
|
|
|
|
|
|
this.add.sprite( |
|
|
|
|
|
this.setPosition(0, COL) + 30, |
|
|
|
|
|
this.setPosition(0, ROW) - 115, |
|
|
|
|
|
"score" |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 添加最高分数背景
|
|
|
|
|
|
this.add.sprite( |
|
|
|
|
|
this.setPosition(1, COL) + 40, |
|
|
|
|
|
this.setPosition(0, ROW) - 115, |
|
|
|
|
|
"score_best" |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 重新开始游戏
|
|
|
|
|
|
let restartButton = this.add.sprite( |
|
|
|
|
|
this.setPosition(3, COL) - 10, |
|
|
|
|
|
this.setPosition(0, ROW) - 110, |
|
|
|
|
|
"restart" |
|
|
|
|
|
); |
|
|
|
|
|
restartButton.setInteractive(); |
|
|
|
|
|
restartButton.on("pointerdown", () => { |
|
|
|
|
|
this.scene.start("PlayScene"); |
|
|
|
|
|
|
|
|
this.scoreText = this.add.text(20, 20, "", { |
|
|
|
|
|
fontSize: 20, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 分数
|
|
|
|
|
|
this.scoreText = this.add |
|
|
|
|
|
.text( |
|
|
|
|
|
this.setPosition(0, COL) + 30, |
|
|
|
|
|
this.setPosition(0, ROW) - 105, |
|
|
|
|
|
"0", |
|
|
|
|
|
{ |
|
|
|
|
|
fontFamily: "Arial", |
|
|
|
|
|
fontSize: 22, |
|
|
|
|
|
fill: "#ffffff", |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
.setOrigin(0.5); |
|
|
|
|
|
|
|
|
this.scoreText.text = "Game Score: " + this.score; |
|
|
} |
|
|
} |
|
|
//设置底部布局
|
|
|
//设置底部布局
|
|
|
layout_body() { |
|
|
layout_body() { |
|
|
|