PAUTREL Johan commited on
Commit
782044b
·
verified ·
1 Parent(s): da91a31

Add 1 files

Browse files
Files changed (1) hide show
  1. index.html +61 -32
index.html CHANGED
@@ -29,18 +29,11 @@
29
  50% { transform: translateY(-10px); }
30
  }
31
 
32
- @keyframes moveRandom {
33
- 0% { transform: translate(0, 0); }
34
- 25% { transform: translate(100px, 80px); }
35
- 50% { transform: translate(50px, -50px); }
36
- 75% { transform: translate(-80px, 30px); }
37
- 100% { transform: translate(0, 0); }
38
- }
39
-
40
  .stain {
41
  animation: fadeIn 0.3s ease-in;
42
  transition: transform 0.2s;
43
  cursor: pointer;
 
44
  }
45
 
46
  .stain:hover {
@@ -48,11 +41,33 @@
48
  }
49
 
50
  .moving-stain {
51
- animation: moveRandom 3s linear infinite;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
 
54
  .game-container {
55
  background-image: linear-gradient(to bottom, #f0f9ff, #e0f2fe);
 
 
56
  }
57
 
58
  .progress-bar {
@@ -320,27 +335,28 @@
320
  gameInterval = setInterval(checkGameState, 500);
321
  }
322
 
323
- // Create a new stain (now covering the whole screen)
324
  function createStain() {
325
  if (!gameActive) return;
326
 
327
  const gameAreaRect = gameArea.getBoundingClientRect();
328
- const x = Math.random() * (gameAreaRect.width - 100);
329
- const y = Math.random() * (gameAreaRect.height - 100);
330
 
331
- // Determine if this should be a moving or penalty stain
 
 
 
 
332
  let stainTypeIndex;
333
 
334
- // Prevent too many penalty stains (max 1 penalty stain for every 3 normal stains)
335
  if (penaltyStainCount >= Math.ceil(stainCount / 3) && Math.random() < penaltyStainChance) {
336
  stainTypeIndex = Math.floor(Math.random() * (stainTypes.length - 2));
337
  } else {
338
- // Chance for moving stain (higher now)
339
  if (Math.random() < movingStainChance) {
340
  stainTypeIndex = Math.floor(Math.random() * (stainTypes.length - 2));
341
  }
342
 
343
- // Chance for penalty stain
344
  if (Math.random() < penaltyStainChance) {
345
  stainTypeIndex = Math.floor(Math.random() * 2) + (stainTypes.length - 2);
346
  } else {
@@ -351,26 +367,46 @@
351
  const stainType = stainTypes[stainTypeIndex];
352
 
353
  const stain = document.createElement('div');
354
- stain.className = `stain rounded-full absolute ${stainType.class} ${stainType.size}`;
355
- stain.style.left = `${x}px`;
356
- stain.style.top = `${y}px`;
357
-
358
- // Add moving class if needed (more stains will move now)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  if (stainType.moving || Math.random() < movingStainChance) {
360
  stain.classList.add('moving-stain');
 
 
361
  }
362
 
363
  // Add data attributes
364
  stain.dataset.points = stainType.points;
365
  stain.dataset.penalty = stainType.penalty;
366
 
 
 
 
 
367
  // Add click event
368
  stain.addEventListener('click', cleanStain);
369
 
370
  gameArea.appendChild(stain);
371
  stainCount++;
372
 
373
- // Track penalty stains
374
  if (stainType.penalty) {
375
  penaltyStainCount++;
376
  }
@@ -384,16 +420,13 @@
384
  const points = parseInt(stain.dataset.points);
385
  const isPenalty = stain.dataset.penalty === 'true';
386
 
387
- // Remove stain
388
  stain.remove();
389
  stainCount--;
390
 
391
- // Update penalty stain count
392
  if (isPenalty) {
393
  penaltyStainCount = Math.max(0, penaltyStainCount - 1);
394
  }
395
 
396
- // Update combo
397
  const now = Date.now();
398
  if (now - lastCleanTime < 1000) {
399
  combo++;
@@ -408,7 +441,6 @@
408
  }
409
  lastCleanTime = now;
410
 
411
- // Update score
412
  if (isPenalty) {
413
  score += points;
414
  showPenaltyEffect(stain, points);
@@ -421,7 +453,6 @@
421
 
422
  updateScore();
423
 
424
- // Check level up
425
  if (stainsCleaned >= level * 10) {
426
  levelUp();
427
  }
@@ -485,14 +516,12 @@
485
  level++;
486
  stainsCleaned = 0;
487
 
488
- // Increase difficulty
489
- stainSpeed = Math.max(stainSpeed - 100, 300); // Faster spawn (min 300ms)
490
- movingStainChance = Math.min(movingStainChance + 0.05, 0.8); // More moving stains
491
- penaltyStainChance = Math.min(penaltyStainChance + 0.02, 0.4); // More penalty stains
492
 
493
  updateLevel();
494
 
495
- // Show level up effect
496
  const levelUpEffect = document.createElement('div');
497
  levelUpEffect.className = 'absolute inset-0 flex items-center justify-center';
498
  levelUpEffect.innerHTML = `
 
29
  50% { transform: translateY(-10px); }
30
  }
31
 
 
 
 
 
 
 
 
 
32
  .stain {
33
  animation: fadeIn 0.3s ease-in;
34
  transition: transform 0.2s;
35
  cursor: pointer;
36
+ position: absolute;
37
  }
38
 
39
  .stain:hover {
 
41
  }
42
 
43
  .moving-stain {
44
+ animation: moveRandom 4s linear infinite;
45
+ }
46
+
47
+ @keyframes moveRandom {
48
+ 0% {
49
+ transform: translate(0, 0);
50
+ left: var(--start-x);
51
+ top: var(--start-y);
52
+ }
53
+ 25% {
54
+ transform: translate(calc(var(--move-x1) * 1px), calc(var(--move-y1) * 1px));
55
+ }
56
+ 50% {
57
+ transform: translate(calc(var(--move-x2) * 1px), calc(var(--move-y2) * 1px));
58
+ }
59
+ 75% {
60
+ transform: translate(calc(var(--move-x3) * 1px), calc(var(--move-y3) * 1px));
61
+ }
62
+ 100% {
63
+ transform: translate(0, 0);
64
+ }
65
  }
66
 
67
  .game-container {
68
  background-image: linear-gradient(to bottom, #f0f9ff, #e0f2fe);
69
+ position: relative;
70
+ overflow: hidden;
71
  }
72
 
73
  .progress-bar {
 
335
  gameInterval = setInterval(checkGameState, 500);
336
  }
337
 
338
+ // Create a new stain with full screen movement
339
  function createStain() {
340
  if (!gameActive) return;
341
 
342
  const gameAreaRect = gameArea.getBoundingClientRect();
343
+ const maxX = gameAreaRect.width - 100;
344
+ const maxY = gameAreaRect.height - 100;
345
 
346
+ // Position aléatoire initiale
347
+ const startX = Math.random() * maxX;
348
+ const startY = Math.random() * maxY;
349
+
350
+ // Determine stain type
351
  let stainTypeIndex;
352
 
 
353
  if (penaltyStainCount >= Math.ceil(stainCount / 3) && Math.random() < penaltyStainChance) {
354
  stainTypeIndex = Math.floor(Math.random() * (stainTypes.length - 2));
355
  } else {
 
356
  if (Math.random() < movingStainChance) {
357
  stainTypeIndex = Math.floor(Math.random() * (stainTypes.length - 2));
358
  }
359
 
 
360
  if (Math.random() < penaltyStainChance) {
361
  stainTypeIndex = Math.floor(Math.random() * 2) + (stainTypes.length - 2);
362
  } else {
 
367
  const stainType = stainTypes[stainTypeIndex];
368
 
369
  const stain = document.createElement('div');
370
+ stain.className = `stain rounded-full ${stainType.class} ${stainType.size}`;
371
+ stain.style.setProperty('--start-x', `${startX}px`);
372
+ stain.style.setProperty('--start-y', `${startY}px`);
373
+
374
+ // Définir des mouvements aléatoires plus grands
375
+ const moveX1 = (Math.random() * maxX - startX) * 0.5;
376
+ const moveY1 = (Math.random() * maxY - startY) * 0.5;
377
+ const moveX2 = (Math.random() * maxX - startX) * 0.5;
378
+ const moveY2 = (Math.random() * maxY - startY) * 0.5;
379
+ const moveX3 = (Math.random() * maxX - startX) * 0.5;
380
+ const moveY3 = (Math.random() * maxY - startY) * 0.5;
381
+
382
+ stain.style.setProperty('--move-x1', moveX1);
383
+ stain.style.setProperty('--move-y1', moveY1);
384
+ stain.style.setProperty('--move-x2', moveX2);
385
+ stain.style.setProperty('--move-y2', moveY2);
386
+ stain.style.setProperty('--move-x3', moveX3);
387
+ stain.style.setProperty('--move-y3', moveY3);
388
+
389
+ // Add moving class if needed (now most stains will move)
390
  if (stainType.moving || Math.random() < movingStainChance) {
391
  stain.classList.add('moving-stain');
392
+ // Make movement faster for moving stains
393
+ stain.style.animationDuration = `${3 + Math.random() * 2}s`;
394
  }
395
 
396
  // Add data attributes
397
  stain.dataset.points = stainType.points;
398
  stain.dataset.penalty = stainType.penalty;
399
 
400
+ // Position initiale
401
+ stain.style.left = `${startX}px`;
402
+ stain.style.top = `${startY}px`;
403
+
404
  // Add click event
405
  stain.addEventListener('click', cleanStain);
406
 
407
  gameArea.appendChild(stain);
408
  stainCount++;
409
 
 
410
  if (stainType.penalty) {
411
  penaltyStainCount++;
412
  }
 
420
  const points = parseInt(stain.dataset.points);
421
  const isPenalty = stain.dataset.penalty === 'true';
422
 
 
423
  stain.remove();
424
  stainCount--;
425
 
 
426
  if (isPenalty) {
427
  penaltyStainCount = Math.max(0, penaltyStainCount - 1);
428
  }
429
 
 
430
  const now = Date.now();
431
  if (now - lastCleanTime < 1000) {
432
  combo++;
 
441
  }
442
  lastCleanTime = now;
443
 
 
444
  if (isPenalty) {
445
  score += points;
446
  showPenaltyEffect(stain, points);
 
453
 
454
  updateScore();
455
 
 
456
  if (stainsCleaned >= level * 10) {
457
  levelUp();
458
  }
 
516
  level++;
517
  stainsCleaned = 0;
518
 
519
+ stainSpeed = Math.max(stainSpeed - 100, 300);
520
+ movingStainChance = Math.min(movingStainChance + 0.05, 0.8);
521
+ penaltyStainChance = Math.min(penaltyStainChance + 0.02, 0.4);
 
522
 
523
  updateLevel();
524
 
 
525
  const levelUpEffect = document.createElement('div');
526
  levelUpEffect.className = 'absolute inset-0 flex items-center justify-center';
527
  levelUpEffect.innerHTML = `