about summary refs log tree commit diff stats
path: root/html
diff options
context:
space:
mode:
Diffstat (limited to 'html')
-rw-r--r--html/tower/index.html8
-rw-r--r--html/tower/js/gameState.js12
-rw-r--r--html/tower/js/mechanics.js51
-rw-r--r--html/tower/js/path.js38
4 files changed, 108 insertions, 1 deletions
diff --git a/html/tower/index.html b/html/tower/index.html
index d9dd854..8f6fd05 100644
--- a/html/tower/index.html
+++ b/html/tower/index.html
@@ -50,6 +50,11 @@
             height: 40px;
             margin-bottom: 5px;
         }
+        .tower-name {
+            font-size: 14px;
+            font-weight: bold;
+            margin-bottom: 3px;
+        }
         .tower-cost {
             font-size: 12px;
             color: #666;
@@ -79,14 +84,17 @@
         <div class="tower-palette">
             <div class="tower-option" draggable="true" data-tower-type="BASIC">
                 <div class="tower-preview" style="background: #4a90e2;"></div>
+                <div class="tower-name">Basic</div>
                 <div class="tower-cost">$20</div>
             </div>
             <div class="tower-option" draggable="true" data-tower-type="SNIPER">
                 <div class="tower-preview" style="background: #9b59b6;"></div>
+                <div class="tower-name">Sniper</div>
                 <div class="tower-cost">$40</div>
             </div>
             <div class="tower-option" draggable="true" data-tower-type="RAPID">
                 <div class="tower-preview" style="background: #2ecc71;"></div>
+                <div class="tower-name">Rapid</div>
                 <div class="tower-cost">$35</div>
             </div>
             <button id="startCombat" class="start-button">Start Combat</button>
diff --git a/html/tower/js/gameState.js b/html/tower/js/gameState.js
index 49708ee..0f379f6 100644
--- a/html/tower/js/gameState.js
+++ b/html/tower/js/gameState.js
@@ -111,4 +111,14 @@ function createParticle(type, position, angle) {
 
 // Add to gameState object
 gameState.particles = [];
-gameState.projectiles = []; 
\ No newline at end of file
+gameState.projectiles = [];
+gameState.enemiesDestroyed = 0;
+gameState.enemiesEscaped = 0;
+gameState.path = []; // This will be populated when the path is generated
+
+gameState.awardEnemyDestroyed = function() {
+    this.enemiesDestroyed++;
+    // Random reward between 5 and 10
+    const reward = Math.floor(Math.random() * 6) + 5;
+    this.currency += reward;
+}; 
\ No newline at end of file
diff --git a/html/tower/js/mechanics.js b/html/tower/js/mechanics.js
index 4babe2a..5d3eacb 100644
--- a/html/tower/js/mechanics.js
+++ b/html/tower/js/mechanics.js
@@ -140,4 +140,55 @@ function handleEnemyAttack(enemy, tower, particles, timestamp, cellSize) {
     
     // Reduce tower's damage as it takes damage
     tower.damage = TowerTypes[tower.type].damage * (tower.currentHealth / tower.maxHealth);
+}
+
+function updateEnemies() {
+    gameState.enemies = gameState.enemies.filter(enemy => {
+        // Add progress property if it doesn't exist
+        if (typeof enemy.progress === 'undefined') {
+            enemy.progress = 0;
+        }
+        
+        // Reduce the multiplier from 0.01 to 0.001 for more reasonable speed
+        enemy.progress += enemy.speed * 0.001; // Smaller multiplier for slower movement
+        
+        // Check if enemy has completed the path
+        if (enemy.progress >= 1) {
+            gameState.enemiesEscaped++;
+            return false; // Remove from array
+        }
+        
+        // Check for collisions with projectiles
+        const hitByProjectile = gameState.projectiles.some(projectile => {
+            const distance = Math.hypot(
+                enemy.position.x - projectile.startPos.x,
+                enemy.position.y - projectile.startPos.y
+            );
+            return distance < 0.5; // Adjust collision radius as needed
+        });
+        
+        if (hitByProjectile) {
+            gameState.awardEnemyDestroyed();
+            return false; // Remove from array
+        }
+        
+        // Update enemy position based on progress
+        const pathPosition = getPathPosition(enemy.progress, gameState.path);
+        enemy.position.x = pathPosition.x;
+        enemy.position.y = pathPosition.y;
+        
+        return true;
+    });
+    
+    // Remove projectiles that hit enemies
+    gameState.projectiles = gameState.projectiles.filter(projectile => {
+        const hitEnemy = gameState.enemies.some(enemy => {
+            const distance = Math.hypot(
+                enemy.position.x - projectile.startPos.x,
+                enemy.position.y - projectile.startPos.y
+            );
+            return distance < 0.5;
+        });
+        return !hitEnemy;
+    });
 } 
\ No newline at end of file
diff --git a/html/tower/js/path.js b/html/tower/js/path.js
index f594ee2..46e4bfb 100644
--- a/html/tower/js/path.js
+++ b/html/tower/js/path.js
@@ -80,4 +80,42 @@ function generatePath(grid) {
     }
     
     return Promise.resolve(path);
+}
+
+function getPathPosition(progress, path) {
+    // Ensure progress is between 0 and 1
+    progress = Math.max(0, Math.min(1, progress));
+    
+    // Get the total path length
+    let totalLength = 0;
+    for (let i = 1; i < path.length; i++) {
+        const dx = path[i].x - path[i-1].x;
+        const dy = path[i].y - path[i-1].y;
+        totalLength += Math.sqrt(dx * dx + dy * dy);
+    }
+    
+    // Find target distance along path
+    const targetDistance = progress * totalLength;
+    
+    // Find the segment where the target position lies
+    let currentDistance = 0;
+    for (let i = 1; i < path.length; i++) {
+        const dx = path[i].x - path[i-1].x;
+        const dy = path[i].y - path[i-1].y;
+        const segmentLength = Math.sqrt(dx * dx + dy * dy);
+        
+        if (currentDistance + segmentLength >= targetDistance) {
+            // Calculate position within this segment
+            const segmentProgress = (targetDistance - currentDistance) / segmentLength;
+            return {
+                x: path[i-1].x + dx * segmentProgress,
+                y: path[i-1].y + dy * segmentProgress
+            };
+        }
+        
+        currentDistance += segmentLength;
+    }
+    
+    // If we somehow exceed the path length, return the last point
+    return { ...path[path.length - 1] };
 } 
\ No newline at end of file