-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawGraphics.js
More file actions
92 lines (81 loc) · 1.99 KB
/
Copy pathdrawGraphics.js
File metadata and controls
92 lines (81 loc) · 1.99 KB
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
function clearCanvas(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
function drawPlayer(){
ctx.drawImage(playerImage, player.x, player.y, player.w, player.h);
}
function drawEnemies(){
enemies.forEach(x => {
var enemyType = x[6];
var enemyVisible = x[4];
if (enemyType == 1 && enemyAnimBool == true){
var enemyImg = enemy1_1;
}
else if (enemyType == 1 && enemyAnimBool == false){
var enemyImg = enemy1_2;
}
if (enemyType == 2 && enemyAnimBool == true){
var enemyImg = enemy2_1;
}
else if (enemyType == 2 && enemyAnimBool == false){
var enemyImg = enemy2_2;
}
if (enemyType == 3 && enemyAnimBool == true){
var enemyImg = enemy3_1;
}
else if (enemyType == 3 && enemyAnimBool == false){
var enemyImg = enemy3_2;
}
if (enemyVisible == true){
ctx.drawImage(enemyImg, x[0], x[1], x[2], x[3]);
}
});
}
function drawMissiles(){
missiles.forEach(x => {
ctx.beginPath();
ctx.arc(x[0], x[1], missileRadius, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "green";
ctx.fill();
});
}
function drawBombs(){
bombs.forEach(x => {
ctx.beginPath();
ctx.arc(x[0], x[1], bombRadius, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "red";
ctx.fill();
});
}
function drawPlayerExplosion(){
if (playerExplosionRadius <= 50){
playerExplosionRadius += 10;
ctx.beginPath();
ctx.arc(player.x + player.w/2, player.y, playerExplosionRadius, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "yellow";
ctx.fill();
}
}
function drawEnemyExplosions(){
enemyExplosions.forEach(explosion => {
explosion[4] += 5; // explosion radius
if (explosion[4] <= enemyExplosionRadius){
ctx.beginPath();
ctx.arc(explosion[0] + explosion[2]/2, explosion[1] + explosion[3] / 2, explosion[4], 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "white";
ctx.fill();
}
else {
enemyExplosions.pop();
}
});
}
var enemyAnimBool = true;
var enemyAnimation = setInterval(switchEnemyImage, 250);
function switchEnemyImage(){
enemyAnimBool = !enemyAnimBool;
}