about summary refs log tree commit diff stats
path: root/html/plains/game.js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-12-18 16:08:15 -0500
committerelioat <elioat@tilde.institute>2024-12-18 16:08:15 -0500
commite8b1a10f45e25aef021b3b164582b609c0ed36a7 (patch)
tree9a31877cb48a83cbeaf5367a972e9b29e677c8c6 /html/plains/game.js
parent735c44959dc85d9e2ac185b5b988e993b672a7d4 (diff)
downloadtour-e8b1a10f45e25aef021b3b164582b609c0ed36a7.tar.gz
*
Diffstat (limited to 'html/plains/game.js')
-rw-r--r--html/plains/game.js24
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
         };
     }
 };