"Script Nou" - Processing

ID Autor Duplicat din Ultima modificare
#6681 6B-Necsulescu Stefan Matei (Stefan_Matei_Necsulescu) - Miercuri, 16 apr 2025, 10:01
x
 
1
function keyPressed() {
2
  if (keyCode === 32) { // Spacebar pentru împușcare directă
3
    bullets.push(new Bullet(player.x, player.y, 1, 0)); // Spre dreapta
4
  }
5
  if (keyCode === UP_ARROW) { // Săritura
6
    player.jump();
7
  }
8
  if (keyCode === DOWN_ARROW) { // Ghemuire
9
    player.crouch();
10
  }
11
  if (keyCode === LEFT_ARROW) { // Mers spre stânga
12
    player.move(-5);
13
  }
14
  if (keyCode === RIGHT_ARROW) { // Mers spre dreapta
15
    player.move(5);
16
  }
17
  
18
  // Trageri cu WASD
19
  if (key === 'w') bullets.push(new Bullet(player.x, player.y, 0, -1)); // Sus
20
  if (key === 'a') bullets.push(new Bullet(player.x, player.y, -1, 0)); // Stânga
21
  if (key === 's') bullets.push(new Bullet(player.x, player.y, 0, 1)); // Jos
22
  if (key === 'd') bullets.push(new Bullet(player.x, player.y, 1, 0)); // Dreapta
23
24
  // Diagonal shots
25
  if (key === 'q') bullets.push(new Bullet(player.x, player.y, -1, -1)); // Stânga sus
26
  if (key === 'e') bullets.push(new Bullet(player.x, player.y, 1, -1)); // Dreapta sus
27
  if (key === 'z') bullets.push(new Bullet(player.x, player.y, -1, 1)); // Stânga jos
28
  if (key === 'c') bullets.push(new Bullet(player.x, player.y, 1, 1)); // Dreapta jos
29
}
30
Du-te sus!