-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvader.js
More file actions
60 lines (46 loc) · 1.77 KB
/
invader.js
File metadata and controls
60 lines (46 loc) · 1.77 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
class Invader {
constructor(randomX){
this.node = document.createElement("img")
this.node.src = "../assets/img/ground-alien.png"
this.node.style.zIndex = 2
this.node.style.position = 'absolute'
gameBoxNode.append(this.node) //to add the node to game box on pipe creation
//add the initial values of position and dimensions
this.width = 23.6
this.height = 49
this.x = 941 + randomX
this.y = 523
//adjust the node with initial values
this.node.style.width = `${this.width}px`
this.node.style.height = `${this.height}px`
this.node.style.top = `${this.y}px`
this.node.style.left = `${this.x}px`
//movements
this.speed = 1
//life
this.life = 5
this.dieFx = new Audio('../assets/audio/fx/alien-exploded.mp3')
this.spawnFx = new Audio('../assets/audio/fx/alien-spawn-sound.mp3')
this.occupyFx = new Audio('../assets/audio/fx/alien-spawn-sound.mp3')
}
automaticMovement(){
this.y += this.speed
this.node.style.top = `${this.y}px`
this.width = this.width + (this.width * (0.4 / 100))
this.height = this.height + (this.height * (0.4 / 100))
this.node.style.width = `${this.width}px`
this.node.style.height = `${this.height}px`
}
die(){
this.node.src = "./assets/img/enemy-explosion.png"
this.width = this.height
this.node.style.width = `${this.width}px`
playSfx(this.dieFx)
currentScore = currentScore + 5
let formattedCurrentScore = currentScore.toString().padStart(6, '0')
gbCurrentScoreNode.innerHTML = formattedCurrentScore
setTimeout(() => {
this.node.remove()
}, 2000)
}
}