forked from mustafamrtt/platformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.js
More file actions
96 lines (71 loc) · 2.43 KB
/
Copy pathEnemy.js
File metadata and controls
96 lines (71 loc) · 2.43 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
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
91
92
93
94
95
96
class Enemy{
constructor(x,y,width,height,imagepath){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.image = image(imagepath);
this.deathImage = image("./sprite/Woodcutter_death.png");
this.frameCount=4;
this.frameWidth=29;
this.frameHeight=48;
this.deathframeWidth=48;
this.deathframeHeight=48;
this.deathCurrentFrame = 0;
this.currentFrame;
this.death = false;
this.frameTimer;
this.animationSpeed = 250;
this.animation();
}
animation(){
this.frameTimer = 0.0;
this.currentFrame = 0;
}
update(deltaTime){
if(this.death){ //duruma göre spriteı update ediyoruz
if(this.frameTimer>= this.animationSpeed){
this.deathCurrentFrame++; ///animasyon hızına ve zamanlayıcıya göre Framei arttırıyoruz.
this.frameTimer = 0.0;
}
if(this.deathCurrentFrame>=6){
///spritesheetteki frame sayısını kontrol edip başa dönüyoruz.
this.frameTimer = 0;
}
else{
this.frameTimer += deltaTime; //geçen zamanı frameTimer'a ekliyoruz.
}
}
else{
if(this.frameTimer >= this.animationSpeed){
this.currentFrame++;
this.frameTimer = 0.0;
}
this.frameTimer += deltaTime;
if(this.currentFrame>=this.frameCount){
this.currentFrame = 0;
}
}
}
draw() {
context.save();
context.translate(this.x + this.width, this.y);
context.scale(-1, 1); //Aynalıyoruz.
if (this.death) {
context.drawImage(
this.deathImage,
this.deathCurrentFrame * this.deathframeWidth, 0,
this.deathframeWidth, this.frameHeight,
0, 0, this.width, this.height
);
} else {
context.drawImage(
this.image,
this.currentFrame * this.frameWidth, 0,
this.frameWidth, this.frameHeight,
0, 0, this.width, this.height
);
}
context.restore();
}
}