-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
144 lines (129 loc) · 4.63 KB
/
script.js
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
let mass = 0;
let planetCount = 0;
let planetCost = 10;
let massPerClick = 1;
let achievements = [];
let planets = [];
const planetTypes = [
{ type: 'Earth-like Planet', filename: 'earth_like.webp', description: 'A vibrant, blue-green planet with visible oceans and continents.' },
{ type: 'Gas Giant', filename: 'gas_giant.webp', description: 'A large planet with a thick atmosphere, primarily composed of gases.' },
{ type: 'Desert Planet', filename: 'desert_planet.webp', description: 'A rocky, arid planet with a reddish or yellowish surface.' },
{ type: 'Ice Planet', filename: 'ice_planet.webp', description: 'A cold, icy world with a white or pale blue surface, covered in ice and snow.' },
{ type: 'Volcanic Planet', filename: 'volcanic_planet.webp', description: 'A fiery planet with active volcanoes, lava flows, and a glowing, molten surface.' }
];
function playSound(soundId) {
document.getElementById(soundId).play();
}
function generateMass() {
mass += massPerClick;
playSound('clickSound');
updateUI();
checkAchievements();
}
function buyPlanet() {
if (mass >= planetCost) {
mass -= planetCost;
playSound('clickSound');
planetCount++;
planetCost = Math.floor(planetCost * 1.5);
const planet = planetTypes[Math.floor(Math.random() * planetTypes.length)];
let newPlanet = {
name: planet.type,
count: 1,
massPerSecond: Math.floor(planetCost / 10),
image: planet.filename,
description: planet.description
};
let newPlanetName = true;
planets.forEach(planet => {
if (planet.name === newPlanet.name) {
newPlanetName = false;
planet.count += 1;
planet.massPerSecond += newPlanet.massPerSecond;
}
});
if (newPlanetName) {
planets.push(newPlanet);
}
updateUI();
checkAchievements();
}
}
function buyUpgrade() {
const upgradeCost = 50;
if (mass >= upgradeCost) {
mass -= upgradeCost;
playSound('clickSound');
massPerClick *= 2;
document.getElementById('upgradeBtn').style.display = 'none';
updateUI();
checkAchievements();
}
}
function checkAchievements() {
if (mass >= 100 && !achievements.includes('Mass Master')) {
achievements.push('Mass Master');
addAchievement('Mass Master');
}
if (planetCount >= 5 && !achievements.includes('Planet Pioneer')) {
achievements.push('Planet Pioneer');
addAchievement('Planet Pioneer');
}
}
function addAchievement(name) {
const achievementList = document.getElementById('achievementList');
const listItem = document.createElement('li');
listItem.textContent = name;
achievementList.appendChild(listItem);
playSound('achievementSound');
}
function updateBackground() {
const baseSize = 100; // base size percentage
const maxSize = 150; // maximum size percentage
const zoomFactor = Math.min(baseSize + planetCount, maxSize);
document.body.style.backgroundSize = `${zoomFactor}%`;
}
function toggleMusic() {
const music = document.getElementById('backgroundMusic');
if (music.paused) {
music.play();
} else {
music.pause();
}
}
function updateProgressBar() {
const progress = Math.min((mass / planetCost) * 100, 100);
document.getElementById('progressFill').style.width = `${progress}%`;
}
function updateUI() {
document.getElementById('mass').textContent = formatNumber(mass);
document.getElementById('planetCount').textContent = formatNumber(planetCount);
document.getElementById('planetCost').textContent = formatNumber(planetCost);
updatePlanetList();
updateBackground();
updateProgressBar();
}
function updatePlanetList() {
const planetList = document.getElementById('planetList');
planetList.innerHTML = '';
planets.forEach(planet => {
const listItem = document.createElement('li');
listItem.innerHTML = `${planet.name}s: ${formatNumber(planet.count)} - Mass per second: ${formatNumber(planet.massPerSecond)}
<br>
<img src="${planet.image}" alt="${planet.type}" title="${planet.description}" class="planet-img">
<p>${planet.description}</p>`;
planetList.appendChild(listItem);
});
}
// Utility function to format numbers with commas
function formatNumber(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Initial UI update
updateUI();
setInterval(() => {
planets.forEach(planet => {
mass += planet.massPerSecond;
});
updateUI();
}, 1000);