|
@@ -374,66 +374,81 @@ class Fruit {
|
|
|
|
|
|
// 水果类中的half方法
|
|
// 水果类中的half方法
|
|
half(deg, shouldEmit = false) {
|
|
half(deg, shouldEmit = false) {
|
|
- // 手动计算世界坐标 (替代getWorldPosition)
|
|
|
|
|
|
+ // 计算世界坐标
|
|
const transform = this.sprite.getWorldTransformMatrix();
|
|
const transform = this.sprite.getWorldTransformMatrix();
|
|
const worldPos = new Phaser.Math.Vector2(
|
|
const worldPos = new Phaser.Math.Vector2(
|
|
transform.getX(0, 0),
|
|
transform.getX(0, 0),
|
|
transform.getY(0, 0)
|
|
transform.getY(0, 0)
|
|
);
|
|
);
|
|
|
|
|
|
- // 创建两半水果,位置严格等于原水果的世界坐标
|
|
|
|
- this.halfOne = this.game.add.sprite(
|
|
|
|
- worldPos.x, // 使用计算出的世界坐标x
|
|
|
|
- worldPos.y, // 使用计算出的世界坐标y
|
|
|
|
- this.sprite.texture.key + '-1'
|
|
|
|
- );
|
|
|
|
|
|
+ // 1. 计算切割方向的垂直向量(用于分离力)
|
|
|
|
+ // 刀刃角度转弧度
|
|
|
|
+ const rad = Phaser.Math.DegToRad(deg);
|
|
|
|
+ // 垂直于刀刃的方向向量(单位向量)
|
|
|
|
+ const sepX = Math.sin(rad); // 垂直方向X分量
|
|
|
|
+ const sepY = -Math.cos(rad); // 垂直方向Y分量
|
|
|
|
+ // 分离力度(可根据水果大小调整)
|
|
|
|
+ const sepForce = 300;
|
|
|
|
+
|
|
|
|
+ // 2. 创建第一半水果
|
|
|
|
+ this.halfOne = this.game.add.sprite(worldPos.x, worldPos.y, this.sprite.texture.key + '-1');
|
|
this.halfOne.setOrigin(0.5, 0.5);
|
|
this.halfOne.setOrigin(0.5, 0.5);
|
|
- this.halfOne.rotation = Phaser.Math.DegToRad(deg + 45);
|
|
|
|
-
|
|
|
|
- // 物理属性:初始速度归零,避免瞬间偏移
|
|
|
|
|
|
+ this.halfOne.rotation = Phaser.Math.DegToRad(deg + 45); // 初始角度与刀刃匹配
|
|
this.game.physics.add.existing(this.halfOne);
|
|
this.game.physics.add.existing(this.halfOne);
|
|
- this.halfOne.body.velocity.x = this.sprite.body.velocity.x; // 仅继承原速度
|
|
|
|
- this.halfOne.body.velocity.y = this.sprite.body.velocity.y;
|
|
|
|
|
|
+ // 速度 = 原速度 + 分离速度(向一侧)
|
|
|
|
+ this.halfOne.body.velocity.x = this.sprite.body.velocity.x + sepX * sepForce;
|
|
|
|
+ this.halfOne.body.velocity.y = this.sprite.body.velocity.y + sepY * sepForce;
|
|
this.halfOne.body.gravity.y = 2000;
|
|
this.halfOne.body.gravity.y = 2000;
|
|
|
|
+ // 增加旋转(顺时针)
|
|
|
|
+ this.halfOne.body.angularVelocity = 500; // 旋转速度(度/秒)
|
|
this.halfOne.body.setCollideWorldBounds(false);
|
|
this.halfOne.body.setCollideWorldBounds(false);
|
|
this.halfOne.checkWorldBounds = true;
|
|
this.halfOne.checkWorldBounds = true;
|
|
this.halfOne.outOfBoundsKill = true;
|
|
this.halfOne.outOfBoundsKill = true;
|
|
|
|
|
|
- // 第二半水果同理
|
|
|
|
- this.halfTwo = this.game.add.sprite(
|
|
|
|
- worldPos.x, // 使用计算出的世界坐标x
|
|
|
|
- worldPos.y, // 使用计算出的世界坐标y
|
|
|
|
- this.sprite.texture.key + '-2'
|
|
|
|
- );
|
|
|
|
|
|
+ // 3. 创建第二半水果(分离方向相反)
|
|
|
|
+ this.halfTwo = this.game.add.sprite(worldPos.x, worldPos.y, this.sprite.texture.key + '-2');
|
|
this.halfTwo.setOrigin(0.5, 0.5);
|
|
this.halfTwo.setOrigin(0.5, 0.5);
|
|
this.halfTwo.rotation = Phaser.Math.DegToRad(deg + 45);
|
|
this.halfTwo.rotation = Phaser.Math.DegToRad(deg + 45);
|
|
-
|
|
|
|
this.game.physics.add.existing(this.halfTwo);
|
|
this.game.physics.add.existing(this.halfTwo);
|
|
- this.halfTwo.body.velocity.x = this.sprite.body.velocity.x; // 仅继承原速度
|
|
|
|
- this.halfTwo.body.velocity.y = this.sprite.body.velocity.y;
|
|
|
|
|
|
+ // 速度 = 原速度 - 分离速度(向另一侧)
|
|
|
|
+ this.halfTwo.body.velocity.x = this.sprite.body.velocity.x - sepX * sepForce;
|
|
|
|
+ this.halfTwo.body.velocity.y = this.sprite.body.velocity.y - sepY * sepForce;
|
|
this.halfTwo.body.gravity.y = 2000;
|
|
this.halfTwo.body.gravity.y = 2000;
|
|
|
|
+ // 增加旋转(逆时针,与第一半相反)
|
|
|
|
+ this.halfTwo.body.angularVelocity = -500;
|
|
this.halfTwo.body.setCollideWorldBounds(false);
|
|
this.halfTwo.body.setCollideWorldBounds(false);
|
|
this.halfTwo.checkWorldBounds = true;
|
|
this.halfTwo.checkWorldBounds = true;
|
|
this.halfTwo.outOfBoundsKill = true;
|
|
this.halfTwo.outOfBoundsKill = true;
|
|
|
|
|
|
- // 延迟销毁原水果,确保视觉上"替换"而非"突然消失"
|
|
|
|
- setTimeout(() => {
|
|
|
|
- this.sprite.destroy();
|
|
|
|
- }, 50);
|
|
|
|
|
|
+ // 4. 原水果透明度渐变消失(替代直接销毁)
|
|
|
|
+ this.game.tweens.add({
|
|
|
|
+ targets: this.sprite,
|
|
|
|
+ alpha: 0, // 透明度从1→0
|
|
|
|
+ duration: 100, // 100ms内消失
|
|
|
|
+ onComplete: () => {
|
|
|
|
+ this.sprite.destroy();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- // 粒子效果
|
|
|
|
|
|
+ // 5. 优化粒子效果(沿分离方向飞溅)
|
|
if (shouldEmit) {
|
|
if (shouldEmit) {
|
|
const emitColor = this.emitterMap[this.sprite.texture.key];
|
|
const emitColor = this.emitterMap[this.sprite.texture.key];
|
|
this.generateFlame(this.bitmap, emitColor);
|
|
this.generateFlame(this.bitmap, emitColor);
|
|
const texture = this.bitmap.generateTexture('fruitParticle', 60, 60);
|
|
const texture = this.bitmap.generateTexture('fruitParticle', 60, 60);
|
|
|
|
+ // 粒子发射器:沿分离方向扩散
|
|
this.emitter = this.game.add.particles(0, 0, texture.key, {
|
|
this.emitter = this.game.add.particles(0, 0, texture.key, {
|
|
x: worldPos.x,
|
|
x: worldPos.x,
|
|
y: worldPos.y,
|
|
y: worldPos.y,
|
|
- speed: { min: -400, max: 400 },
|
|
|
|
- scale: { start: 1, end: 0.1 },
|
|
|
|
|
|
+ // 速度方向:以分离方向为中心,±30度范围
|
|
|
|
+ angle: {
|
|
|
|
+ min: deg - 30,
|
|
|
|
+ max: deg + 30
|
|
|
|
+ },
|
|
|
|
+ speed: { min: 100, max: 300 }, // 速度与分离力度匹配
|
|
|
|
+ scale: { start: 0.8, end: 0.1 },
|
|
alpha: { start: 1, end: 0.1 },
|
|
alpha: { start: 1, end: 0.1 },
|
|
- lifespan: 4000,
|
|
|
|
- maxParticles: 10
|
|
|
|
|
|
+ lifespan: 600, // 延长粒子生命周期,增强视觉效果
|
|
|
|
+ maxParticles: 15 // 增加粒子数量
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1067,7 +1082,7 @@ class PlayScene extends Phaser.Scene {
|
|
y: y
|
|
y: y
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ console.log("isFruitisFruitisFruit",isFruit)
|
|
fruit.isFruit = isFruit;
|
|
fruit.isFruit = isFruit;
|
|
const sprite = fruit.getSprite();
|
|
const sprite = fruit.getSprite();
|
|
|
|
|