-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.js
59 lines (50 loc) · 1.67 KB
/
enemy.js
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
import { canvas, c, randomInt, words, player, projectils, shotAudios, score} from "./canvas.js"
import { Projectile } from "./shot.js"
export let letter = 0
export let points = 0
const meteor = new Image()
meteor.src = './folder/images/spaceMeteors_001.png'
export class Enemy {
constructor(x, y, word){
this.x = canvas.width/2
this.y = y
this.speedMultiplyer = 1
this.arr = word.split('')
this.draw = () => {
c.font = "25px Arial"
c.fillStyle = 'white'
c.fillText(this.arr.join(''), this.x+10, this.y-15)
c.drawImage(meteor, this.x-5, this.y, 20, 20)
this.update()
}
this.update = () => {
this.y += 1.5 * this.speedMultiplyer
this.getWord()
}
this.removeLetter = (e) => {
if(e.key.toUpperCase() == this.arr[letter]){
this.arr.shift()
projectils.push(new Projectile(this.y, this.speedMultiplyer))
shotAudios.push(new Audio('./folder/sounds/synth_laser_02.ogg'))
}
this.getWord()
}
this.getWord = () => {
if(this.y > canvas.height){
player.getHit()
this.speedMultiplyer = 1
}
if(this.arr.length == 0 || this.y > canvas.height){
points += 100
score.innerHTML = points
this.arr = words[randomInt(0, words.length)].split('')
this.y = -100
this.speedMultiplyer += 0.1
}
}
this.turnZero = () => {
points = 0
score.innerHTML = points
}
}
}