diff options
Diffstat (limited to 'html/plains/game.js')
-rw-r--r-- | html/plains/game.js | 24 |
1 files changed, 23 insertions, 1 deletions
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 }; } }; |