diff options
Diffstat (limited to 'html')
-rw-r--r-- | html/tower/js/gameState.js | 35 | ||||
-rw-r--r-- | html/tower/js/mechanics.js | 8 | ||||
-rw-r--r-- | html/tower/js/renderer.js | 38 |
3 files changed, 69 insertions, 12 deletions
diff --git a/html/tower/js/gameState.js b/html/tower/js/gameState.js index 41f25e5..ff64753 100644 --- a/html/tower/js/gameState.js +++ b/html/tower/js/gameState.js @@ -10,7 +10,8 @@ const TowerTypes = { range: 3, damage: 1, attackSpeed: 1, - color: '#3498db' + color: '#3498db', + maxAmmo: 15 }, SNIPER: { name: 'Sniper Tower', @@ -18,7 +19,8 @@ const TowerTypes = { range: 6, damage: 2, attackSpeed: 0.5, - color: '#8e44ad' + color: '#8e44ad', + maxAmmo: 8 }, RAPID: { name: 'Rapid Tower', @@ -26,7 +28,8 @@ const TowerTypes = { range: 2, damage: 0.5, attackSpeed: 2, - color: '#16a085' + color: '#16a085', + maxAmmo: 30 }, GOOP: { name: 'Goop Tower', @@ -36,17 +39,19 @@ const TowerTypes = { attackSpeed: 1, color: '#27ae60', special: 'slow', - slowAmount: 0.5 // Reduces enemy speed by 50% + slowAmount: 0.75, + maxAmmo: 20 }, AOE: { name: 'AOE Tower', cost: 45, range: 2, - damage: 1.5, + damage: 3, attackSpeed: 0.3, color: '#d35400', special: 'aoe', - aoeRadius: 1 // Additional tiles affected + aoeRadius: 4, + maxAmmo: 10 } }; @@ -96,13 +101,15 @@ const EnemyTypes = { }; function createTower(type, position) { + const towerType = TowerTypes[type]; return { - ...TowerTypes[type], + ...towerType, type, position, lastAttackTime: 0, currentHealth: 10, - maxHealth: 10 + maxHealth: 10, + ammo: towerType.maxAmmo // Initialize ammo }; } @@ -174,14 +181,20 @@ const gameState = { // Add method to advance to next level advanceToNextLevel() { + // Award bonus for remaining ammo + let ammoBonus = 0; + this.towers.forEach(tower => { + ammoBonus += tower.ammo * 2; + }); + this.currency += ammoBonus; + this.level++; this.phase = GamePhase.PLACEMENT; - this.towers = []; // Clear existing towers + this.towers = []; this.enemies = []; this.projectiles = []; this.particles = []; this.grid = Array(20).fill().map(() => Array(20).fill('empty')); - // Award bonus currency for reaching new level - this.currency += 10; + this.currency += 10; // Level completion bonus } }; \ No newline at end of file diff --git a/html/tower/js/mechanics.js b/html/tower/js/mechanics.js index f2ec57b..13b3ce8 100644 --- a/html/tower/js/mechanics.js +++ b/html/tower/js/mechanics.js @@ -153,6 +153,14 @@ function createSlimeTrail(enemy, cellSize) { } function handleTowerAttack(tower, target, projectiles, particles, timestamp, cellSize) { + // Check if tower has ammo + if (tower.ammo <= 0) { + return; + } + + // Decrease ammo + tower.ammo--; + projectiles.push({ startPos: tower.position, targetPos: target.position, diff --git a/html/tower/js/renderer.js b/html/tower/js/renderer.js index cd2d11d..9bebe0b 100644 --- a/html/tower/js/renderer.js +++ b/html/tower/js/renderer.js @@ -114,7 +114,7 @@ function renderTowers(ctx, towers) { towers.forEach(tower => { const healthPercent = tower.currentHealth / tower.maxHealth; - // Draw tower body with opacity based on health + // Draw tower body ctx.fillStyle = tower.color + Math.floor(healthPercent * 255).toString(16).padStart(2, '0'); ctx.fillRect( tower.position.x * cellSize + cellSize * 0.1, @@ -123,6 +123,16 @@ function renderTowers(ctx, towers) { cellSize * 0.8 ); + // Draw ammo count + ctx.fillStyle = 'white'; + ctx.font = '12px Arial'; + ctx.textAlign = 'center'; + ctx.fillText( + tower.ammo, + (tower.position.x + 0.5) * cellSize, + (tower.position.y + 0.7) * cellSize + ); + // Draw range indicator if (gameState.phase === GamePhase.PLACEMENT) { ctx.beginPath(); @@ -277,4 +287,30 @@ function renderProjectiles(ctx, projectiles) { ctx.fill(); } }); +} + +// Update level complete message in game.js +function handleLevelComplete() { + gameState.phase = GamePhase.TRANSITION; + + // Calculate ammo bonus + let ammoBonus = 0; + gameState.towers.forEach(tower => { + ammoBonus += tower.ammo * 2; + }); + + const message = ` + Level ${gameState.level} Complete! + Current Money: $${gameState.currency} + Ammo Bonus: +$${ammoBonus} + Level Bonus: +$10 + + Ready for Level ${gameState.level + 1}? + `; + + setTimeout(() => { + if (confirm(message)) { + startNextLevel(); + } + }, 100); } \ No newline at end of file |