diff --git a/src/entities/Enemy.js b/src/entities/Enemy.js index 4e3b91a..7a01c2c 100644 --- a/src/entities/Enemy.js +++ b/src/entities/Enemy.js @@ -47,9 +47,15 @@ export class Enemy extends Physics.Arcade.Sprite { if (this.enemyType === 'bug') { this.x += this.speed * dt; - if (Math.abs(this.x - this.startX) > this.patrolRange) { - this.speed *= -1; - this.setFlipX(this.speed < 0); + // Reverse only when past the patrol edge AND still heading outward, + // otherwise the flip re-triggers each frame and the bug jitters. + const dx = this.x - this.startX; + if (dx > this.patrolRange && this.speed > 0) { + this.speed = -Math.abs(this.speed); + this.setFlipX(true); + } else if (dx < -this.patrolRange && this.speed < 0) { + this.speed = Math.abs(this.speed); + this.setFlipX(false); } if (this.x < -60) this.x = GAME_WIDTH + 60; if (this.x > GAME_WIDTH + 60) this.x = -60; @@ -62,9 +68,14 @@ export class Enemy extends Physics.Arcade.Sprite { } else if (this.enemyType === 'mev_bot') { const player = this.scene.player; if (player && player.active) { - const dir = Math.sign(player.x - this.x); - this.x += dir * this.homeSpeed * dt; - this.setFlipX(dir < 0); + // Deadzone: stop chasing when roughly aligned so Math.sign doesn't + // flip every frame and make the bot vibrate around the player column. + const diff = player.x - this.x; + if (Math.abs(diff) > 6) { + const dir = Math.sign(diff); + this.x += dir * this.homeSpeed * dt; + this.setFlipX(dir < 0); + } } this.x = Phaser.Math.Clamp(this.x, 24, GAME_WIDTH - 24); const t = time - this.spawnTime; diff --git a/src/entities/Platform.js b/src/entities/Platform.js index ee0d7c6..41a8b5d 100644 --- a/src/entities/Platform.js +++ b/src/entities/Platform.js @@ -55,10 +55,16 @@ export class Platform extends Physics.Arcade.Sprite { preUpdate(time, delta) { super.preUpdate(time, delta); if (this.platformType === 'moving' && this.body) { - this.setVelocityX(this.moveSpeed); - if (Math.abs(this.x - this.startX) > this.moveRange) { - this.moveSpeed *= -1; + // Reverse direction only when past the edge AND still heading outward. + // (A plain |x-startX|>range flip re-triggers every frame at the boundary, + // which made the platform vibrate in place.) + const dx = this.x - this.startX; + if (dx > this.moveRange && this.moveSpeed > 0) { + this.moveSpeed = -Math.abs(this.moveSpeed); + } else if (dx < -this.moveRange && this.moveSpeed < 0) { + this.moveSpeed = Math.abs(this.moveSpeed); } + this.setVelocityX(this.moveSpeed); if (this.genesisGlow) this.genesisGlow.setPosition(this.x, this.y + 10); } }