-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeToggleButton.js
More file actions
70 lines (67 loc) · 1.96 KB
/
Copy pathModeToggleButton.js
File metadata and controls
70 lines (67 loc) · 1.96 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
function ModeToggleButton(xPosition, yPosition) {
this.sprite = sprites.extras["simple_button"].normal;
this.position = new Vector2(xPosition, yPosition);
this.origin = new Vector2(0, 0);
this.mode = "normal";
}
ModeToggleButton.prototype.draw = function () {
if (this.mode === "normal") {
Canvas.drawImage(this.sprite, this.position, 0, this.origin, 0.5);
Canvas.drawText(
"Extra Modes",
new Vector2(this.position.x + 20, this.position.y + 35),
"black",
"top",
"Courier New",
"25px"
);
}
if (this.mode === "extras") {
Canvas.drawImage(this.sprite, this.position, 0, this.origin, 0.5);
Canvas.drawText(
"Normal Modes",
new Vector2(this.position.x + 10, this.position.y + 35),
"black",
"top",
"Courier New",
"25px"
);
}
};
ModeToggleButton.prototype.update = function () {
this.rect = new Rectangle(
this.position.x ,
this.position.y,
this.sprite.width / 2,
this.sprite.height / 2
);
if (!Touch.isTouchDevice) {
if (this.rect.contains(Mouse.position) && Mouse.pressed) {
if (this.mode === "normal") {
this.mode = "extras";
Game.gameWorld.scrollLength = Game.gameWorld.extraButtonString.length;
Game.gameWorld.scrollInteger = 0;
}
else if (this.mode === "extras") {
this.mode = "normal";
Game.gameWorld.scrollLength = Game.gameWorld.normalButtonString.length;
Game.gameWorld.scrollInteger = 0;
}
}
}
else {
if (Touch.containsTouchPress(this.rect)) {
if (this.mode === "normal") {
this.mode = "extras";
Game.gameWorld.scrollLength = Game.gameWorld.extraButtonString.length;
Game.gameWorld.scrollInteger = 0;
alert("yes");
}
else if (this.mode === "extras") {
this.mode = "normal";
Game.gameWorld.scrollLength = Game.gameWorld.normalButtonString.length;
Game.gameWorld.scrollInteger = 0;
}
}
}
};