about summary refs log tree commit diff stats
path: root/html/tower/js/mechanics.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/tower/js/mechanics.js')
-rw-r--r--html/tower/js/mechanics.js57
1 files changed, 53 insertions, 4 deletions
diff --git a/html/tower/js/mechanics.js b/html/tower/js/mechanics.js
index c9c4202..ab9bee4 100644
--- a/html/tower/js/mechanics.js
+++ b/html/tower/js/mechanics.js
@@ -55,8 +55,12 @@ function updateParticles(particles, timestamp, deltaTime) {
         const age = timestamp - particle.createdAt;
         if (age > particle.lifetime) return false;
         
-        particle.position.x += particle.velocity.x * deltaTime;
-        particle.position.y += particle.velocity.y * deltaTime;
+        // Only update position for particles with velocity
+        if (particle.velocity) {
+            particle.position.x += particle.velocity.x * deltaTime;
+            particle.position.y += particle.velocity.y * deltaTime;
+        }
+        
         return true;
     });
 }
@@ -109,15 +113,60 @@ function findEnemiesInRange(tower, enemies) {
     });
 }
 
+function createAOEExplosion(position, cellSize) {
+    return {
+        position: {
+            x: (position.x + 0.5) * cellSize,
+            y: (position.y + 0.5) * cellSize
+        },
+        createdAt: performance.now(),
+        type: 'AOE_EXPLOSION',
+        ...ParticleTypes.AOE_EXPLOSION
+    };
+}
+
 function handleTowerAttack(tower, target, projectiles, particles, timestamp, cellSize) {
+    // Create projectile
     projectiles.push({
         startPos: tower.position,
         targetPos: target.position,
         createdAt: timestamp,
-        lifetime: 300
+        lifetime: 300,
+        towerType: tower.type
     });
     
-    target.currentHealth -= tower.damage;
+    if (tower.special === 'aoe') {
+        // Find all enemies in AOE radius
+        const enemiesInAOE = gameState.enemies.filter(enemy => {
+            const dx = enemy.position.x - target.position.x;
+            const dy = enemy.position.y - target.position.y;
+            return Math.sqrt(dx * dx + dy * dy) <= tower.aoeRadius;
+        });
+        
+        // Create AOE explosion effect
+        particles.push(createAOEExplosion(target.position, cellSize));
+        
+        // Damage all enemies in range
+        enemiesInAOE.forEach(enemy => {
+            enemy.currentHealth -= tower.damage;
+            if (enemy.currentHealth <= 0) {
+                particles.push(...createDeathParticles(enemy, cellSize));
+            }
+        });
+    } else if (tower.special === 'slow') {
+        // Apply slow effect instead of damage
+        if (!target.slowed) {
+            target.speed *= (1 - tower.slowAmount);
+            target.slowed = true;
+            
+            // Visual indicator for slowed enemies
+            target.color = '#27ae60' + Math.floor(0.5 * 255).toString(16).padStart(2, '0');
+        }
+    } else {
+        // Normal damage for regular towers
+        target.currentHealth -= tower.damage;
+    }
+    
     tower.lastAttackTime = timestamp;
     
     if (target.currentHealth <= 0) {