From e8b1a10f45e25aef021b3b164582b609c0ed36a7 Mon Sep 17 00:00:00 2001 From: elioat Date: Wed, 18 Dec 2024 16:08:15 -0500 Subject: * --- html/plains/game.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'html/plains/game.js') diff --git a/html/plains/game.js b/html/plains/game.js index d25daaf..1f9b27e 100644 --- a/html/plains/game.js +++ b/html/plains/game.js @@ -777,13 +777,35 @@ const weaponSystems = { const newAngle = state.player.swordAngle + CONFIG.sword.swingSpeed; const swingComplete = newAngle > Math.atan2(state.player.direction.y, state.player.direction.x) + Math.PI / 2; + // Add sword collision detection + const swordTip = { + x: state.player.x + Math.cos(state.player.swordAngle) * CONFIG.sword.length, + y: state.player.y + Math.sin(state.player.swordAngle) * CONFIG.sword.length + }; + + // Check all enemies for sword collision + const updatedEnemies = state.enemies.map(enemy => { + if (!enemy.stunned) { + const dx = enemy.x - state.player.x; + const dy = enemy.y - state.player.y; + const distance = Math.sqrt(dx * dx + dy * dy); + + if (distance < enemy.size + CONFIG.sword.length) { + const knockbackAngle = Math.atan2(dy, dx); + enemySystem.handleEnemyDamage(enemy, 1, 1, knockbackAngle); + } + } + return enemy; + }); + return { ...state, player: { ...state.player, swordAngle: newAngle, isSwinging: !swingComplete - } + }, + enemies: updatedEnemies }; } }; -- cgit 1.4.1-2-gfad0