-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSprites_Monkey.js
More file actions
50 lines (50 loc) · 1.32 KB
/
Copy pathSprites_Monkey.js
File metadata and controls
50 lines (50 loc) · 1.32 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
class Sprites_Monkey{
constructor(x,y,speed,img,imgWidth,imgHeight,totalFrames){
this.x=x;
this.y=y;
this.speed=speed;
this.img=img;
this.imgWidth=imgWidth;
this.imgHeight=imgHeight;
this.frameX=0;
this.frameY=0;
this.totalFrames=totalFrames;
}
movment(canvas,keys,time,speed,timeCheck){
if(keys.right && this.x<739){
this.frameY=0;
if(speed==1 && timeCheck==true){
this.x+=6;
}
else if(speed==-1 && timeCheck==true){
this.x+=2;
}
else{
this.x+=4
}
}
if(keys.left && this.x>10){
this.frameY=1;
if(speed==1 && timeCheck==true){
this.x-=6;
}
else if(speed==-1 && timeCheck==true){
this.x-=2;
}
else{
this.x-=4;
}
}
if(keys.left || keys.right){
if(time%3==0){
this.frameX++;
if(this.frameX==this.totalFrames) this.frameX=0;
}
}
}
draw(ctx){
ctx.beginPath();
ctx.drawImage(this.img, this.frameX*this.imgWidth, this.frameY*this.imgHeight, this.imgWidth, this.imgHeight, this.x, this.y, this.imgWidth, this.imgHeight);
ctx.closePath();
}
}