-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.js
90 lines (76 loc) · 2.01 KB
/
class.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
84
85
86
87
88
89
90
class Player{
constructor(x,y,image,speed){
this.x = x
this.y = y
this.rl = 0
this.width = 90
this.height = 20
this.image = image[0]
this.imageleft = image[0]
this.imageright = image[1]
this.speed = speed
this.image.onload = this.draw()
addEventListener("keydown", (e) =>{
switch(e.key){
case 'a':
this.left = true
break;
case 'd':
this.right = true
break;
}
})
addEventListener("keyup", (e) =>{
switch(e.key){
case 'a':
this.left = false
break;
case 'd':
this.right = false
break;
}
})
}
draw(){
// c.fillStyle = "#107040"
// c.fillRect(this.x,this.y,this.width,this.height)
c.drawImage(this.image,this.x - 20,this.y - 30,130,60)
}
move(){
if(this.left){
this.x -= this.speed
this.image = this.imageleft
if(this.x <= -20){
this.x = 590
}
}
if(this.right){
this.x += this.speed
this.image = this.imageright
if(this.x >= 600){
this.x = -10
}
}
}
}
class Egg{
constructor(size,x,y,image,potion){
this.x = x
this.y = y
this.width = size
this.height = size
this.image = image
this.image.onload = this.draw()
this.potion = potion
}
draw(){
// c.fillStyle = "#FFFFFF"
// c.fillRect(this.x,this.y,this.width,this.height)
c.drawImage(this.image,this.x,this.y,this.width+5,this.height+5)
}
move(){
this.y += 5
}
collision(){
}
}