From 623caaea314ca2035bfd3537d73751e5e4f6e55a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Nov 2025 08:20:05 +0000 Subject: [PATCH] feat(combat): Integrate chair kicking with punch mechanic Update chair interaction to use the punch system instead of direct kicking: **Changes to interactions.js:** - Modified swivel chair interaction to trigger player punch instead of directly applying kick velocity - Simplified chair interaction handler to just call playerCombat.punch() **Changes to player-combat.js:** - Extended checkForHits() to detect chairs in punch range and direction - Added kickChair() method that applies the same velocity calculation: - Calculates direction from player to chair - Applies 1200 px/s kick force in that direction - Triggers spin direction calculation for visual rotation - Adds visual feedback (flash chair, light screen shake) - Chairs now respond to punch AOE damage like hostile NPCs Now clicking a chair or pressing 'E' near it triggers a punch, and if the chair is in punch range and facing direction, it gets kicked with the original velocity physics. Multiple chairs can be kicked with one punch. --- js/systems/interactions.js | 32 +++------------ js/systems/player-combat.js | 79 ++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/js/systems/interactions.js b/js/systems/interactions.js index 9dac178..90ff578 100644 --- a/js/systems/interactions.js +++ b/js/systems/interactions.js @@ -453,35 +453,13 @@ export function handleObjectInteraction(sprite) { }); } - // Handle swivel chair interaction - send it flying! + // Handle swivel chair interaction - trigger punch to kick it! if (sprite.isSwivelChair && sprite.body) { const player = window.player; - if (player) { - // Calculate direction from player to chair - const dx = sprite.x - player.x; - const dy = sprite.y - player.y; - const distance = Math.sqrt(dx * dx + dy * dy); - - if (distance > 0) { - // Normalize the direction vector - const dirX = dx / distance; - const dirY = dy / distance; - - // Apply a strong kick velocity - const kickForce = 1200; // Pixels per second - sprite.body.setVelocity(dirX * kickForce, dirY * kickForce); - - // Trigger spin direction calculation for visual rotation - if (window.calculateChairSpinDirection) { - window.calculateChairSpinDirection(player, sprite); - } - - // Show feedback message - console.log('SWIVEL CHAIR KICKED', { - chairName: sprite.name, - velocity: { x: dirX * kickForce, y: dirY * kickForce } - }); - } + if (player && window.playerCombat) { + // Trigger punch instead of directly kicking the chair + // The punch system will detect the chair and apply kick velocity + window.playerCombat.punch(); } return; } diff --git a/js/systems/player-combat.js b/js/systems/player-combat.js index b6eca59..420d7f7 100644 --- a/js/systems/player-combat.js +++ b/js/systems/player-combat.js @@ -130,9 +130,41 @@ export class PlayerCombat { hitCount++; }); + // Check for chairs in range and direction + let chairsHit = 0; + if (window.chairs && window.chairs.length > 0) { + window.chairs.forEach(chair => { + // Only kick swivel chairs with physics bodies + if (!chair.isSwivelChair || !chair.body) { + return; + } + + const chairX = chair.x; + const chairY = chair.y; + const distance = Phaser.Math.Distance.Between(playerX, playerY, chairX, chairY); + + if (distance > punchRange) { + return; // Too far + } + + // Check if chair is in the facing direction + if (!this.isInDirection(playerX, playerY, chairX, chairY, direction)) { + return; // Not in facing direction + } + + // Hit landed! Kick the chair + this.kickChair(chair); + chairsHit++; + }); + } + if (hitCount > 0) { console.log(`Player punch hit ${hitCount} NPC(s)`); - } else { + } + if (chairsHit > 0) { + console.log(`Player punch hit ${chairsHit} chair(s)`); + } + if (hitCount === 0 && chairsHit === 0) { console.log('Player punch missed'); } } @@ -192,4 +224,49 @@ export class PlayerCombat { console.log(`Dealt ${damage} damage to ${npc.id}`); } + + /** + * Apply kick velocity to chair + * @param {Phaser.GameObjects.Sprite} chair - Chair sprite + */ + kickChair(chair) { + if (!chair || !chair.body || !window.player) { + return; + } + + // Calculate direction from player to chair + const dx = chair.x - window.player.x; + const dy = chair.y - window.player.y; + const distance = Math.sqrt(dx * dx + dy * dy); + + if (distance > 0) { + // Normalize the direction vector + const dirX = dx / distance; + const dirY = dy / distance; + + // Apply a strong kick velocity + const kickForce = 1200; // Pixels per second + chair.body.setVelocity(dirX * kickForce, dirY * kickForce); + + // Trigger spin direction calculation for visual rotation + if (window.calculateChairSpinDirection) { + window.calculateChairSpinDirection(window.player, chair); + } + + // Visual feedback - flash the chair + if (window.spriteEffects) { + window.spriteEffects.flashHit(chair); + } + + // Light screen shake + if (window.screenEffects) { + window.screenEffects.shake(2, 150); + } + + console.log('CHAIR KICKED', { + chairName: chair.name, + velocity: { x: dirX * kickForce, y: dirY * kickForce } + }); + } + } }