Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/gopher-kart/js/stateChoice.js
1036 views
1
var StateChoice = {
2
preload: function () {
3
//Music and Sounds
4
game.load.audio("select", "assets/music/BeepBox-Song3-compressed.m4a");
5
6
//Spritesheets for the 3 colored Gophers
7
//Later put into 1 spritesheet
8
game.load.spritesheet("racer", "assets/character-select-loops.png", 76, 72, 7);
9
10
game.load.image("background", "assets/bg-color.png");
11
game.load.image("city", "assets/city-re-colored.png");
12
game.load.image("sky", "assets/clouds-re-colored.png");
13
game.load.image("mtn", "assets/mountains-recolored.png");
14
game.load.image("select", "assets/character-select-bg.png");
15
16
//sample test button
17
game.load.spritesheet("confirmButton", "assets/buttons-sprite.png", 111, 24, 4);
18
game.load.spritesheet("neon", "assets/neon-sign.png", 120, 30, 13);
19
20
game.load.spritesheet("buttons", "assets/on-off-buttons.png", 59, 41, 2);
21
game.load.spritesheet("blueMarquee", "assets/blue-crawl.png", 50, 12, 45);
22
game.load.spritesheet("pinkMarquee", "assets/pink-crawl.png", 50, 12, 45);
23
game.load.spritesheet("purpleMarquee", "assets/purple-crawl.png", 50, 12, 45);
24
// game.load.spritesheet("neonCnfrm", "assets/neon-sign.png", )
25
26
},
27
28
create: function () {
29
this.camera.reset();
30
31
//MUSIC
32
this.selectSong = game.add.audio("select");
33
//Watched youtube video, need to check docs for .play params
34
this.selectSong.play('', 0, 1, true);
35
36
//BACKGROUND
37
this.background = game.add.tileSprite(0, 0, 600, 432, "background");
38
39
this.sky = game.add.tileSprite(0, 10, 600, 78, "sky");
40
this.mtn = game.add.tileSprite(0, 250, 600, 131, "mtn");
41
this.city = game.add.tileSprite(0, 290, 600, 90, "city");
42
this.select = game.add.tileSprite(0, 0, 600, 432, "select");
43
44
//MARQUEE
45
//Blue
46
this.blueMarquee = game.add.sprite(game.world.bounds.height - 282, game.world.centerY-16, "blueMarquee");
47
this.blueMarquee.anchor.set(0.5, 0.5);
48
this.blueMarquee.animations.add("blueCrawl", [],15, true);
49
this.blueMarquee.animations.play("blueCrawl");
50
//Pink
51
this.pinkMarquee = game.add.sprite(game.world.bounds.height - 132, game.world.centerY-16, "pinkMarquee");
52
this.pinkMarquee.anchor.set(0.5, 0.5);
53
this.pinkMarquee.animations.add("pinkCrawl", [],13, true);
54
this.pinkMarquee.animations.play("pinkCrawl");
55
//Purple
56
this.purpleMarquee = game.add.sprite(game.world.bounds.height + 18, game.world.centerY-16, "purpleMarquee");
57
this.purpleMarquee.anchor.set(0.5, 0.5);
58
this.purpleMarquee.animations.add("purpleCrawl", [],10, true);
59
this.purpleMarquee.animations.play("purpleCrawl");
60
61
//Choose Racer1
62
this.pickRacer1 = game.add.button(game.world.bounds.height - 282, game.world.centerY+105,
63
"buttons", this.racerStart.bind(this, "blue"), this);
64
this.pickRacer1.anchor.set(0.5, 0.5);
65
66
//Choose Racer2
67
this.pickRacer2 = game.add.button(game.world.bounds.height - 132, game.world.centerY+105,
68
"buttons", this.racerStart.bind(this, "pink"), this);
69
this.pickRacer2.anchor.set(0.5, 0.5);
70
71
//Choose Racer3
72
this.pickRacer3 = game.add.button(game.world.bounds.height + 18, game.world.centerY+105,
73
"buttons", this.racerStart.bind(this, "purple"), this);
74
this.pickRacer3.anchor.set(0.5, 0.5);
75
76
this.buttons = {
77
"blue": this.pickRacer1,
78
"pink": this.pickRacer2,
79
"purple": this.pickRacer3
80
};
81
82
//BLACK AND WHITE GOPHERS
83
//Blue
84
this.blue = game.add.sprite(game.world.bounds.height - 282, game.world.centerY+40, "racer");
85
this.blue.frame = 1;
86
this.blue.animations.add("blue", [1, 2],9, true);
87
this.blue.anchor.set(0.5, 0.5);
88
this.blue.animations.play("blue");
89
90
//Pink
91
this.PinkGopher = game.add.sprite(game.world.bounds.height - 132, game.world.centerY+40, "racer");
92
this.PinkGopher.frame = 3;
93
this.PinkGopher.animations.add("pink", [3, 4],9, true);
94
this.PinkGopher.anchor.set(0.5, 0.5);
95
this.PinkGopher.animations.play("pink");
96
97
//Purple
98
this.PurpleGopher = game.add.sprite(game.world.bounds.height + 18, game.world.centerY+40, "racer");
99
this.PurpleGopher.frame = 5;
100
this.PurpleGopher.animations.add("purple", [5, 6],9, true);
101
this.PurpleGopher.anchor.set(0.5, 0.5);
102
this.PurpleGopher.animations.play("purple");
103
104
105
//CONFIRMATION BUTTON
106
this.startConfirm = game.add.button(game.world.bounds.height - 132, game.world.height-46,
107
"neon", this.startGame, this, 12, 12, 12);
108
this.startConfirm.frame = 12;
109
this.startConfirm.anchor.set(0.5, 0.5);
110
this.startConfirm.animations.add("neon", [],5, true);
111
this.startConfirm.anchor.set(0.5, 0.5);
112
// this.startConfirm.animations.play("neon");
113
},
114
115
startGame: function () {
116
if(character === undefined){
117
this.sampleText = game.add.text(game.world.centerX, 30, "You must choose a gopher!");
118
this.sampleText.fill = "ffffff";
119
this.sampleText.fontSize = 32;
120
this.sampleText.anchor.set(0.5, 0.5);
121
// console.log("You must choose a gopher!");
122
} else {
123
this.selectSong.stop();
124
game.state.start("StateMain");
125
}
126
},
127
128
racerStart: function (racer){
129
console.log(racer);
130
for (var key in this.buttons) {
131
this.buttons[key].frame = 0;
132
}
133
134
this.buttons[racer].frame = 1;
135
character = racer;
136
137
138
this.startConfirm.animations.play("neon");
139
// character.animations.play("blue");
140
// console.log(character);
141
},
142
143
144
update: function () {
145
this.sky.tilePosition.x -= 0.1;
146
147
},
148
149
150
};
151
152