-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
642 lines (567 loc) · 25.5 KB
/
index.html
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pop-up Circles with Upgrade</title>
<style>
body {
margin: 0;
overflow: hidden;
position: relative;
}
canvas {
display: block;
border: 1px solid #000;
}
#topRightContent {
position: absolute;
top: 10px;
right: 10px;
font-size: 48px;
color: red;
}
#circlesCounter {
position: absolute;
top: 10px;
left: 10px;
font-size: 16px;
color: #333;
}
#upgradeButton {
position: absolute;
bottom: 50px;
right: 10px;
padding: 10px;
font-size: 16px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
#rarityUpgradeButton {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
font-size: 16px;
background-color: #ffa500;
color: white;
cursor: pointer;
}
#capacityUpgradeButton {
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
font-size: 16px;
background-color: #ffcc00;
color: white;
cursor: pointer;
}
#speedUpgradeButton {
position: absolute;
top: 50px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
font-size: 16px;
background-color: #4CAF50;
color: white;
cursor: pointer;
}
#critUpgradeButton {
position: absolute;
top: 90px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
font-size: 16px;
background-color: #ff0000;
color: white;
cursor: pointer;
}
#upgradeUpgradeButton {
position: absolute;
bottom: 10px;
right: 100px;
padding: 10px;
font-size: 16px;
background-color: #808080;
color: white;
cursor: pointer;
}
#saveButton {
position: absolute;
bottom: 10px;
left: 100px;
padding: 10px;
font-size: 16px;
background-color: #008CBA;
color: white;
cursor: pointer;
}
#loadButton {
position: absolute;
bottom: 10px;
left: 190px;
padding: 10px;
font-size: 16px;
background-color: #008CBA;
color: white;
cursor: pointer;
}
#autoclickButton {
position: absolute;
top: 10px;
left: 100px;
padding: 10px;
font-size: 16px;
background color: #A020F0;
color: white;
cursor: pointer;
}
#startScreen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
/* Change the image url below right here */
background-image: url('Media/Images/ccstitle.jpg');
background-size: 100% 100%;
background-position: center;
color: white;
}
#startScreen button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
border-radius: 10px;
transition: background-color 0.3s;
}
#startScreen button:hover {
background-color: #45a049;
}
#gameScreen {
display: none;
}
</style>
</head>
<body>
<!-- Start Screen -->
<div id="startScreen">
<button onclick="initializeGame()">Start Game</button>
</div>
<!-- Start Screen -->
<!-- Game Screen -->
<div id="gameScreen" style="display:none;">
<canvas id="canvas"></canvas>
<div id="topRightContent">0</div>
<div id="circlesCounter">Circles: 0</div>
<div id="upgradeButton" onclick="purchaseUpgrade()">Upgrade (Cost: <span id="upgradeCost">10</span> circles)</div>
<div id="rarityUpgradeButton" onclick="purchaseRarityUpgrade()">Rarity Upgrade (Cost: <span id="rarityUpgradeCost">20</span> circles)</div>
<div id="capacityUpgradeButton" onclick="purchaseCapacityUpgrade()">Capacity Upgrade (Cost: <span id="capacityUpgradeCost">5</span> circles)</div>
<div id="speedUpgradeButton" onclick="purchaseSpeedUpgrade()">Speed Upgrade (Cost: <span id="speedUpgradeCost">15</span> circles)</div>
<div id="critUpgradeButton" onclick="purchaseCritUpgrade()">Crit Upgrade (Cost: <span id="critUpgradeCost">25</span> circles)</div>
<div id="upgradeUpgradeButton" onclick="purchaseUpgradeUpgrade()">Upgrade Upgrade (Cost: <span id="upgradeUpgradeCost">300</span> circles)</div>
<div id="saveButton" onclick="saveGame()">Save</div>
<div id="loadButton" onclick="loadGame()">Load</div>
<script>
// Start Screen -> Game Screen Transition function
function initializeGame() {
document.getElementById("startScreen").style.display = "none";
document.getElementById("gameScreen").style.display = "block";
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const circles = [];
let score = 0;
let tapValue = 1;
let upgradeCost = 10;
let rarityUpgradeCost = 20;
let capacityUpgradeCost = 5;
let speedUpgradeCost = 15;
let critUpgradeCost = 25;
let upgradeUpgradeCost = 300; // Cost of Upgrade Upgrade
let maxCircles = 100;
let rarityBlue = 0.01; // 1% base chance for blue circles
let rarityGreen = 0.001; // 0.1% base chance for green circles
let rarityRed = 0.0001; // 0.01% base chance for red circles
let rarityGrey = 0.2; // 20% base chance for grey circles
let rarityYellow = 0.05; // 5% base chance for yellow circles
let rarityLime = 0.1; // 10% base chance for lime circles
let rarityOrange = 0.005; // 0.5% base chance for orange circles
let rarityPink = 0.0075;
let rarityTeal = 0.0005;
let rarityPurple = 0.0008;
let rarityAqua = 0.004;
let rarityMagenta = 0.00025;
let rarityMaroon = 0.025;
let rarityBrown = 0.35;
let rarityLavender = 0.008;
let rarityOlive = 0.1;
let rarityCoralXface = 0.00015;
let rarityPalegreen = 0.00025;
let rarityLightblue = 0.075;
let rarityKhaki = 0.12;
let critChanceReduction = 1; // Crit chance reduction in percentage
let baseCircleSpawnInterval = 2000; // Base circle spawn interval in milliseconds
let circleSpawnInterval = baseCircleSpawnInterval; // Initial circle spawn interval
const circleRadius = 50; // Set the desired radius for all circles
// New Audio
const audio = new Audio('Media/Audio/pop.mp3');
// Add event listeners for upgrade buttons
document.getElementById("upgradeButton").addEventListener("click", purchaseUpgrade);
document.getElementById("rarityUpgradeButton").addEventListener("click", purchaseRarityUpgrade);
document.getElementById("capacityUpgradeButton").addEventListener("click", purchaseCapacityUpgrade);
document.getElementById("speedUpgradeButton").addEventListener("click", purchaseSpeedUpgrade);
document.getElementById("critUpgradeButton").addEventListener("click", purchaseCritUpgrade);
document.getElementById("upgradeUpgradeButton").addEventListener("click", purchaseUpgradeUpgrade);
document.getElementById("saveButton").addEventListener("click", saveGame);
document.getElementById("loadButton").addEventListener("click", loadGame);
// Update upgrade costs
updateUpgradeCost();
updateRarityUpgradeCost();
updateCapacityUpgradeCost();
updateSpeedUpgradeCost();
updateCritUpgradeCost();
updateUpgradeUpgradeCost();
updateScore();
function Circle(x, y, color, valueMultiplier) {
this.x = x;
this.y = y;
this.radius = circleRadius;
this.color = color;
this.valueMultiplier = valueMultiplier || 1;
this.isCritical = false;
this.draw = function() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2);
if (this.color === 'red') {
// Add a glowing effect to the red circle
const gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.radius);
gradient.addColorStop(0, 'red');
gradient.addColorStop(0.8 + Math.sin(Date.now() / 300) * 0.1, 'rgba(255, 0, 0, 0.5)');
ctx.fillStyle = gradient;
} else {
ctx.fillStyle = this.color;
}
ctx.fill();
ctx.closePath();
// Display rarity in the middle of the circle
ctx.font = '12px Arial';
ctx.fillStyle = 'white';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
const shortScore = shortenNumber(score);
ctx.fillText(shortScore, this.x, this.y);
// Display "Critical" text if the circle is critical
if (this.isCritical) {
ctx.font = '18px Arial';
ctx.fillStyle = 'red';
ctx.fillText('Critical', this.x, this.y - this.radius - 10);
}
};
this.getRarityText = function() {
switch (this.color) {
case 'blue':
return 'Rare';
case 'green':
return 'Uncommon';
case 'red':
return 'Legendary';
case 'grey':
return 'Common';
case 'yellow':
return 'Semi-common';
default:
return 'Common';
}
};
this.isClicked = function(mouseX, mouseY) {
const distance = Math.sqrt(Math.pow(mouseX - this.x, 2) + Math.pow(mouseY - this.y, 2));
return distance <= this.radius;
};
this.showCriticalText = function() {
this.isCritical = true;
setTimeout(() => {
this.isCritical = false;
}, 2000);
};
}
function shortenNumber(num) {
if (num >= 1000000 && num < 10000000) {
return (num / 1000000).toFixed(1) + 'M';
} else if (num >= 10000000 && num < 100000000) {
return (num / 1000000).toFixed(0) + 'M';
} else if (num >= 100000000 && num < 1000000000) {
return (num / 1000000).toFixed(1) + 'M';
} else {
return num.toString();
}
}
function createCircle() {
if (circles.length < maxCircles) {
const x = Math.random() * (canvas.width - 2 * circleRadius) + circleRadius;
const y = Math.random() * (canvas.height - 2 * circleRadius) + circleRadius;
let color = 'black';
let valueMultiplier = 1;
// Use rarity values to determine the chance of different colored circles
const random = Math.random();
if (random < rarityBlue) {
color = 'blue';
valueMultiplier = 10; // Blue circle is worth 10x more
} else if (random < rarityBlue + rarityGreen) {
color = 'green';
valueMultiplier = 100; // Green circle is worth 100x more
} else if (random < rarityBlue + rarityGreen + rarityRed) {
color = 'red';
valueMultiplier = 1000; // Red circle is worth 1000x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey) {
color = 'grey';
valueMultiplier = 0.5; // Grey circle is worth half
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow) {
color = 'yellow';
valueMultiplier = 5; // Yellow circle is worth 5x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime) {
color = 'lime';
valueMultiplier = 2; // Lime circle is worth 5x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange) {
color = 'orange';
valueMultiplier = 50; // Orange circle is worth 5x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink) {
color = 'pink';
valueMultiplier = 15; // Pink circle is worth 15x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal) {
color = 'teal';
valueMultiplier = 500; // Teal circle is worth 500x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal + rarityPurple) {
color = 'purple';
valueMultiplier = 150; // Teal circle is worth 500x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal + rarityPurple + rarityAqua) {
color = 'aqua';
valueMultiplier = 40; // Teal circle is worth 500x more
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal + rarityPurple + rarityAqua + rarityMagenta) {
color = 'magenta';
valueMultiplier = 750; // Teal circle is worth 500x
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal + rarityPurple + rarityAqua + rarityMagenta + rarityLightblue) {
color = 'lightblue';
valueMultiplier = 3;
} else if (random < rarityBlue + rarityGreen + rarityRed + rarityGrey + rarityYellow + rarityLime + rarityOrange + rarityPink + rarityTeal + rarityPurple + rarityAqua + rarityMagenta + rarityLightblue + rarityKhaki) {
color = 'khaki';
valueMultiplier = 8;
}
ctx.fill();
ctx.closePath();
const circle = new Circle(x, y, color, valueMultiplier);
circles.push(circle);
// Check for critical hit
const criticalHitChance = 0.01 - critChanceReduction; // 1% chance of critical hit, reduced by Crit Upgrade
if (Math.random() < criticalHitChance) {
circle.showCriticalText();
circle.valueMultiplier *= 4; // Quadruple the circle's value for a critical hit
}
}
}
function drawCircles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (const circle of circles) {
circle.draw();
}
}
function update() {
if (Date.now() % circleSpawnInterval < 20 && circles.length < maxCircles) {
createCircle();
}
drawCircles();
updateScore();
updateCirclesCounter();
requestAnimationFrame(update);
}
function handleClick(event) {
const rect = canvas.getBoundingClientRect();
const mouseX = event.clientX - rect.left;
const mouseY = event.clientY - rect.top;
for (let i = circles.length - 1; i >= 0; i--) {
if (circles[i].isClicked(mouseX, mouseY)) {
score += tapValue * circles[i].valueMultiplier;
circles.splice(i, 1);
// Play audio
audio.play();
break; // Remove only one circle per click
}
}
}
function updateScore() {
const topRightContent = document.getElementById('topRightContent');
topRightContent.textContent = shortenNumber(score);
}
function updateCirclesCounter() {
const circlesCounter = document.getElementById('circlesCounter');
circlesCounter.textContent = `Circles: ${circles.length}`;
}
function purchaseUpgrade() {
if (score >= upgradeCost) {
score -= upgradeCost;
tapValue *= 2; // Double the circles per tap
upgradeCost *= 3; // Triple the cost for the next upgrade
updateUpgradeCost();
updateScore();
}
}
function purchaseRarityUpgrade() {
if (score >= rarityUpgradeCost) {
score -= rarityUpgradeCost;
rarityBlue += 0.01; // +1% chance for blue circles
rarityGreen += 0.001; // +0.1% chance for green circles
rarityRed += 0.0001; // +0.01% chance for red circles
rarityGrey -= 0.02; // -2% chance for grey circles
rarityYellow += 0.005; // +0.5% chance for yellow circles
rarityUpgradeCost *= 2; // Double the cost for the next rarity upgrade
updateRarityUpgradeCost();
updateScore();
}
}
function purchaseCapacityUpgrade() {
if (score >= capacityUpgradeCost) {
score -= capacityUpgradeCost;
maxCircles += 10; // Increase the base capacity by 10
capacityUpgradeCost *= 2; // Double the cost for the next capacity upgrade
updateCapacityUpgradeCost();
updateScore();
}
}
function purchaseSpeedUpgrade() {
if (score >= speedUpgradeCost) {
score -= speedUpgradeCost;
circleSpawnInterval -= 100; // Reduce the spawn interval by 100ms
speedUpgradeCost *= 2; // Double the cost for the next speed upgrade
updateSpeedUpgradeCost();
updateScore();
}
}
function purchaseCritUpgrade() {
if (score >= critUpgradeCost) {
score -= critUpgradeCost;
critChanceReduction += 1; // Reduce crit rarity by 1%
critUpgradeCost *= 2; // Double the cost for the next crit upgrade
updateCritUpgradeCost();
updateScore();
}
}
function purchaseUpgradeUpgrade() {
if (score >= upgradeUpgradeCost) {
score -= upgradeUpgradeCost;
// Here you can define how each upgrade will be more effective
// For example, double the effectiveness of the speed upgrade
circleSpawnInterval -= 50; // Reducing the spawn interval by 50ms in addition to the regular upgrade
rarityBlue += 0.01; // Increase the chance for blue circles by 1%
rarityGreen += 0.001; // Increase the chance for green circles by 0.1%
rarityRed += 0.0001; // Increase the chance for red circles by 0.01%
rarityGrey -= 0.02; // Decrease the chance for grey circles by 2%
rarityYellow += 0.005; // Increase the chance for yellow circles by 0.5%
// Similar changes can be made for other upgrades
upgradeUpgradeCost *= 5; // Increase the cost for the next upgrade upgrade
console.log("Upgrade upgrade purchased!");
updateUpgradeUpgradeCost();
updateScore();
}
}
function updateUpgradeCost() {
const upgradeCostElement = document.getElementById('upgradeCost');
upgradeCostElement.textContent = shortenNumber(upgradeCost);
}
function updateRarityUpgradeCost() {
const rarityUpgradeCostElement = document.getElementById('rarityUpgradeCost');
rarityUpgradeCostElement.textContent = shortenNumber(rarityUpgradeCost);
}
function updateCapacityUpgradeCost() {
const capacityUpgradeCostElement = document.getElementById('capacityUpgradeCost');
capacityUpgradeCostElement.textContent = shortenNumber(capacityUpgradeCost);
}
function updateSpeedUpgradeCost() {
const speedUpgradeCostElement = document.getElementById('speedUpgradeCost');
speedUpgradeCostElement.textContent = shortenNumber(speedUpgradeCost);
}
function updateCritUpgradeCost() {
const critUpgradeCostElement = document.getElementById('critUpgradeCost');
critUpgradeCostElement.textContent = shortenNumber(critUpgradeCost);
}
function updateUpgradeUpgradeCost() {
const upgradeUpgradeCostElement = document.getElementById('upgradeUpgradeCost');
upgradeUpgradeCostElement.textContent = shortenNumber(upgradeUpgradeCost);
}
function saveGame() {
const savedData = {
score,
tapValue,
upgradeCost,
rarityUpgradeCost,
capacityUpgradeCost,
speedUpgradeCost,
critUpgradeCost,
upgradeUpgradeCost,
maxCircles,
rarityBlue,
rarityGreen,
rarityRed,
rarityGrey,
rarityYellow,
circleSpawnInterval,
critChanceReduction
};
localStorage.setItem('gameData', JSON.stringify(savedData));
}
function loadGame() {
const savedData = localStorage.getItem('gameData');
if (savedData) {
const parsedData = JSON.parse(savedData);
score = parsedData.score || 0;
tapValue = parsedData.tapValue || 1;
upgradeCost = parsedData.upgradeCost || 10;
rarityUpgradeCost = parsedData.rarityUpgradeCost || 20;
capacityUpgradeCost = parsedData.capacityUpgradeCost || 5;
speedUpgradeCost = parsedData.speedUpgradeCost || 15;
critUpgradeCost = parsedData.critUpgradeCost || 25;
upgradeUpgradeCost = parsedData.upgradeUpgradeCost || 300;
maxCircles = parsedData.maxCircles || 100;
rarityBlue = parsedData.rarityBlue || 0.01;
rarityGreen = parsedData.rarityGreen || 0.001;
rarityRed = parsedData.rarityRed || 0.0001;
rarityGrey = parsedData.rarityGrey || 0.2;
rarityYellow = parsedData.rarityYellow || 0.05;
circleSpawnInterval = parsedData.circleSpawnInterval || baseCircleSpawnInterval;
critChanceReduction = parsedData.critChanceReduction || 1;
updateUpgradeCost();
updateRarityUpgradeCost();
updateCapacityUpgradeCost();
updateSpeedUpgradeCost();
updateCritUpgradeCost();
updateUpgradeUpgradeCost();
updateScore(); // Update displayed score after loading game data
}
}
function displayRarity(rarity) {
const rarityDisplay = document.getElementById('rarityDisplay');
rarityDisplay.textContent = `Rarity: ${rarity}`;
}
window.addEventListener('resize', () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
canvas.addEventListener('click', handleClick);
// Initial setup
window.dispatchEvent(new Event('resize'));
update();
}
</script>
</div>
</body>
</html>