-
Notifications
You must be signed in to change notification settings - Fork 1
/
Preload.js
207 lines (179 loc) · 5.71 KB
/
Preload.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Game.Preload = function(game) {
this.preloadBar = null;//The preloadBar sprite
//Webfont code from phaser tutorial: http://phaser.io/examples/v2/text/google-webfonts
// The Google WebFont Loader will look for this object, so create it before loading the script.
WebFontConfig = {
active: function() {console.log("Font Loaded");},
// The Google Fonts we want to load (specify as many as you like in the array)
google: {
families: ['Faster One', 'Stalinist One']
}
};
};
//LocalStorage name if localSotrage was implemented
var localStorageName = "SPEEDRUNNER";
//Levels Object idea is from: http://thoughts.amphibian.com/2015/12/more-levels-fewer-states.html
var tutorial = {
map:'Tut',//Map to load
starTime: 30,//Time to get the third star
devAllStar: 16,//The dev's time (my time) to complete level with all stars
devNoStar: 10,//The dev's time to complete the level with no stars
gotStar: [false, false, false],//Array showing if the stars are gotten or not
locked: false,//Is the level locked(true) or unlocked(false)
playerTime: 100//The player's best Time Default of 100
}
var level1 = {
map: 'Lvl1',
starTime: 30,
devAllStar: 15,
devNoStar: 3,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level2 = {
map: 'Lvl2',
starTime: 30,
devAllStar: 12,
devNoStar: 9,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level3 = {
map: 'Lvl3',
starTime: 30,
devAllStar: 13,
devNoStar: 2,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level4 = {
map: 'Lvl4',
starTime: 30,
devAllStar: 15,
devNoStar: 5,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level5 = {
map: 'Lvl5',
starTime: 25,
devAllStar: 11,
devNoStar: 5,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level6 = {
map: 'Lvl6',
starTime: 40,
devAllStar: 20,
devNoStar: 5,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level7 = {
map: 'Lvl7',
starTime: 40,
devAllStar: 19,
devNoStar: 5,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level8 = {
map: 'Lvl8',
starTime: 60,
devAllStar: 32,
devNoStar: 2,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
var level9 = {
map: 'Lvl9',
starTime:50,
devAllStar: 23,
devNoStar: 5,
gotStar: [false,false,false],
locked: true,
playerTime: 100
}
//The levels in the game
Game.Levels = {
levels: [],//Array to hold the levels
currentLevel: 'Tut',//Current level
levelsComplete: [false,false,false,false,false,false,false,false,false,false]//Array to see if the levels are complete
};
//Adding levels to the levels array
Game.Levels.levels[0] = tutorial;
Game.Levels.levels[1] = level1;
Game.Levels.levels[2] = level2;
Game.Levels.levels[3] = level3;
Game.Levels.levels[4] = level4;
Game.Levels.levels[5] = level5;
Game.Levels.levels[6] = level6;
Game.Levels.levels[7] = level7;
Game.Levels.levels[8] = level8;
Game.Levels.levels[9] = level9;
//Function to add text over a generic button sprite
//Copied from phaser tutorial: https://www.youtube.com/watch?v=F8DzoVIHoIc&list=PL9iYZZWgVwsfNdldSzmYev0tbVKjeov6w&index=13
Game.createButton = function(game,string,x,y,w,h,callback){
var button1 = game.add.button(x,y,'Button', callback,this,0,1,2);
button1.anchor.setTo(0.5);
button1.width = w;
button1.height = h;
var txt = game.add.text(button1.x, button1.y, string, {font:"18px Stalinist One", fill:"#fff", align: "center"});
txt.anchor.setTo(0.5);
}
Game.Preload.prototype = {
//Load in assets and set loading screen
preload: function() {
//Making the preload bar
this.preloadBar = this.add.sprite(this.world.centerX, this.world.centerY,'preloadBar');
this.preloadBar.anchor.setTo(0.5);
this.time.advancedTiming = true;
this.load.setPreloadSprite(this.preloadBar);
///////////////////
//LOAD ALL ASSETS//
///////////////////
//Tilemaps
this.load.tilemap('Tut', "Assets/tutorial.json", null, Phaser.Tilemap.TILED_JSON);
for(var i =1; i< Game.Levels.levels.length; i++) {
var imgKey = 'Lvl' + i.toString();
var filePath = "Assets/Level"+ i.toString() +".json";
this.load.tilemap(imgKey, filePath, null, Phaser.Tilemap.TILED_JSON);
}
//Images
this.load.image('GroundTiles', "Assets/GroundTiles.png");
this.load.image('Objects', "Assets/Objects.png");
this.load.image('Sky', "Assets/Sky.png");
this.load.image('Clouds', "Assets/Clouds.png");
this.load.image('exit', "Assets/Door.png");
this.load.image('spike', "Assets/Spike.png");
this.load.image('door', "Assets/Door.png");
this.load.image('pause', "Assets/pauseMenu.png");
//Spritesheets
this.load.spritesheet('thumbnail', "Assets/Thumbnail.png", 64,64);
this.load.spritesheet('star', "Assets/Stars.png", 20,20);
this.load.spritesheet('sound', "Assets/SoundButtons.png", 64,64);
this.load.spritesheet('enemy', "Assets/Enemy.png", 32,32);
this.load.spritesheet('Button', "Assets/Button.png",200,50);
this.load.spritesheet('flyEnemy', "Assets/Flying_Enemy.png", 25,23);
this.load.spritesheet('player', "Assets/Player.png", 16, 32);
this.load.spritesheet('coin', "Assets/Coin.png", 16, 16);
this.load.spritesheet('movePlatform', "Assets/MovingPlatform.png", 64,32);
//Sounds
this.load.audio('starSnd', ["Assets/getStar.mp3", "Assets/getStar.ogg"]);
// Load the Google WebFont Loader script
//NOTE: Load after the images or some won't load on first try
this.load.script('webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
},
create: function() {
this.state.start("MainMenu")
}
}