Spaces:
Running
Running
File size: 10,648 Bytes
75b1060 b9fed9a 75b1060 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tiny Healer</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #1a1a1a;
color: white;
}
#game-container {
width: 800px;
height: 600px;
border: 2px solid #333;
padding: 20px;
background-color: #222;
}
#combat-window {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
#allies {
width: 45%;
}
#boss {
width: 45%;
}
.health-bar {
height: 30px;
background-color: #4CAF50;
margin-bottom: 10px;
position: relative;
cursor: pointer;
}
.health-bar.selected {
background-color: #2196F3;
}
.health-bar-text {
position: absolute;
width: 100%;
text-align: center;
line-height: 30px;
}
#boss-health-bar {
height: 50px;
background-color: #f44336;
}
#spell-buttons {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.spell-button {
width: 18%;
height: 50px;
background-color: #008CBA;
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 4px 2px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.spell-button:disabled {
background-color: #555;
cursor: not-allowed;
}
.cooldown-progress {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0;
background-color: rgba(0, 0, 0, 0.5);
transition: width linear;
}
#spellbook {
width: 100%;
padding: 10px;
background-color: #333;
border: none;
color: white;
font-size: 16px;
margin-top: 10px;
}
#spell-info {
margin-top: 10px;
padding: 10px;
background-color: #444;
border-radius: 5px;
display: none;
}
</style>
</head>
<body>
<div id="game-container">
<div id="combat-window">
<div id="allies"></div>
<div id="boss">
<div id="boss-health-bar" class="health-bar">
<div class="health-bar-text">Boss HP: 5000/5000</div>
</div>
</div>
</div>
<div id="spell-buttons"></div>
<select id="spellbook">
<option value="">Spellbook - Select a spell for info</option>
<option value="0">Quick Heal</option>
<option value="1">Strong Heal</option>
<option value="2">Healing Stream</option>
<option value="3">Chain Heal</option>
<option value="4">Team Heal</option>
</select>
<div id="spell-info"></div>
</div>
<script>
const allies = [];
let boss = { hp: 5000, maxHp: 5000 };
let selectedAlly = null;
let globalCooldown = false;
const spells = [
{ name: "Quick Heal", cooldown: 1.5, heal: 10, description: "Heals the target for 10 HP. Global cooldown: 1.5 seconds." },
{ name: "Strong Heal", cooldown: 15, heal: 30, description: "Heals the target for 30 HP. Cooldown: 15 seconds." },
{ name: "Healing Stream", cooldown: 45, heal: 3, duration: 10, interval: 0.5, description: "Heals the target for 3 HP every 0.5 seconds for 10 seconds. Cooldown: 45 seconds." },
{ name: "Chain Heal", cooldown: 15, heal: 10, targets: 3, description: "Heals 3 random allies for 10 HP each. Cooldown: 15 seconds." },
{ name: "Team Heal", cooldown: 120, heal: 50, description: "Heals all allies for 50 HP. Cooldown: 2 minutes." }
];
function createAlly(id) {
return { id, hp: 100, maxHp: 100 };
}
function updateHealthBar(entity, barElement) {
const percentage = (entity.hp / entity.maxHp) * 100;
barElement.style.width = `${percentage}%`;
barElement.querySelector('.health-bar-text').textContent = `HP: ${entity.hp}/${entity.maxHp}`;
}
function createAllies() {
const alliesContainer = document.getElementById('allies');
for (let i = 0; i < 5; i++) {
const ally = createAlly(i);
allies.push(ally);
const healthBar = document.createElement('div');
healthBar.className = 'health-bar';
healthBar.innerHTML = `<div class="health-bar-text">Ally ${i + 1} HP: 100/100</div>`;
healthBar.onclick = () => selectAlly(i);
alliesContainer.appendChild(healthBar);
updateHealthBar(ally, healthBar);
}
}
function selectAlly(index) {
const healthBars = document.querySelectorAll('#allies .health-bar');
healthBars.forEach(bar => bar.classList.remove('selected'));
healthBars[index].classList.add('selected');
selectedAlly = allies[index];
updateSpellButtons();
}
function createSpellButtons() {
const spellButtonsContainer = document.getElementById('spell-buttons');
spells.forEach((spell, index) => {
const button = document.createElement('button');
button.className = 'spell-button';
button.innerHTML = `${spell.name}<div class="cooldown-progress"></div>`;
button.onclick = () => castSpell(index);
button.disabled = true;
spellButtonsContainer.appendChild(button);
});
}
function updateSpellButtons() {
const spellButtons = document.querySelectorAll('.spell-button');
spellButtons.forEach((button, index) => {
button.disabled = !selectedAlly || globalCooldown || button.classList.contains('on-cooldown');
});
}
function castSpell(spellIndex) {
if (selectedAlly && !globalCooldown && !document.querySelectorAll('.spell-button')[spellIndex].classList.contains('on-cooldown')) {
const spell = spells[spellIndex];
switch (spellIndex) {
case 0:
case 1:
healAlly(selectedAlly, spell.heal);
break;
case 2:
startHealingStream(selectedAlly, spell);
break;
case 3:
chainHeal(spell);
break;
case 4:
teamHeal(spell);
break;
}
startSpellCooldown(spellIndex);
startGlobalCooldown();
}
}
function healAlly(ally, amount) {
ally.hp = Math.min(ally.hp + amount, ally.maxHp);
updateHealthBar(ally, document.querySelectorAll('.health-bar')[ally.id]);
}
function startHealingStream(ally, spell) {
let ticks = spell.duration / spell.interval;
function tick() {
if (ticks > 0) {
healAlly(ally, spell.heal);
ticks--;
setTimeout(tick, spell.interval * 1000);
}
}
tick();
}
function chainHeal(spell) {
const targets = allies.sort(() => 0.5 - Math.random()).slice(0, spell.targets);
targets.forEach(ally => healAlly(ally, spell.heal));
}
function teamHeal(spell) {
allies.forEach(ally => healAlly(ally, spell.heal));
}
function startSpellCooldown(spellIndex) {
const button = document.querySelectorAll('.spell-button')[spellIndex];
const progressBar = button.querySelector('.cooldown-progress');
button.classList.add('on-cooldown');
progressBar.style.transition = `width ${spells[spellIndex].cooldown}s linear`;
progressBar.style.width = '100%';
setTimeout(() => {
button.classList.remove('on-cooldown');
progressBar.style.width = '0';
updateSpellButtons();
}, spells[spellIndex].cooldown * 1000);
}
function startGlobalCooldown() {
globalCooldown = true;
updateSpellButtons();
setTimeout(() => {
globalCooldown = false;
updateSpellButtons();
}, 1500);
}
function bossDamage() {
const damageAmount = 8;
const targetAlly = allies[Math.floor(Math.random() * allies.length)];
targetAlly.hp = Math.max(targetAlly.hp - damageAmount, 0);
updateHealthBar(targetAlly, document.querySelectorAll('.health-bar')[targetAlly.id]);
}
function gameLoop() {
bossDamage();
setTimeout(gameLoop, 1000);
}
document.addEventListener('keydown', (event) => {
const key = event.key;
if (key >= '1' && key <= '5') {
castSpell(parseInt(key) - 1);
}
});
document.getElementById('spellbook').addEventListener('change', (event) => {
const spellIndex = event.target.value;
const spellInfo = document.getElementById('spell-info');
if (spellIndex !== "") {
spellInfo.textContent = spells[spellIndex].description;
spellInfo.style.display = 'block';
} else {
spellInfo.style.display = 'none';
}
});
createAllies();
createSpellButtons();
updateHealthBar(boss, document.getElementById('boss-health-bar'));
gameLoop();
</script>
</body>
</html> |