about summary refs log tree commit diff stats
path: root/html/plains/enemies.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/plains/enemies.js')
-rw-r--r--html/plains/enemies.js61
1 files changed, 33 insertions, 28 deletions
diff --git a/html/plains/enemies.js b/html/plains/enemies.js
index 77f5245..e3be9af 100644
--- a/html/plains/enemies.js
+++ b/html/plains/enemies.js
@@ -69,6 +69,36 @@ const generateEnemies = (villagers, collisionMap) => {
     return enemies;
 };
 
+const createDeathParticles = (enemy) => {
+    const numParticles = 15 + Math.floor(Math.random() * 10);
+    for (let i = 0; i < numParticles; i++) {
+        const particleAngle = (i / numParticles) * Math.PI * 2;
+        const speed = 2 + Math.random() * 3;
+        state.particles.push({
+            x: enemy.x,
+            y: enemy.y,
+            dx: Math.cos(particleAngle) * speed,
+            dy: Math.sin(particleAngle) * speed,
+            size: enemy.size * (0.1 + Math.random() * 0.2),
+            color: enemy.color,
+            lifetime: 1000,
+            createdAt: animationTime
+        });
+    }
+};
+
+const createDeathDiamonds = (enemy) => {
+    const diamondCount = Math.floor(Math.random() * 5);
+    for (let i = 0; i < diamondCount; i++) {
+        state.diamonds.push({
+            x: enemy.x + (Math.random() - 0.5) * 20,
+            y: enemy.y + (Math.random() - 0.5) * 20,
+            size: 6,
+            collected: false
+        });
+    }
+};
+
 const handleEnemyDamage = (enemy, damage, knockbackForce = 0, angle = 0) => {
     const gridSize = CONFIG.display.grid.size;
     enemy.hp -= damage;
@@ -79,7 +109,7 @@ const handleEnemyDamage = (enemy, damage, knockbackForce = 0, angle = 0) => {
     
     // Apply knockback if there's a force
     if (knockbackForce > 0) {
-        const knockbackDistance = gridSize * 0.5; // Half grid cell knockback
+        const knockbackDistance = gridSize * 0.5;
         enemy.knockback = {
             active: true,
             startX: enemy.x,
@@ -92,33 +122,8 @@ const handleEnemyDamage = (enemy, damage, knockbackForce = 0, angle = 0) => {
     }
     
     if (damage > 0 && enemy.hp <= 0) {
-        // Create death particles
-        const numParticles = 15 + Math.floor(Math.random() * 10);
-        for (let i = 0; i < numParticles; i++) {
-            const particleAngle = (i / numParticles) * Math.PI * 2;
-            const speed = 2 + Math.random() * 3;
-            state.particles.push({
-                x: enemy.x,
-                y: enemy.y,
-                dx: Math.cos(particleAngle) * speed,
-                dy: Math.sin(particleAngle) * speed,
-                size: enemy.size * (0.1 + Math.random() * 0.2),
-                color: enemy.color,
-                lifetime: 1000,
-                createdAt: animationTime
-            });
-        }
-
-        // Generate diamonds when enemy is defeated
-        const diamondCount = Math.floor(Math.random() * 5);
-        for (let i = 0; i < diamondCount; i++) {
-            state.diamonds.push({
-                x: enemy.x + (Math.random() - 0.5) * 20,
-                y: enemy.y + (Math.random() - 0.5) * 20,
-                size: 6,
-                collected: false
-            });
-        }
+        createDeathParticles(enemy);
+        createDeathDiamonds(enemy);
     }
     
     return damage > 0 && enemy.hp <= 0;