-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopButton.js
More file actions
75 lines (71 loc) · 1.93 KB
/
Copy pathShopButton.js
File metadata and controls
75 lines (71 loc) · 1.93 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
function ShopButton(position) {
this.sprite = sprites.extras["simple_button"].normal;
this.position = position;
this.origin = new Vector2(this.sprite.width / 2, this.sprite.height / 2);
this.rect = new Rectangle(
position.x - this.origin.x / 2,
position.y - this.origin.y / 2,
this.sprite.width * 0.5,
this.sprite.height * 0.5
);
}
ShopButton.prototype.draw = function () {
Canvas.drawImage(this.sprite, this.position, 0, this.origin, 0.5);
if (Game.gameWorld.area === "home") {
Canvas.drawText(
"Shop",
new Vector2(this.position.x - 55, this.position.y - 20),
"black",
"top",
"Courier New",
"40px"
);
}
if (Game.gameWorld.area === "shop") {
Canvas.drawText(
"Home",
new Vector2(this.position.x - 55, this.position.y - 20),
"black",
"top",
"Courier New",
"40px"
);
}
};
ShopButton.prototype.update = function () {
this.origin = new Vector2(this.sprite.width / 2, this.sprite.height / 2);
this.rect = new Rectangle(
this.position.x - this.origin.x / 2,
this.position.y - this.origin.y / 2,
this.sprite.width * 0.5,
this.sprite.height * 0.5
);
if (!Touch.isTouchDevice) {
if (this.rect.contains(Mouse.position) && Mouse.pressed) {
if (Game.gameWorld.area === "shop") {
Game.gameWorld.area = "home";
this.position = new Vector2(200, 550);
return;
}
if (Game.gameWorld.area === "home") {
Game.gameWorld.area = "shop";
this.position = new Vector2(200, 650);
return;
}
}
}
else {
if (Touch.containsTouchPress(this.rect)) {
if (Game.gameWorld.area === "shop") {
Game.gameWorld.area = "home";
this.position = new Vector2(200, 550);
return;
}
if (Game.gameWorld.area === "home") {
Game.gameWorld.area = "shop";
this.position = new Vector2(200, 650);
return;
}
}
}
};