-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
83 lines (68 loc) · 2.09 KB
/
player.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { canvas, c, enemy, pause, score, scoreDiv } from "./canvas.js"
import { points } from "./enemy.js"
const player = new Image()
export var gameOver = false
player.src = './folder/images/ship_1.png'
export default class Player {
constructor(x = canvas.width/2-24, y = canvas.height-68){
this.x = x,
this.y = y,
this.health = 10
this.draw = () => {
c.drawImage(player, this.x, this.y, 50, 50)
}
this.update = () => {
c.clearRect(0, 0, 600, 600)
this.draw()
}
this.life = () => {
c.beginPath()
c.fillStyle = '#43d364'
c.fillRect(0, canvas.height-15, this.health*50, 15)
}
this.getHit = () => {
score.innerHTML = points
gameOver = true
}
this.exitGameOver = () => {
gameOver = false
scoreDiv.classList.remove('gameOver')
}
this.fire = () => {
document.addEventListener('keydown', (e) => {
enemy.removeLetter(e)
})
}
// document.addEventListener('keydown', (e) => {
// switch(e.code){
// case 'KeyA':
// this.moveL = true
// break
// case 'KeyD':
// this.moveR = true
// break
// case 'Space':
// console.log('shot')
// break
// }
// })
// document.addEventListener('keyup', (e) => {
// switch(e.code){
// case 'KeyA':
// this.moveL = false
// break
// case 'KeyD':
// this.moveR = false
// break
// }
// })
// this.move = () => {
// if(this.moveR && this.x+40 < canvas.width){
// this.x += 7
// }
// if(this.moveL && this.x > 0){
// this.x -= 7
// }
// }
}
}