-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.js
48 lines (44 loc) · 1.12 KB
/
platform.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
function Platform(x, y, width, height,
xTravel, xSpeed, yTravel, ySpeed, danger) {
this.xBase = x;
this.x = x;
this.yBase = y;
this.y = y;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
this.width = width;
this.height = height;
this.danger = danger;
this.old_x = x;
this.old_y = y;
if(danger) {
this.color = "#300000";
} else {
this.color = "#303000";
}
this.xTravel = xTravel;
this.yTravel = yTravel;
this.update = function() {
this.old_x = this.x;
this.old_y = this.y;
this.x += this.xSpeed;
this.y += this.ySpeed;
if(this.x < this.xBase) {
this.x = this.xBase;
this.xSpeed = -this.xSpeed;
} else if(this.x > this.xBase + this.xTravel) {
this.x = this.xBase + this.xTravel;
this.xSpeed = -this.xSpeed;
}
if(this.y < this.yBase) {
this.y = this.yBase;
this.ySpeed = -this.ySpeed;
} else if(this.y > this.yBase + this.yTravel) {
this.y = this.yBase + this.yTravel;
this.ySpeed = -this.ySpeed;
}
};
this.draw = function (camera) {
camera.rect(this.color, this.x, this.y, this.width, this.height);
};
}