-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.js
71 lines (60 loc) · 1.9 KB
/
classes.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
class CanvasObject{
constructor(x,y, width, height, context, move_function, values){
this.position = {
'x':x,
'y':y
};
this.size = {
'width':width,
'height':height
}
this.move_function = move_function | null;
this.context = context;
this.values = values | null;
this.originalPosition = [x,y];
}
resetPosition(){
this.position.x = this.originalPosition[0];
this.position.y = this.originalPosition[1];
}
draw(total_time, delta_time){
if(this.move_function)
this.move_function(total_time, delta_time);
this.display();
}
}
class Sprite extends CanvasObject{
constructor(x,y, width, height ,src, context, move_function, values){
super(x,y,width,height, context, move_function, values);
this.image = new Image();
this.image.src = src;
}
display(){
this.context.save();
this.context.translate(this.position.x, this.position.y);
this.context.drawImage(this.image,0,0,this.size.width,this.size.height);
this.context.restore();
}
}
class Rectangle extends CanvasObject{
constructor(x,y, width, height, color, context, move_function, values){
super(x,y,width,height, context, move_function, values);
this.color = color;
}
display(){
this.context.beginPath();
this.context.rect(this.position.x, this.position.y, this.size.width, this.size.height);
this.context.fill();
}
}
class CanvasText extends CanvasObject{
constructor(x,y, text, font, context, move_function, values){
super(x,y, null, null, context, move_function, values);
this.text = text;
this.font = font;
}
display(){
this.context.font = this.font;
this.context.fillText(this.text, this.position.x, this.position.y);
}
}