@@ -13,11 +13,17 @@ let upgradeCost = 10;
1313let swordUpgradeCost = 20 ;
1414let manaUpgradeCost = 50 ;
1515let zone = 0 ;
16+ let heroMaxHP = 100 ;
17+ let heroHP = 100 ;
18+ let heroDefense = 0 ;
19+ let armorUpgradeCost = 30 ;
1620let mana = 0 ;
1721let maxMana = 50 ;
1822let manaRegen = 5 ;
1923let spellCost = 20 ;
2024let spellDamage = 20 ;
25+ const healCost = 30 ;
26+ let healAmount = 50 ;
2127const video = document . getElementById ( 'enemy-video' ) ;
2228const logDiv = document . getElementById ( 'log' ) ;
2329
@@ -37,6 +43,11 @@ function updateUI() {
3743 document . getElementById ( 'xp-next' ) . textContent = xpToNext ;
3844 document . getElementById ( 'dps' ) . textContent = dps ;
3945 document . getElementById ( 'enemy-level' ) . textContent = enemyLevel ;
46+ document . getElementById ( 'enemy-name' ) . textContent = enemyNames [ enemyLevel ] + ( enemyLevel === 10 ? ' (Boss)' : '' ) ;
47+ document . getElementById ( 'armor-cost' ) . textContent = armorUpgradeCost ;
48+ document . getElementById ( 'hero-hp' ) . textContent = `${ Math . floor ( Math . max ( 0 , heroHP ) ) } /${ heroMaxHP } ` ;
49+ const heroPercent = Math . max ( 0 , ( heroHP / heroMaxHP ) * 100 ) ;
50+ document . getElementById ( 'hero-hp-fill' ) . style . width = `${ heroPercent } %` ;
4051 document . getElementById ( 'enemy-hp' ) . textContent = `${ Math . max ( 0 , enemyHP ) } /${ enemyMaxHP } ` ;
4152 document . getElementById ( 'dps-cost' ) . textContent = upgradeCost ;
4253 document . getElementById ( 'sword-cost' ) . textContent = swordUpgradeCost ;
@@ -100,9 +111,23 @@ function attack(damage, isManual = false, isSpell = false) {
100111// Idle auto-attack every second
101112// No change, but context
102113function autoTick ( ) {
103- attack ( dps ) ;
104- mana = Math . min ( mana + manaRegen , maxMana ) ;
105- updateUI ( ) ;
114+ attack ( dps ) ;
115+ let baseDmg = ( enemyLevel + 1 ) * Math . pow ( 1.5 , zone ) ;
116+ if ( enemyLevel === 10 ) baseDmg *= 2 ;
117+ const enemyDamage = Math . max ( 1 , baseDmg - heroDefense ) ;
118+ heroHP -= enemyDamage ;
119+ if ( heroHP <= 0 ) {
120+ log ( `You have been defeated by the ${ enemyNames [ enemyLevel ] } ! Lost half your gold and returned to Zone 0.` ) ;
121+ gold = Math . floor ( gold * 0.5 ) ;
122+ zone = 0 ;
123+ enemyLevel = 0 ;
124+ enemyMaxHP = 10 ;
125+ enemyHP = enemyMaxHP ;
126+ video . src = `assets/enemy-0.mp4` ;
127+ heroHP = heroMaxHP ;
128+ }
129+ mana = Math . min ( mana + manaRegen , maxMana ) ;
130+ updateUI ( ) ;
106131}
107132setInterval ( autoTick , 1000 ) ;
108133
@@ -148,6 +173,7 @@ document.getElementById('upgrade-mana').addEventListener('click', () => {
148173 if ( gold >= manaUpgradeCost ) {
149174 gold -= manaUpgradeCost ;
150175 maxMana += 50 ;
176+ healAmount += 25 ;
151177 manaRegen += 5 ;
152178 spellDamage += 10 ;
153179 manaUpgradeCost = Math . floor ( manaUpgradeCost * 1.5 ) ;
@@ -157,9 +183,37 @@ document.getElementById('upgrade-mana').addEventListener('click', () => {
157183 log ( 'Not enough gold!' ) ;
158184 }
159185} ) ;
186+ // Upgrade Armor
187+ document . getElementById ( 'upgrade-armor' ) . addEventListener ( 'click' , ( ) => {
188+ if ( gold >= armorUpgradeCost ) {
189+ gold -= armorUpgradeCost ;
190+ heroMaxHP += 50 ;
191+ heroDefense += 5 ;
192+ armorUpgradeCost = Math . floor ( armorUpgradeCost * 1.5 ) ;
193+ heroHP = heroMaxHP ;
194+ log ( `Upgraded armor! Max HP ${ heroMaxHP } , defense ${ heroDefense } . Next upgrade costs ${ armorUpgradeCost } .` ) ;
195+ updateUI ( ) ;
196+ } else {
197+ log ( 'Not enough gold!' ) ;
198+ }
199+ } ) ;
200+ // Heal Spell
201+ document . getElementById ( 'heal-btn' ) . addEventListener ( 'click' , ( ) => {
202+ if ( mana >= healCost ) {
203+ mana -= healCost ;
204+ heroHP = Math . min ( heroHP + healAmount , heroMaxHP ) ;
205+ log ( `You cast heal, restoring ${ healAmount } HP.` ) ;
206+ updateUI ( ) ;
207+ }
208+ } ) ;
160209// Save and load
161210function saveGame ( ) {
162211 const saveData = { heroLevel, gold, xp, xpToNext, dps, manualDamage, enemyLevel, enemyMaxHP, enemyHP, upgradeCost, swordUpgradeCost, manaUpgradeCost, zone, mana, maxMana, manaRegen, spellDamage } ;
212+ saveData . heroMaxHP = heroMaxHP ;
213+ saveData . heroHP = heroHP ;
214+ saveData . heroDefense = heroDefense ;
215+ saveData . armorUpgradeCost = armorUpgradeCost ;
216+ saveData . healAmount = healAmount ;
163217 localStorage . setItem ( 'eldoriaSave' , JSON . stringify ( saveData ) ) ;
164218 log ( 'Game saved.' ) ;
165219}
@@ -182,6 +236,11 @@ function loadGame() {
182236 manaUpgradeCost = data . manaUpgradeCost || 50 ;
183237 zone = data . zone || 0 ;
184238 mana = data . mana || 0 ;
239+ heroMaxHP = data . heroMaxHP || 100 ;
240+ heroHP = data . heroHP || 100 ;
241+ heroDefense = data . heroDefense || 0 ;
242+ armorUpgradeCost = data . armorUpgradeCost || 30 ;
243+ healAmount = data . healAmount || 50 ;
185244 maxMana = data . maxMana || 50 ;
186245 manaRegen = data . manaRegen || 5 ;
187246 spellDamage = data . spellDamage || 20 ;
@@ -195,7 +254,7 @@ function loadGame() {
195254
196255document . getElementById ( 'save-btn' ) . addEventListener ( 'click' , saveGame ) ;
197256document . getElementById ( 'load-btn' ) . addEventListener ( 'click' , loadGame ) ;
198-
257+ video . addEventListener ( 'click' , ( ) => attack ( manualDamage , true ) ) ;
199258// Initial setup
200259video . src = `assets/enemy-${ enemyLevel } .mp4` ;
201260updateUI ( ) ;
0 commit comments