Chronos234 commited on
Commit
c176516
·
verified ·
1 Parent(s): fdc68ba

Rename game.js to script.js

Browse files
Files changed (2) hide show
  1. game.js +0 -35
  2. script.js +64 -0
game.js DELETED
@@ -1,35 +0,0 @@
1
- const canvas = document.getElementById('gameCanvas');
2
- const ctx = canvas.getContext('2d');
3
-
4
- canvas.width = window.innerWidth;
5
- canvas.height = window.innerHeight;
6
-
7
- // Definir as variáveis de jogo
8
- let towers = [];
9
- let enemies = [];
10
-
11
- // Adicionar uma torre e inimigo de teste
12
- towers.push(new Tower(canvas.width / 2, canvas.height / 2));
13
- enemies.push(new Enemy(canvas.width / 2, 100));
14
-
15
- // Função para desenhar e atualizar as entidades
16
- function update() {
17
- // Limpar a tela
18
- ctx.clearRect(0, 0, canvas.width, canvas.height);
19
-
20
- // Atualizar torres
21
- for (let tower of towers) {
22
- tower.update();
23
- }
24
-
25
- // Atualizar inimigos
26
- for (let enemy of enemies) {
27
- enemy.update();
28
- }
29
-
30
- // Continuar o loop de animação
31
- requestAnimationFrame(update);
32
- }
33
-
34
- // Começar a atualização do jogo
35
- update();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
script.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const canvas = document.getElementById("gameCanvas");
2
+ const ctx = canvas.getContext("2d");
3
+
4
+ let width = window.innerWidth;
5
+ let height = window.innerHeight;
6
+
7
+ canvas.width = width;
8
+ canvas.height = height;
9
+
10
+ let star = {
11
+ x: width / 2,
12
+ y: height / 2,
13
+ radius: 50,
14
+ color: "yellow",
15
+ };
16
+
17
+ let towers = [];
18
+ let enemies = [];
19
+
20
+ function drawStar() {
21
+ ctx.beginPath();
22
+ ctx.arc(star.x, star.y, star.radius, 0, Math.PI * 2);
23
+ ctx.fillStyle = star.color;
24
+ ctx.fill();
25
+ }
26
+
27
+ function drawTowers() {
28
+ towers.forEach(tower => {
29
+ ctx.beginPath();
30
+ ctx.arc(tower.x, tower.y, tower.radius, 0, Math.PI * 2);
31
+ ctx.fillStyle = "blue";
32
+ ctx.fill();
33
+ });
34
+ }
35
+
36
+ function drawEnemies() {
37
+ enemies.forEach(enemy => {
38
+ ctx.beginPath();
39
+ ctx.arc(enemy.x, enemy.y, enemy.radius, 0, Math.PI * 2);
40
+ ctx.fillStyle = "red";
41
+ ctx.fill();
42
+ });
43
+ }
44
+
45
+ function spawnEnemies() {
46
+ let enemy = {
47
+ x: Math.random() * width,
48
+ y: 0,
49
+ radius: 20,
50
+ speed: 2,
51
+ };
52
+ enemies.push(enemy);
53
+ }
54
+
55
+ function update() {
56
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
57
+ drawStar();
58
+ drawTowers();
59
+ drawEnemies();
60
+ spawnEnemies();
61
+ requestAnimationFrame(update);
62
+ }
63
+
64
+ update();