mirror of
https://github.com/tiennm99/nntv.git
synced 2026-10-16 08:15:26 +00:00
fix: close poup after replay
This commit is contained in:
1 parent
67cc6d64b7
commit
a062ade3c7
3 files changed
+36
-9
No files matched your search
@@ -20,7 +20,7 @@ export class LevelManager {
|
||||
|
||||
// Cập nhật UI
|
||||
this.scene.levelText.setText(`Level: ${levelId}`);
|
||||
|
||||
|
||||
// Xóa các trạm gác hiện tại
|
||||
if (this.scene.guards) {
|
||||
this.scene.guards.forEach(guard => {
|
||||
@@ -36,17 +36,17 @@ export class LevelManager {
|
||||
if (gridSize !== this.scene.gridSize) {
|
||||
this.scene.gridSize = gridSize;
|
||||
this.scene.grid.resize(gridSize, gridSize);
|
||||
|
||||
|
||||
// Tính toán lại vị trí lưới để căn giữa
|
||||
const width = this.scene.cameras.main.width;
|
||||
const height = this.scene.cameras.main.height;
|
||||
this.scene.gridOffsetX = (width - (gridSize * this.scene.cellSize)) / 2;
|
||||
this.scene.gridOffsetY = (height - (gridSize * this.scene.cellSize)) / 2;
|
||||
|
||||
|
||||
// Cập nhật vị trí của graphics
|
||||
this.scene.grid.graphics.x = this.scene.gridOffsetX;
|
||||
this.scene.grid.graphics.y = this.scene.gridOffsetY;
|
||||
|
||||
|
||||
if (this.scene.lightSystem) {
|
||||
this.scene.lightSystem.graphics.x = this.scene.gridOffsetX;
|
||||
this.scene.lightSystem.graphics.y = this.scene.gridOffsetY;
|
||||
@@ -76,7 +76,8 @@ export class LevelManager {
|
||||
|
||||
// Thiết lập vị trí người chơi
|
||||
if (levelData.player) {
|
||||
this.scene.player.moveTo(levelData.player.row, levelData.player.col);
|
||||
// Sử dụng skipDetectionCheck = true để tránh kiểm tra phát hiện khi tải lại màn chơi
|
||||
this.scene.player.moveTo(levelData.player.row, levelData.player.col, true);
|
||||
}
|
||||
|
||||
// Thiết lập các ô sáng cố định (nếu có)
|
||||
@@ -90,7 +91,7 @@ export class LevelManager {
|
||||
if (levelData.guards) {
|
||||
levelData.guards.forEach(guardData => {
|
||||
let guard = null;
|
||||
|
||||
|
||||
switch (guardData.type) {
|
||||
case 'static':
|
||||
guard = new this.scene.StaticGuard(
|
||||
@@ -130,7 +131,7 @@ export class LevelManager {
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (guard) {
|
||||
this.scene.guards.push(guard);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class Player {
|
||||
}
|
||||
|
||||
// Di chuyển đến vị trí mới
|
||||
moveTo(row, col) {
|
||||
moveTo(row, col, skipDetectionCheck = false) {
|
||||
// Kiểm tra vị trí hợp lệ và không phải là tường
|
||||
if (!this.grid.isValidPosition(row, col) || this.grid.isWall(row, col)) {
|
||||
return false;
|
||||
@@ -45,7 +45,8 @@ export class Player {
|
||||
ease: 'Linear',
|
||||
onComplete: () => {
|
||||
// Kiểm tra xem người chơi có đang ở ô sáng không sau khi di chuyển
|
||||
if (this.isInLitCell()) {
|
||||
// Bỏ qua kiểm tra nếu skipDetectionCheck = true (khi đang tải lại màn chơi)
|
||||
if (!skipDetectionCheck && this.isInLitCell()) {
|
||||
// Người chơi bị phát hiện
|
||||
this.scene.showDetectionPopup();
|
||||
}
|
||||
|
||||
@@ -376,6 +376,11 @@ export class Game extends Phaser.Scene {
|
||||
|
||||
// Hiển thị popup khi người chơi bị phát hiện
|
||||
showDetectionPopup() {
|
||||
// Kiểm tra xem popup đã tồn tại chưa, nếu có thì không tạo mới
|
||||
if (this.detectionPopup) {
|
||||
return; // Đã có popup, không tạo thêm
|
||||
}
|
||||
|
||||
const width = this.cameras.main.width;
|
||||
const height = this.cameras.main.height;
|
||||
|
||||
@@ -386,9 +391,11 @@ export class Game extends Phaser.Scene {
|
||||
// Tạo container cho popup
|
||||
this.detectionPopup = this.add.container(width / 2, height / 2);
|
||||
this.detectionPopup.setDepth(100);
|
||||
this.detectionPopup.popup = 'detection'; // Đánh dấu container
|
||||
|
||||
// Background
|
||||
const bg = this.add.rectangle(0, 0, 300, 200, 0x000000, 0.8);
|
||||
bg.popup = 'detection'; // Đánh dấu phần tử thuộc về popup
|
||||
|
||||
// Thông báo
|
||||
const title = this.add.text(0, -60, 'Bạn đã bị phát hiện!', {
|
||||
@@ -396,14 +403,18 @@ export class Game extends Phaser.Scene {
|
||||
fill: '#FF0000'
|
||||
});
|
||||
title.setOrigin(0.5, 0.5);
|
||||
title.popup = 'detection'; // Đánh dấu phần tử thuộc về popup
|
||||
|
||||
// Nút chơi lại
|
||||
const restartButton = this.add.rectangle(0, 20, 200, 40, 0x444444);
|
||||
restartButton.popup = 'detection'; // Đánh dấu phần tử thuộc về popup
|
||||
|
||||
const restartText = this.add.text(0, 20, 'CHƠI LẠI', {
|
||||
font: '20px Arial',
|
||||
fill: '#ffffff'
|
||||
});
|
||||
restartText.setOrigin(0.5, 0.5);
|
||||
restartText.popup = 'detection'; // Đánh dấu phần tử thuộc về popup
|
||||
|
||||
// Thêm các phần tử vào container
|
||||
this.detectionPopup.add([bg, title, restartButton, restartText]);
|
||||
@@ -421,10 +432,19 @@ export class Game extends Phaser.Scene {
|
||||
// Đóng popup phát hiện
|
||||
closeDetectionPopup() {
|
||||
if (this.detectionPopup) {
|
||||
// Đảm bảo tất cả các phần tử con cũng được hủy
|
||||
this.detectionPopup.removeAll(true);
|
||||
this.detectionPopup.destroy();
|
||||
this.detectionPopup = null;
|
||||
this.isPaused = false;
|
||||
this.inputEnabled = true;
|
||||
|
||||
// Đảm bảo rằng tất cả các phần tử liên quan đến popup đã được xóa
|
||||
this.children.list.forEach(child => {
|
||||
if (child.popup && child.popup === 'detection') {
|
||||
child.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,6 +457,11 @@ export class Game extends Phaser.Scene {
|
||||
this.livesText.setText(`Lives: ${this.livesRemaining}`);
|
||||
}
|
||||
|
||||
// Đảm bảo tất cả các popup đã được đóng
|
||||
if (this.detectionPopup) {
|
||||
this.closeDetectionPopup();
|
||||
}
|
||||
|
||||
if (this.livesRemaining <= 0) {
|
||||
// Hết mạng, game over
|
||||
this.scene.start('GameOver', {
|
||||
|
||||
Reference in new issue
Block a user