File size: 44,141 Bytes
6f90d62 | 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 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AvaRush - Adventure Match Game</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
overflow-x: hidden;
}
.game-container {
max-width: 1200px;
margin: 0 auto;
padding: 10px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
padding: 15px 20px;
border-radius: 15px;
margin-bottom: 10px;
}
.logo {
font-size: 2.5em;
font-weight: bold;
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.nav-buttons {
display: flex;
gap: 10px;
}
.nav-btn {
padding: 10px 20px;
background: linear-gradient(45deg, #ff6b6b, #ee5a52);
color: white;
border: none;
border-radius: 25px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease;
}
.nav-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.game-area {
display: flex;
gap: 20px;
height: 600px;
}
.left-panel, .right-panel {
width: 200px;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 20px;
color: white;
}
.game-board {
flex: 1;
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.score-info {
text-align: right;
margin-bottom: 20px;
}
.score-item {
background: rgba(255, 255, 255, 0.2);
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
}
.moves-info {
text-align: left;
margin-bottom: 20px;
}
.canvas-container {
position: relative;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
canvas {
display: block;
background: #2c3e50;
}
.game-controls {
display: flex;
gap: 10px;
margin-top: 20px;
}
.control-btn {
padding: 15px 30px;
font-size: 18px;
border: none;
border-radius: 25px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease;
}
.play-btn {
background: linear-gradient(45deg, #4ecdc4, #44a08d);
color: white;
}
.pause-btn {
background: linear-gradient(45deg, #ffa726, #ff7043);
color: white;
}
.control-btn:hover {
transform: scale(1.05);
}
.objective-info {
background: rgba(255, 255, 255, 0.2);
padding: 15px;
border-radius: 10px;
text-align: center;
color: white;
font-weight: bold;
margin-bottom: 20px;
}
.level-info {
text-align: center;
margin: 20px 0;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
z-index: 1000;
}
.modal-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30px;
border-radius: 20px;
color: white;
text-align: center;
min-width: 300px;
}
.toast {
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(45deg, #4ecdc4, #44a08d);
color: white;
padding: 15px 25px;
border-radius: 10px;
z-index: 1001;
transform: translateX(400px);
transition: transform 0.3s ease;
}
.toast.show {
transform: translateX(0);
}
.gem {
width: 40px;
height: 40px;
border-radius: 8px;
display: inline-block;
margin: 2px;
cursor: pointer;
transition: all 0.2s ease;
}
.gem:hover {
transform: scale(1.1);
}
.gem-red { background: linear-gradient(45deg, #ff6b6b, #ee5a52); }
.gem-blue { background: linear-gradient(45deg, #4ecdc4, #44a08d); }
.gem-green { background: linear-gradient(45deg, #a8e6cf, #88d8a3); }
.gem-yellow { background: linear-gradient(45deg, #ffd93d, #ffb74d); }
.gem-purple { background: linear-gradient(45deg, #b19cd9, #9b59b6); }
.gem-ice { background: linear-gradient(45deg, #e3f2fd, #bbdefb); border: 2px solid #2196f3; }
.modal-buttons {
display: flex;
gap: 15px;
justify-content: center;
margin-top: 20px;
}
.modal-btn {
padding: 10px 20px;
border: none;
border-radius: 20px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s ease;
}
.close-btn {
background: #e74c3c;
color: white;
}
.continue-btn {
background: #27ae60;
color: white;
}
</style>
</head>
<body>
<div class="game-container">
<div class="header">
<div class="logo">AvaRush</div>
<div class="nav-buttons">
<button class="nav-btn" onclick="showModal('shop')">Shop</button>
<button class="nav-btn" onclick="showModal('equip')">Equip</button>
<button class="nav-btn" onclick="showModal('friends')">Friends</button>
<button class="nav-btn" onclick="showModal('tasks')">Tasks</button>
<button class="nav-btn" onclick="showModal('rating')">Rating</button>
<button class="nav-btn" onclick="showModal('boosters')">Boosters</button>
<button class="nav-btn" onclick="showModal('skins')">Skins</button>
</div>
</div>
<div class="game-area">
<div class="left-panel">
<div class="moves-info">
<h3>Moves</h3>
<div class="score-item">
<div style="font-size: 2em; color: #4ecdc4;" id="moves-count">25</div>
</div>
</div>
<div class="objective-info">
<div>Crush Ice</div>
<div style="font-size: 1.5em; color: #4ecdc4;" id="ice-count">0/28</div>
</div>
<div class="level-info">
<h3>Level</h3>
<div style="font-size: 2em; color: #ffd93d;" id="player-level">1</div>
<div style="font-size: 0.9em; margin-top: 5px;" id="map-name">Forest Valley</div>
</div>
</div>
<div class="game-board">
<div class="canvas-container">
<canvas id="gameCanvas" width="480" height="480"></canvas>
</div>
<div class="game-controls">
<button class="control-btn pause-btn" onclick="pauseGame()" id="pauseBtn">Pause</button>
<button class="control-btn play-btn" onclick="playGame()" id="playBtn" style="display: none;">Play</button>
</div>
</div>
<div class="right-panel">
<div class="score-info">
<h3>Score</h3>
<div class="score-item">
<div style="font-size: 2em; color: #ff6b6b;" id="score">0</div>
</div>
<div class="score-item">
<div>High Score</div>
<div style="color: #ffd93d;" id="high-score">1250</div>
</div>
<div class="score-item">
<div>Level Progress</div>
<div style="color: #4ecdc4;" id="level-progress">Level 1/30</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modals -->
<div id="modal" class="modal">
<div class="modal-content">
<div id="modal-title"></div>
<div id="modal-body"></div>
<div class="modal-buttons">
<button class="modal-btn close-btn" onclick="closeModal()">Close</button>
</div>
</div>
</div>
<!-- Toast Notification -->
<div id="toast" class="toast"></div>
<script>
// Game state
let gameState = {
score: 0,
moves: 25,
level: 1,
iceCount: 0,
iceTarget: 28,
isPaused: false,
currentMap: 'forest',
gems: [],
selectedGem: null,
animations: [],
fallingGems: [],
isAnimating: false
};
// Audio context for sound effects
let audioContext;
function initAudio() {
try {
audioContext = new (window.AudioContext || window.webkitAudioContext)();
} catch (e) {
console.log('Audio not supported');
}
}
function playSound(frequency, duration, type = 'sine') {
if (!audioContext) return;
const oscillator = audioContext.createOscillator();
const gainNode = audioContext.createGain();
oscillator.connect(gainNode);
gainNode.connect(audioContext.destination);
oscillator.frequency.setValueAtTime(frequency, audioContext.currentTime);
oscillator.type = type;
gainNode.gain.setValueAtTime(0.1, audioContext.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + duration);
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + duration);
}
function playMatchSound() {
// Pleasant chime sound for matches
playSound(523.25, 0.2); // C5
setTimeout(() => playSound(659.25, 0.2), 100); // E5
setTimeout(() => playSound(783.99, 0.3), 200); // G5
}
function playDropSound() {
// Soft drop sound
playSound(220, 0.15, 'triangle');
}
function playIceBreakSound() {
// Crystal break sound
playSound(1000, 0.1, 'square');
setTimeout(() => playSound(800, 0.1, 'square'), 50);
setTimeout(() => playSound(600, 0.1, 'square'), 100);
}
// Game maps with different backgrounds
const maps = {
forest: { name: 'Forest Valley', bg: '#2d5016', levels: [1,2,3,4,5,6,7,8,9,10] },
desert: { name: 'Desert Oasis', bg: '#8b4513', levels: [11,12,13,14,15,16,17,18,19,20] },
skylands: { name: 'Sky Realm', bg: '#4169e1', levels: [21,22,23,24,25,26,27,28,29,30] }
};
// Canvas setup
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const gridSize = 8;
const gemSize = 60;
// Game elements (natural themed)
const gemTypes = ['wood', 'water', 'snake', 'bee', 'whale', 'fish'];
const gemColors = {
wood: '#8B4513',
water: '#4682B4',
snake: '#228B22',
bee: '#FFD700',
whale: '#4169E1',
fish: '#FF6347'
};
// Initialize game
function initGame() {
createGemGrid();
updateUI();
updateMapTheme();
gameLoop();
}
function createGemGrid() {
gameState.gems = [];
for (let row = 0; row < gridSize; row++) {
gameState.gems[row] = [];
for (let col = 0; col < gridSize; col++) {
gameState.gems[row][col] = {
type: gemTypes[Math.floor(Math.random() * gemTypes.length)],
x: col * gemSize,
y: row * gemSize,
isIce: Math.random() < 0.1 // 10% chance for ice blocks
};
}
}
// Add some ice gems for the objective
addIceGems();
}
function addIceGems() {
let iceAdded = 0;
while (iceAdded < gameState.iceTarget && iceAdded < 15) {
const row = Math.floor(Math.random() * gridSize);
const col = Math.floor(Math.random() * gridSize);
if (!gameState.gems[row][col].isIce) {
gameState.gems[row][col].isIce = true;
iceAdded++;
}
}
}
function drawGame() {
// Clear canvas with map-specific background
const currentMapData = Object.values(maps).find(map =>
map.levels.includes(gameState.level)
) || maps.forest;
ctx.fillStyle = currentMapData.bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw grid background
ctx.strokeStyle = 'rgba(255,255,255,0.1)';
ctx.lineWidth = 1;
for (let i = 0; i <= gridSize; i++) {
ctx.beginPath();
ctx.moveTo(i * gemSize, 0);
ctx.lineTo(i * gemSize, canvas.height);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i * gemSize);
ctx.lineTo(canvas.width, i * gemSize);
ctx.stroke();
}
// Draw gems (including falling ones)
for (let row = 0; row < gridSize; row++) {
for (let col = 0; col < gridSize; col++) {
const gem = gameState.gems[row][col];
if (gem && !gem.isMatched) {
drawGem(gem, col * gemSize, row * gemSize);
}
}
}
// Draw falling gems with animation
gameState.fallingGems.forEach(fallingGem => {
drawGem(fallingGem.gem, fallingGem.x, fallingGem.y);
});
// Draw match animations
gameState.animations.forEach(animation => {
drawMatchAnimation(animation);
});
// Highlight selected gem
if (gameState.selectedGem && !gameState.isAnimating) {
const { row, col } = gameState.selectedGem;
ctx.strokeStyle = '#fff';
ctx.lineWidth = 3;
ctx.strokeRect(col * gemSize + 2, row * gemSize + 2, gemSize - 4, gemSize - 4);
}
}
function drawMatchAnimation(animation) {
const progress = (Date.now() - animation.startTime) / animation.duration;
if (progress >= 1) return;
const alpha = 1 - progress;
const scale = 1 + progress * 0.5;
ctx.save();
ctx.globalAlpha = alpha;
ctx.translate(animation.x + gemSize/2, animation.y + gemSize/2);
ctx.scale(scale, scale);
ctx.translate(-gemSize/2, -gemSize/2);
// Draw sparkle effect
ctx.fillStyle = '#FFD700';
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const x = Math.cos(angle) * 20 * progress;
const y = Math.sin(angle) * 20 * progress;
ctx.beginPath();
ctx.arc(gemSize/2 + x, gemSize/2 + y, 3, 0, Math.PI * 2);
ctx.fill();
}
ctx.restore();
}
function drawGem(gem, x, y) {
const padding = 4;
const size = gemSize - padding * 2;
const centerX = x + padding + size/2;
const centerY = y + padding + size/2;
ctx.save();
// Draw different shapes based on gem type
switch(gem.type) {
case 'wood':
drawWood(centerX, centerY, size);
break;
case 'water':
drawWaterDrop(centerX, centerY, size);
break;
case 'snake':
drawSnake(centerX, centerY, size);
break;
case 'bee':
drawBee(centerX, centerY, size);
break;
case 'whale':
drawWhale(centerX, centerY, size);
break;
case 'fish':
drawFish(centerX, centerY, size);
break;
}
// Draw ice overlay if applicable
if (gem.isIce) {
ctx.strokeStyle = '#87CEEB';
ctx.lineWidth = 3;
ctx.strokeRect(x + padding, y + padding, size, size);
// Ice crystal pattern
ctx.strokeStyle = 'rgba(135, 206, 235, 0.7)';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(centerX, y + padding);
ctx.lineTo(centerX, y + padding + size);
ctx.moveTo(x + padding, centerY);
ctx.lineTo(x + padding + size, centerY);
ctx.moveTo(x + padding + size/4, y + padding + size/4);
ctx.lineTo(x + padding + 3*size/4, y + padding + 3*size/4);
ctx.moveTo(x + padding + 3*size/4, y + padding + size/4);
ctx.lineTo(x + padding + size/4, y + padding + 3*size/4);
ctx.stroke();
}
ctx.restore();
}
function drawWood(centerX, centerY, size) {
const radius = size * 0.4;
// Wood background
const gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
gradient.addColorStop(0, '#D2691E');
gradient.addColorStop(1, '#8B4513');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(centerX, centerY, radius, 0, Math.PI * 2);
ctx.fill();
// Wood rings
ctx.strokeStyle = '#654321';
ctx.lineWidth = 2;
for(let i = 1; i <= 3; i++) {
ctx.beginPath();
ctx.arc(centerX, centerY, radius * 0.3 * i, 0, Math.PI * 2);
ctx.stroke();
}
}
function drawWaterDrop(centerX, centerY, size) {
const radius = size * 0.4;
// Water drop shape
const gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, radius);
gradient.addColorStop(0, '#87CEEB');
gradient.addColorStop(1, '#4682B4');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(centerX, centerY + radius * 0.2, radius * 0.8, 0, Math.PI * 2);
ctx.moveTo(centerX, centerY - radius);
ctx.quadraticCurveTo(centerX - radius * 0.5, centerY, centerX, centerY + radius * 0.2);
ctx.quadraticCurveTo(centerX + radius * 0.5, centerY, centerX, centerY - radius);
ctx.fill();
// Highlight
ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
ctx.beginPath();
ctx.arc(centerX - radius * 0.3, centerY - radius * 0.3, radius * 0.2, 0, Math.PI * 2);
ctx.fill();
}
function drawSnake(centerX, centerY, size) {
const radius = size * 0.15;
// Snake body (S-curve)
ctx.strokeStyle = '#228B22';
ctx.lineWidth = radius;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(centerX - size * 0.3, centerY - size * 0.2);
ctx.quadraticCurveTo(centerX + size * 0.2, centerY - size * 0.1, centerX, centerY);
ctx.quadraticCurveTo(centerX - size * 0.2, centerY + size * 0.1, centerX + size * 0.3, centerY + size * 0.2);
ctx.stroke();
// Snake head
ctx.fillStyle = '#32CD32';
ctx.beginPath();
ctx.arc(centerX + size * 0.3, centerY + size * 0.2, radius * 1.2, 0, Math.PI * 2);
ctx.fill();
// Eyes
ctx.fillStyle = '#000';
ctx.beginPath();
ctx.arc(centerX + size * 0.25, centerY + size * 0.15, 2, 0, Math.PI * 2);
ctx.arc(centerX + size * 0.35, centerY + size * 0.15, 2, 0, Math.PI * 2);
ctx.fill();
}
function drawBee(centerX, centerY, size) {
const bodyWidth = size * 0.6;
const bodyHeight = size * 0.3;
// Bee body
ctx.fillStyle = '#FFD700';
ctx.beginPath();
ctx.ellipse(centerX, centerY, bodyWidth/2, bodyHeight/2, 0, 0, Math.PI * 2);
ctx.fill();
// Black stripes
ctx.fillStyle = '#000';
for(let i = 0; i < 3; i++) {
ctx.fillRect(centerX - bodyWidth/2 + i * bodyWidth/3, centerY - bodyHeight/2, bodyWidth/6, bodyHeight);
}
// Wings
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
ctx.beginPath();
ctx.ellipse(centerX - bodyWidth/4, centerY - bodyHeight/2, bodyWidth/3, bodyHeight/3, -Math.PI/6, 0, Math.PI * 2);
ctx.ellipse(centerX + bodyWidth/4, centerY - bodyHeight/2, bodyWidth/3, bodyHeight/3, Math.PI/6, 0, Math.PI * 2);
ctx.fill();
// Head
ctx.fillStyle = '#FFD700';
ctx.beginPath();
ctx.arc(centerX, centerY - bodyHeight/2, bodyHeight/3, 0, Math.PI * 2);
ctx.fill();
}
function drawWhale(centerX, centerY, size) {
const bodyWidth = size * 0.7;
const bodyHeight = size * 0.4;
// Whale body
const gradient = ctx.createLinearGradient(centerX - bodyWidth/2, centerY, centerX + bodyWidth/2, centerY);
gradient.addColorStop(0, '#4169E1');
gradient.addColorStop(1, '#191970');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.ellipse(centerX, centerY, bodyWidth/2, bodyHeight/2, 0, 0, Math.PI * 2);
ctx.fill();
// Tail
ctx.beginPath();
ctx.moveTo(centerX + bodyWidth/2, centerY);
ctx.lineTo(centerX + bodyWidth/2 + size * 0.2, centerY - size * 0.15);
ctx.lineTo(centerX + bodyWidth/2 + size * 0.2, centerY + size * 0.15);
ctx.closePath();
ctx.fill();
// Eye
ctx.fillStyle = '#FFF';
ctx.beginPath();
ctx.arc(centerX - bodyWidth/4, centerY - bodyHeight/4, 4, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#000';
ctx.beginPath();
ctx.arc(centerX - bodyWidth/4, centerY - bodyHeight/4, 2, 0, Math.PI * 2);
ctx.fill();
// Water spout
ctx.strokeStyle = '#87CEEB';
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(centerX, centerY - bodyHeight/2);
ctx.lineTo(centerX, centerY - bodyHeight/2 - size * 0.2);
ctx.stroke();
}
function drawFish(centerX, centerY, size) {
const bodyWidth = size * 0.6;
const bodyHeight = size * 0.4;
// Fish body
const gradient = ctx.createRadialGradient(centerX, centerY, 0, centerX, centerY, bodyWidth/2);
gradient.addColorStop(0, '#FFA500');
gradient.addColorStop(1, '#FF6347');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.ellipse(centerX, centerY, bodyWidth/2, bodyHeight/2, 0, 0, Math.PI * 2);
ctx.fill();
// Tail
ctx.beginPath();
ctx.moveTo(centerX + bodyWidth/2, centerY);
ctx.lineTo(centerX + bodyWidth/2 + size * 0.25, centerY - size * 0.2);
ctx.lineTo(centerX + bodyWidth/2 + size * 0.15, centerY);
ctx.lineTo(centerX + bodyWidth/2 + size * 0.25, centerY + size * 0.2);
ctx.closePath();
ctx.fill();
// Fins
ctx.beginPath();
ctx.moveTo(centerX - bodyWidth/4, centerY + bodyHeight/2);
ctx.lineTo(centerX - bodyWidth/4 - size * 0.1, centerY + bodyHeight/2 + size * 0.15);
ctx.lineTo(centerX, centerY + bodyHeight/2);
ctx.closePath();
ctx.fill();
// Eye
ctx.fillStyle = '#FFF';
ctx.beginPath();
ctx.arc(centerX - bodyWidth/4, centerY - bodyHeight/6, 5, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = '#000';
ctx.beginPath();
ctx.arc(centerX - bodyWidth/4, centerY - bodyHeight/6, 3, 0, Math.PI * 2);
ctx.fill();
// Scales pattern
ctx.strokeStyle = 'rgba(255, 255, 255, 0.3)';
ctx.lineWidth = 1;
for(let i = 0; i < 3; i++) {
ctx.beginPath();
ctx.arc(centerX - bodyWidth/4 + i * bodyWidth/6, centerY, bodyWidth/8, 0, Math.PI * 2);
ctx.stroke();
}
}
function darkenColor(color, amount) {
const num = parseInt(color.replace("#", ""), 16);
const amt = Math.round(2.55 * amount * 100);
const R = (num >> 16) - amt;
const G = (num >> 8 & 0x00FF) - amt;
const B = (num & 0x0000FF) - amt;
return "#" + (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
(G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
(B < 255 ? B < 1 ? 0 : B : 255)).toString(16).slice(1);
}
// Game loop
function gameLoop() {
if (!gameState.isPaused) {
updateAnimations();
drawGame();
}
requestAnimationFrame(gameLoop);
}
function updateAnimations() {
// Update falling gems
gameState.fallingGems = gameState.fallingGems.filter(fallingGem => {
fallingGem.y += fallingGem.speed;
fallingGem.speed += 0.5; // Gravity effect
const targetY = fallingGem.targetRow * gemSize;
if (fallingGem.y >= targetY) {
fallingGem.y = targetY;
gameState.gems[fallingGem.targetRow][fallingGem.col] = fallingGem.gem;
playDropSound();
return false; // Remove from falling gems array
}
return true;
});
// Update match animations
gameState.animations = gameState.animations.filter(animation => {
return (Date.now() - animation.startTime) < animation.duration;
});
// Check if all animations are done
if (gameState.fallingGems.length === 0 && gameState.animations.length === 0 && gameState.isAnimating) {
gameState.isAnimating = false;
// Check for new matches after gems have fallen
setTimeout(() => {
const newMatches = findMatches();
if (newMatches.length > 0) {
processMatches(newMatches);
}
}, 200);
}
}
// Mouse handling
canvas.addEventListener('click', function(e) {
if (gameState.isPaused) return;
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const col = Math.floor(x / gemSize);
const row = Math.floor(y / gemSize);
if (row >= 0 && row < gridSize && col >= 0 && col < gridSize) {
handleGemClick(row, col);
}
});
function handleGemClick(row, col) {
if (gameState.isAnimating) return; // Don't allow clicks during animations
if (!gameState.selectedGem) {
gameState.selectedGem = { row, col };
} else {
const selected = gameState.selectedGem;
if (selected.row === row && selected.col === col) {
gameState.selectedGem = null;
} else if (isAdjacent(selected, { row, col })) {
swapGems(selected, { row, col });
gameState.selectedGem = null;
} else {
gameState.selectedGem = { row, col };
}
}
}
function isAdjacent(gem1, gem2) {
const rowDiff = Math.abs(gem1.row - gem2.row);
const colDiff = Math.abs(gem1.col - gem2.col);
return (rowDiff === 1 && colDiff === 0) || (rowDiff === 0 && colDiff === 1);
}
function swapGems(gem1, gem2) {
const temp = gameState.gems[gem1.row][gem1.col];
gameState.gems[gem1.row][gem1.col] = gameState.gems[gem2.row][gem2.col];
gameState.gems[gem2.row][gem2.col] = temp;
const matches = findMatches();
if (matches.length > 0) {
gameState.moves--;
processMatches(matches);
updateUI();
showToast('Great match!');
} else {
// Swap back if no matches
const temp = gameState.gems[gem1.row][gem1.col];
gameState.gems[gem1.row][gem1.col] = gameState.gems[gem2.row][gem2.col];
gameState.gems[gem2.row][gem2.col] = temp;
showToast('No matches found!');
}
}
function findMatches() {
const matches = [];
// Check horizontal matches
for (let row = 0; row < gridSize; row++) {
let count = 1;
let currentType = gameState.gems[row][0].type;
for (let col = 1; col < gridSize; col++) {
if (gameState.gems[row][col].type === currentType) {
count++;
} else {
if (count >= 3) {
for (let i = col - count; i < col; i++) {
matches.push({ row, col: i });
}
}
count = 1;
currentType = gameState.gems[row][col].type;
}
}
if (count >= 3) {
for (let i = gridSize - count; i < gridSize; i++) {
matches.push({ row, col: i });
}
}
}
// Check vertical matches
for (let col = 0; col < gridSize; col++) {
let count = 1;
let currentType = gameState.gems[0][col].type;
for (let row = 1; row < gridSize; row++) {
if (gameState.gems[row][col].type === currentType) {
count++;
} else {
if (count >= 3) {
for (let i = row - count; i < row; i++) {
matches.push({ row: i, col });
}
}
count = 1;
currentType = gameState.gems[row][col].type;
}
}
if (count >= 3) {
for (let i = gridSize - count; i < gridSize; i++) {
matches.push({ row: i, col });
}
}
}
return matches;
}
function processMatches(matches) {
let iceDestroyed = 0;
gameState.isAnimating = true;
// Mark matched gems and create animations
matches.forEach(match => {
const gem = gameState.gems[match.row][match.col];
if (gem.isIce) {
iceDestroyed++;
playIceBreakSound();
}
// Create match animation
gameState.animations.push({
x: match.col * gemSize,
y: match.row * gemSize,
startTime: Date.now(),
duration: 500
});
// Mark gem as matched (will be replaced)
gameState.gems[match.row][match.col].isMatched = true;
});
// Play match sound
playMatchSound();
// Update score and ice count
gameState.iceCount += iceDestroyed;
gameState.score += matches.length * 100 + iceDestroyed * 200;
// Start dropping animation after a brief delay
setTimeout(() => {
applyGravity();
fillEmptySpaces();
}, 300);
if (gameState.iceCount >= gameState.iceTarget) {
setTimeout(() => {
levelComplete();
}, 1000);
}
}
function applyGravity() {
// Make gems fall down to fill empty spaces
for (let col = 0; col < gridSize; col++) {
const column = [];
// Collect non-matched gems from bottom to top
for (let row = gridSize - 1; row >= 0; row--) {
if (!gameState.gems[row][col].isMatched) {
column.push(gameState.gems[row][col]);
}
}
// Clear the column
for (let row = 0; row < gridSize; row++) {
gameState.gems[row][col] = null;
}
// Create falling animations for existing gems
column.forEach((gem, index) => {
const newRow = gridSize - 1 - index;
const currentRow = findGemCurrentRow(gem, col);
if (currentRow !== newRow && currentRow !== -1) {
gameState.fallingGems.push({
gem: gem,
x: col * gemSize,
y: currentRow * gemSize,
targetRow: newRow,
col: col,
speed: 2
});
} else {
gameState.gems[newRow][col] = gem;
}
});
}
}
function findGemCurrentRow(targetGem, col) {
for (let row = 0; row < gridSize; row++) {
if (gameState.gems[row][col] === targetGem) {
return row;
}
}
return -1;
}
function fillEmptySpaces() {
// Fill empty spaces with new gems
for (let col = 0; col < gridSize; col++) {
for (let row = 0; row < gridSize; row++) {
if (!gameState.gems[row][col]) {
const newGem = {
type: gemTypes[Math.floor(Math.random() * gemTypes.length)],
isIce: false,
isMatched: false
};
// Create falling animation for new gem
gameState.fallingGems.push({
gem: newGem,
x: col * gemSize,
y: -gemSize * (gridSize - row),
targetRow: row,
col: col,
speed: 2
});
}
}
}
}
function levelComplete() {
showToast('Level Complete!');
gameState.level++;
if (gameState.level > 30) {
showToast('Congratulations! Game Complete!');
gameState.level = 30;
} else {
setTimeout(() => {
initializeNewLevel();
}, 2000);
}
}
function initializeNewLevel() {
gameState.moves = 25;
gameState.iceCount = 0;
gameState.iceTarget = Math.min(28 + gameState.level * 2, 50);
updateMapTheme();
createGemGrid();
updateUI();
}
function updateMapTheme() {
let currentMap = 'forest';
if (gameState.level >= 11 && gameState.level <= 20) {
currentMap = 'desert';
} else if (gameState.level >= 21) {
currentMap = 'skylands';
}
gameState.currentMap = currentMap;
document.getElementById('map-name').textContent = maps[currentMap].name;
}
// UI Updates
function updateUI() {
document.getElementById('score').textContent = gameState.score;
document.getElementById('moves-count').textContent = gameState.moves;
document.getElementById('ice-count').textContent = `${gameState.iceCount}/${gameState.iceTarget}`;
document.getElementById('player-level').textContent = gameState.level;
document.getElementById('level-progress').textContent = `Level ${gameState.level}/30`;
}
// Game controls
function pauseGame() {
gameState.isPaused = true;
document.getElementById('pauseBtn').style.display = 'none';
document.getElementById('playBtn').style.display = 'block';
showToast('Game Paused');
}
function playGame() {
gameState.isPaused = false;
document.getElementById('pauseBtn').style.display = 'block';
document.getElementById('playBtn').style.display = 'none';
showToast('Game Resumed');
}
// Modal system
function showModal(type) {
const modal = document.getElementById('modal');
const title = document.getElementById('modal-title');
const body = document.getElementById('modal-body');
const modalContent = {
shop: {
title: 'ποΈ Shop',
body: '<p>Buy power-ups and boosters!</p><div style="margin: 20px 0;"><div>π Gems: 150</div><div>β‘ Energy Boost - 50 gems</div><div>π₯ Fire Boost - 75 gems</div><div>βοΈ Ice Breaker - 100 gems</div></div>'
},
equip: {
title: 'βοΈ Equipment',
body: '<p>Manage your power-ups and equipment!</p><div style="margin: 20px 0;"><div>π‘οΈ Equipped: Basic Hammer</div><div>β‘ Energy Boost: Ready</div><div>π₯ Fire Power: Cooldown 2 moves</div></div>'
},
friends: {
title: 'π₯ Friends',
body: '<p>Connect with friends and send lives!</p><div style="margin: 20px 0;"><div>π’ Alex_Gamer - Online</div><div>π‘ Sarah_123 - 5 min ago</div><div>π΄ Mike_Pro - 1 hour ago</div><button style="margin-top: 10px; padding: 5px 15px; background: #4ecdc4; border: none; border-radius: 15px; color: white;">Invite Friends</button></div>'
},
tasks: {
title: 'π Daily Tasks',
body: '<p>Complete tasks for rewards!</p><div style="margin: 20px 0;"><div>β
Play 3 levels - Completed</div><div>β³ Crush 50 ice blocks - 28/50</div><div>β³ Score 5000 points - 0/5000</div><div>β³ Use 5 power-ups - 0/5</div></div>'
},
rating: {
title: 'π Leaderboard',
body: '<p>Global Rankings</p><div style="margin: 20px 0;"><div>π₯ ProGamer99 - 45,230</div><div>π₯ MatchMaster - 42,100</div><div>π₯ GemCrusher - 38,950</div><div style="color: #4ecdc4;">π
You - 0 (Rank: 15,432)</div></div>'
},
boosters: {
title: 'π Boosters',
body: '<p>Activate powerful boosters!</p><div style="margin: 20px 0;"><div>β‘ Color Bomb - 3 left</div><div>πͺοΈ Line Blast - 2 left</div><div>βοΈ Ice Breaker - 1 left</div><div>π₯ Fire Storm - 0 left</div></div>'
},
skins: {
title: 'π¨ Skins & Themes',
body: '<p>Customize your game appearance!</p><div style="margin: 20px 0;"><div>π² Forest Theme - Active</div><div>ποΈ Desert Theme - Unlocked</div><div>βοΈ Sky Theme - Locked</div><div>π Galaxy Theme - Locked</div></div>'
}
};
const content = modalContent[type];
title.innerHTML = `<h2>${content.title}</h2>`;
body.innerHTML = content.body;
modal.style.display = 'block';
}
function closeModal() {
document.getElementById('modal').style.display = 'none';
}
// Toast notifications
function showToast(message) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('modal');
if (event.target === modal) {
closeModal();
}
}
// Initialize the game
initGame();
initAudio();
showToast('Welcome to AvaRush!');
</script>
</body>
</html> |