|
@@ -632,6 +632,11 @@ class GameScene extends Phaser.Scene {
|
|
|
this.isShooting = true;
|
|
|
this.shootTimeLeft = 15; // 重置剩余时间
|
|
|
|
|
|
+ // 隐藏原玩家角色(关键修改)
|
|
|
+ if (this.player) {
|
|
|
+ this.player.visible = false; // 隐藏奔跑状态的玩家
|
|
|
+ }
|
|
|
+
|
|
|
// 暂停计分定时器
|
|
|
if (this.timer) {
|
|
|
this.timer.paused = true;
|
|
@@ -682,14 +687,20 @@ class GameScene extends Phaser.Scene {
|
|
|
});
|
|
|
|
|
|
// 调整球员位置(准备射门)
|
|
|
- this.player.setPosition(clientObj.value.width / 2, clientObj.value.height - 100);
|
|
|
- this.player.setTexture('playerShoot');
|
|
|
- this.player.setVelocity(0);
|
|
|
+ // this.player.setPosition(clientObj.value.width / 2, clientObj.value.height - 100);
|
|
|
+ // this.player.setTexture('playerShoot');
|
|
|
+ // this.player.setVelocity(0);
|
|
|
+
|
|
|
+
|
|
|
+ //射门员
|
|
|
+ this.playerShoot = this.physics.add.sprite(clientObj.value.width / 2, clientObj.value.height - 100, 'playerShoot');
|
|
|
+ this.playerShoot.setScale(2);
|
|
|
+ this.playerShoot.setDepth(9); // 确保在合理层级
|
|
|
|
|
|
// 创建足球
|
|
|
- this.ball = this.physics.add.sprite(this.player.x, this.player.y - 50, 'ballAnim');
|
|
|
+ this.ball = this.physics.add.sprite(clientObj.value.width / 2, clientObj.value.height - 150 - this.playerShoot.height, 'ballAnim');
|
|
|
this.ball.setScale(2);
|
|
|
- this.ball.anims.play('ballAnim', true);
|
|
|
+ // this.ball.anims.play('ballAnim', true);
|
|
|
this.ball.setDepth(8);
|
|
|
|
|
|
// 显示射门提示和倒计时
|
|
@@ -731,8 +742,8 @@ class GameScene extends Phaser.Scene {
|
|
|
}
|
|
|
|
|
|
handleShootTimeout() {
|
|
|
- this.isShooting = false; // 立即终止射门状态
|
|
|
- this.tweens.killAll(); // 终止射门动画
|
|
|
+ this.isShooting = false; // 立即终止射门状态
|
|
|
+ this.tweens.killAll(); // 终止射门动画
|
|
|
// 清除超时计时器
|
|
|
if (this.shootTimeout) {
|
|
|
this.shootTimeout.remove();
|
|
@@ -807,7 +818,7 @@ class GameScene extends Phaser.Scene {
|
|
|
|
|
|
// 关键修复:在当前方法内定义并计算目标位置
|
|
|
const goalNetY = this.goal.y + 30;
|
|
|
- const goalNetX = this.player.x;
|
|
|
+ const goalNetX = this.playerShoot.x;
|
|
|
|
|
|
// 创建射门动画
|
|
|
const ballTween = this.tweens.add({
|
|
@@ -819,11 +830,11 @@ class GameScene extends Phaser.Scene {
|
|
|
onComplete: () => {
|
|
|
|
|
|
if (!this.ball || !this.ball.active) return;
|
|
|
- // 关键:检查是否仍处于有效射门状态
|
|
|
- if (!this.isShooting || !this.scene.isActive()) {
|
|
|
- ballTween.remove();
|
|
|
- return; // 状态无效时直接退出
|
|
|
- }
|
|
|
+ // 关键:检查是否仍处于有效射门状态
|
|
|
+ if (!this.isShooting || !this.scene.isActive()) {
|
|
|
+ ballTween.remove();
|
|
|
+ return; // 状态无效时直接退出
|
|
|
+ }
|
|
|
// 判断是否成功
|
|
|
const isSuccess = Phaser.Math.Between(0, 1) === 1;
|
|
|
if (isSuccess) {
|
|
@@ -914,20 +925,20 @@ class GameScene extends Phaser.Scene {
|
|
|
// 重置为奔跑场景
|
|
|
resetToRunningScene() {
|
|
|
|
|
|
- // 1. 立即更新状态为非射门状态
|
|
|
- this.isShooting = false;
|
|
|
-
|
|
|
- // 2. 停止所有动画并清除回调
|
|
|
- this.tweens.killAll(); // 终止所有未完成的动画
|
|
|
+ // 1. 立即更新状态为非射门状态
|
|
|
+ this.isShooting = false;
|
|
|
|
|
|
- // 3. 销毁射门相关对象
|
|
|
- if (this.ball && this.ball.active) {
|
|
|
- this.ball.destroy();
|
|
|
- this.ball = null;
|
|
|
- }
|
|
|
- if (this.goal) this.goal.destroy();
|
|
|
- if (this.goalkeeper) this.goalkeeper.destroy();
|
|
|
+ // 2. 停止所有动画并清除回调
|
|
|
+ this.tweens.killAll(); // 终止所有未完成的动画
|
|
|
|
|
|
+ // 3. 销毁射门相关对象
|
|
|
+ if (this.ball && this.ball.active) {
|
|
|
+ this.ball.destroy();
|
|
|
+ this.ball = null;
|
|
|
+ }
|
|
|
+ if (this.goal) this.goal.destroy();
|
|
|
+ if (this.goalkeeper) this.goalkeeper.destroy();
|
|
|
+ if (this.playerShoot) this.playerShoot.destroy();
|
|
|
// 确保清除超时计时器
|
|
|
if (this.shootTimeout) {
|
|
|
this.shootTimeout.remove();
|
|
@@ -947,6 +958,7 @@ class GameScene extends Phaser.Scene {
|
|
|
this.player.setTexture('playerAnim');
|
|
|
this.player.setPosition(clientObj.value.width / 2, clientObj.value.height - 100);
|
|
|
this.player.setVelocity(0);
|
|
|
+ this.player.visible = true; // 恢复玩家显示
|
|
|
}
|
|
|
|
|
|
// 恢复背景和游戏状态
|
|
@@ -1064,6 +1076,7 @@ class GameScene extends Phaser.Scene {
|
|
|
// 清理射门场景的元素
|
|
|
if (this.goal) this.goal.destroy();
|
|
|
if (this.goalkeeper) this.goalkeeper.destroy();
|
|
|
+ if (this.playerShoot) this.playerShoot.destroy();
|
|
|
if (this.shootHint) this.shootHint.destroy();
|
|
|
|
|
|
// 关键修复:清理ball时判空
|
|
@@ -1094,15 +1107,16 @@ class GameScene extends Phaser.Scene {
|
|
|
this.input.keyboard.off('keydown-SPACE', this.shootBall, this);
|
|
|
this.input.off('pointerdown', this.shootBall, this);
|
|
|
|
|
|
-
|
|
|
- // 清除所有动画和定时器
|
|
|
- this.tweens.killAll();
|
|
|
- this.time.removeAllEvents();
|
|
|
+
|
|
|
+ // 清除所有动画和定时器
|
|
|
+ this.tweens.killAll();
|
|
|
+ this.time.removeAllEvents();
|
|
|
// 清理所有游戏对象
|
|
|
this.obstacles.forEach(obs => obs.destroy());
|
|
|
this.powerUps.forEach(p => p.destroy());
|
|
|
if (this.goal) this.goal.destroy();
|
|
|
if (this.goalkeeper) this.goalkeeper.destroy();
|
|
|
+ if (this.playerShoot) this.playerShoot.destroy();
|
|
|
if (this.ball) this.ball.destroy();
|
|
|
|
|
|
// 调用父类销毁方法
|