/
barn.js
78 lines (75 loc) · 3.26 KB
/
barn.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
72
73
74
75
76
77
78
class barn extends Phaser.Scene{
constructor(){
super("barn")
}
create(){
this.add.tileSprite(0,0,920,460,"barn").setOrigin(0);
this.horse1 = this.add.sprite(400,150,"blackHorse").setScale(1.25);
this.horse1price = this.add.text(320, 10, "500 Bucks", {fontFamily: "lightbulb", fontSize: "32px", color: "black"});
this.horse2 = this.add.sprite(400,150,"brownHorse").setScale(1.25).setVisible(false);
this.horse2price = this.add.text(310, 10, "1000 Bucks", {fontFamily: "lightbulb", fontSize: "32px", color: "black"}).setVisible(false);
this.horse3 = this.add.sprite(400,150,"whiteHorse").setScale(1.25).setVisible(false);
this.horse3price = this.add.text(310, 10, "2000 Bucks", {fontFamily: "lightbulb", fontSize: "32px", color: "black"}).setVisible(false);
this.next = this.add.text(340,240,"NEXT",{fontFamily:"lightbulb", fontSize: "32px", color: "black"}).setInteractive().setDepth(99);
this.buy = this.add.text(340,280,"BUY",{fontFamily:"lightbulb", fontSize: "32px", color: "black"}).setInteractive().setDepth(99);
this.exit = this.add.text(340,320,"EXIT",{fontFamily:"lightbulb", fontSize: "32px", color: "black"}).setInteractive().setDepth(99);
this.next.on("pointerdown", () => {
if(this.horse1.visible == true){
this.horse1.visible = this.horse1price.visible = false;
this.horse2.visible = this.horse2price.visible = true;
}
else if(this.horse2.visible == true){
this.horse2.visible = this.horse2price.visible = false;
this.horse3.visible = this.horse3price.visible = true;
}
else{
this.horse3.visible = this.horse3price.visible = false;
this.horse1.visible = this.horse1price.visible = true;
}
});
this.chase = false;
this.buy.on("pointerdown", () => {
if(this.horse1.visible == true && money >= 500){
if(localStorage.getItem("hasHorse") == undefined)
this.chase = true
money -= 500;
localStorage.setItem("money", money);
localStorage.setItem("hasHorse", "black");
localStorage.setItem("location", "town");
if(this.chase == true)
this.scene.start("preRidersChase");
else
this.scene.start("town");
}
else if(this.horse2.visible == true && money >= 1000){
if(localStorage.getItem("hasHorse") == undefined)
this.chase = true
money -= 1000;
localStorage.setItem("money", money);
localStorage.setItem("hasHorse", "brown");
localStorage.setItem("location", "town");
if(this.chase == true)
this.scene.start("preRidersChase");
else
this.scene.start("town");
}
else if(this.horse3.visible == true && money >= 2000){
if(localStorage.getItem("hasHorse") == undefined)
this.chase = true
money -= 500;
localStorage.setItem("money", money);
localStorage.setItem("hasHorse", "white");
localStorage.setItem("location", "town");
if(this.chase == true)
this.scene.start("preRidersChase");
else
this.scene.start("town");
}
});
this.exit.on("pointerdown", () => {
this.sound.play("doorOpen");
localStorage.setItem("location", "town");
this.scene.start("town");
})
}
}