-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.js
118 lines (108 loc) · 3.21 KB
/
data.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
/* jshint esversion: 6 */
// CALLED BEFORE GAME, AFTER DATA/HELPER
var WIDTH = 1280;
var HEIGHT = 720;
var VCENTER = HEIGHT/2;
var HCENTER = WIDTH/2;
// IMAGES TO LOAD INTO PIXI
// AND MUSIC WITH HOWLER
var IMAGES = [];
var MUSICS = [];
var SOUNDS = [];
var DATA = (function() {
var prefix = "resources/";
var music_prefix = "music/";
var sounds_prefix = "sounds/";
var extentions = ["B1", "B2", "F1", "F2", "S1", "S2"];
return {
add: function(img, name) {
IMAGES[IMAGES.length]=[img,name];
},
add_simple: function(sname) {
this.add(sname+".png", sname);
},
add_hidable: function(sname) {
this.add_simple(sname);
this.add_simple(sname+'X');
},
add_folder: function(sname) {
for (var i = 0; i < extentions.length; i++) {
this.add(sname+"/"+sname+extentions[i]+".png", sname+extentions[i]);
}
},
add_music: function(file, name) {
MUSICS[name] = new Howl({
src: [music_prefix+file+'.ogg', music_prefix+file+'.mp3'],
loop: true,
volume: 0.4
});
},
add_sound: function(file, name) {
SOUNDS[name] = new Howl({
src: [sounds_prefix+file+'.ogg', sounds_prefix+file+'.mp3'],
volume: 0.4
});
},
get_sound: function(name) {
return SOUNDS[name];
},
play_sound: function(name) {
SOUNDS[name].play();
},
play: function(name) {
MUSICS[name].play();
},
stop: function(name) {
MUSICS[name].stop();
},
stop_all: function() {
for (var song in MUSICS) {
MUSICS[song].stop();
}
},
run: function(callback) {
let loader = PIXI.loader;
for ( let i = 0; i < IMAGES.length; i++ ){
loader.add(IMAGES[i][1], prefix + IMAGES[i][0]);
}
loader.load(callback);
},
getTexture: function(texture_name) {
return getTexture(texture_name);
}
};
})();
DATA.add_simple("bg");
DATA.add_simple("cardthing");
DATA.add_simple("trashcan");
DATA.add_simple("wallH");
DATA.add_simple("wallV");
DATA.add_simple("bossdoor");
DATA.add_simple("example");
DATA.add_simple("blend");
DATA.add_simple("menutitel");
DATA.add_simple("chair1");
DATA.add_simple("chair2");
DATA.add_hidable("printer");
DATA.add_hidable("shelf");
DATA.add_hidable("fridge");
DATA.add_hidable("tabelH");
DATA.add_hidable("tabelV");
DATA.add_hidable("vase");
DATA.add_hidable("plant");
DATA.add_folder("coworker");
DATA.add_folder("boss");
DATA.add_folder("hero");
DATA.add_music("TheOfficeMain", "office");
DATA.add_music("Boss_Theme", "boss");
DATA.add_music("Menu_Theme", "menu");
DATA.add_sound("NeedAir", "air");
DATA.add_sound("explosion", "explosion");
DATA.add_sound("notice", "notice");
document.addEventListener("click", () => resumeHowler());
document.addEventListener("keydown", () => resumeHowler());
function resumeHowler() {
Howler.ctx.resume().then(() => {
console.log("AudioContext resumed successfully");
});
}