Rooni commited on
Commit
353551f
·
verified ·
1 Parent(s): 0137a51

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +20 -1
script.js CHANGED
@@ -21,23 +21,32 @@ document.addEventListener('mousemove', (e) => {
21
  function createOrb() {
22
  const orb = document.createElement('div');
23
  orb.classList.add('orb');
24
- orb.style.backgroundColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
25
  orb.style.left = `${Math.random() * (gameArea.offsetWidth - 30)}px`;
26
  orb.style.top = `${Math.random() * 50 - 50}px`; // Start above the top
27
  gameArea.appendChild(orb);
28
 
 
 
 
 
 
 
 
 
29
  let interval = setInterval(() => {
30
  let orbTop = parseFloat(getComputedStyle(orb).getPropertyValue('top'));
31
  orb.style.top = `${orbTop + orbSpeed}px`;
32
  if (orbTop > gameArea.offsetHeight) {
33
  clearInterval(interval);
34
  gameArea.removeChild(orb);
 
35
  }
36
 
37
  // Collision detection
38
  if (checkCollision(orb, player)) {
39
  clearInterval(interval);
40
  gameArea.removeChild(orb);
 
41
  score += 10;
42
  scoreDisplay.textContent = score;
43
  increaseDifficulty();
@@ -53,18 +62,28 @@ function createBonus() {
53
  bonus.style.top = `${Math.random() * 50 - 50}px`; // Start above the top
54
  gameArea.appendChild(bonus);
55
 
 
 
 
 
 
 
 
 
56
  let interval = setInterval(() => {
57
  let bonusTop = parseFloat(getComputedStyle(bonus).getPropertyValue('top'));
58
  bonus.style.top = `${bonusTop + bonusSpeed}px`;
59
  if (bonusTop > gameArea.offsetHeight) {
60
  clearInterval(interval);
61
  gameArea.removeChild(bonus);
 
62
  }
63
 
64
  // Collision detection
65
  if (checkCollision(bonus, player)) {
66
  clearInterval(interval);
67
  gameArea.removeChild(bonus);
 
68
  score += 50; // Bonus gives 50 points
69
  scoreDisplay.textContent = score;
70
  }
 
21
  function createOrb() {
22
  const orb = document.createElement('div');
23
  orb.classList.add('orb');
 
24
  orb.style.left = `${Math.random() * (gameArea.offsetWidth - 30)}px`;
25
  orb.style.top = `${Math.random() * 50 - 50}px`; // Start above the top
26
  gameArea.appendChild(orb);
27
 
28
+ // Create trail
29
+ const trail = document.createElement('div');
30
+ trail.classList.add('trail');
31
+ trail.style.background = orb.style.background;
32
+ trail.style.left = orb.style.left;
33
+ trail.style.top = orb.style.top;
34
+ gameArea.appendChild(trail);
35
+
36
  let interval = setInterval(() => {
37
  let orbTop = parseFloat(getComputedStyle(orb).getPropertyValue('top'));
38
  orb.style.top = `${orbTop + orbSpeed}px`;
39
  if (orbTop > gameArea.offsetHeight) {
40
  clearInterval(interval);
41
  gameArea.removeChild(orb);
42
+ gameArea.removeChild(trail);
43
  }
44
 
45
  // Collision detection
46
  if (checkCollision(orb, player)) {
47
  clearInterval(interval);
48
  gameArea.removeChild(orb);
49
+ gameArea.removeChild(trail);
50
  score += 10;
51
  scoreDisplay.textContent = score;
52
  increaseDifficulty();
 
62
  bonus.style.top = `${Math.random() * 50 - 50}px`; // Start above the top
63
  gameArea.appendChild(bonus);
64
 
65
+ // Create trail
66
+ const trail = document.createElement('div');
67
+ trail.classList.add('trail');
68
+ trail.style.background = bonus.style.background;
69
+ trail.style.left = bonus.style.left;
70
+ trail.style.top = bonus.style.top;
71
+ gameArea.appendChild(trail);
72
+
73
  let interval = setInterval(() => {
74
  let bonusTop = parseFloat(getComputedStyle(bonus).getPropertyValue('top'));
75
  bonus.style.top = `${bonusTop + bonusSpeed}px`;
76
  if (bonusTop > gameArea.offsetHeight) {
77
  clearInterval(interval);
78
  gameArea.removeChild(bonus);
79
+ gameArea.removeChild(trail);
80
  }
81
 
82
  // Collision detection
83
  if (checkCollision(bonus, player)) {
84
  clearInterval(interval);
85
  gameArea.removeChild(bonus);
86
+ gameArea.removeChild(trail);
87
  score += 50; // Bonus gives 50 points
88
  scoreDisplay.textContent = score;
89
  }