-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
358 lines (357 loc) · 13 KB
/
main.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var GLOBAL_MUSIC_ASSETS = [];
var GLOBAL_SOUND_ASSETS = [
'click.wav',
'bottle.ogg',
'coin.ogg',
'damage.ogg',
'splash.ogg',
'creepysound1.ogg'
];
var GLOBAL_ASSETS = [
///////////////////////////////////////////
// Atlases
///////////////////////////////////////////
'tiles1.json',
'smallfontx1.xml',
];
exports.PIXI = window.PIXI;
/*
import {config} from "./config";
import {Game} from "./Stages/Game";
import {SM} from "./Stages/SM";
import {Sound} from "./Sound";
import {Menu} from "./Stages/Menu";
import {PauseTimer} from "./PauseTimer";
import {CharacterSelect} from "./Stages/CharacterSelect";
import {Controls} from "./Controls";
import {LM} from "./lm";
import {network} from "./Network";
import {LookingForCompanions} from "./Stages/LookingForCompanions";
import {GameShop} from "./Stages/GameShop";
*/
exports.SCR_WIDTH = 800; //config.Client.ScreenWidth;
exports.SCR_HEIGHT = 600; //config.Client.ScreenHeight;
var SCR_SCALE = 1.0;
var FRAME_RATE = 60;
var FRAME_DELAY = 1000 / FRAME_RATE;
var DEBUG = false;
//asdasd
var Main = (function () {
function Main() {
// public menu: Menu = new Menu();
// public game: Game = new Game();
// public shop: GameShop = new GameShop();
//
// public charSel: CharacterSelect = new CharacterSelect();
// public companions: LookingForCompanions = new LookingForCompanions();
this.fps = 0;
this.lastLoop = 0;
this.totalFrames = 0;
this.totalDelta = 0;
this.TweenMax = window.TweenMax;
// public sm: SM;
// public lm: LM;
this.worldSpeed = 1;
this.debug = true;
// public timer: PauseTimer = new PauseTimer();
this.isInitialLoading = true;
this.assetsLoaded = 0;
this.delta = 0;
this.delta2 = 0; // 1000 / delta time
this.shaders = {};
// private prevPos: Vec2 = null;
this.loadingCounter = 0;
this.__DIR = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);
}
Main.GET = function (url, cb) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
cb(xmlHttp.responseText);
}
};
xmlHttp.open("GET", url, true); // true for asynchronous
xmlHttp.send(null);
};
Main.prototype.start = function () {
var _this = this;
var pr = "testprivate";
var pub = "testpublic";
document.addEventListener('contextmenu', function (event) {
if (_this.onContext)
_this.onContext();
event.preventDefault();
});
setTimeout(function () {
// this.saveAnalytics()
}, 10 * 1000);
this.stats = new Stats();
document.body.appendChild(this.stats.domElement);
this.stats.domElement.style.position = "absolute";
this.stats.domElement.style.top = "0px";
// document.body.requestPointerLock();
// this.controls = new Controls();
this.PIXI = exports.PIXI;
this.app = new exports.PIXI.Application(exports.SCR_WIDTH, exports.SCR_HEIGHT, { resolution: 1, antialias: true,
preserveDrawingBuffer: true });
document.body.appendChild(this.app.view);
this.app.ticker.add(this.animate.bind(this));
requestAnimationFrame(this.animate.bind(this));
};
;
Main.prototype.addSprite = function (px, py) {
var tex = exports.PIXI.Texture.fromFrame("wall2.png");
var s = new exports.PIXI.Sprite(tex);
s.x = px;
s.y = py;
return s;
};
Main.prototype.cs = function (s, layer) {
if (layer === void 0) { layer = null; }
var texture = exports.PIXI.Texture.fromFrame(s);
var gfx = new exports.PIXI.Sprite(texture);
gfx.anchor.x = .5;
gfx.anchor.y = .5;
if (layer)
layer.addChild(gfx);
else {
// _.sm.ol.addChild(gfx);
}
//this.sm.ol.addChild(gfx);
return gfx;
};
Main.prototype.loadComplete = function () {
var _this = this;
document.addEventListener("keydown", function (e) {
var keyCode = e.keyCode;
switch (keyCode) {
case 68:
_this.restartScene();
break;
}
});
this.isInitialLoading = false;
this.bg = new exports.PIXI.Container();
this.bg1 = new exports.PIXI.Container();
this.bg2 = new exports.PIXI.Container();
this.bg1.z = 10;
this.bg2.z = 50;
//Light layer in front of everything but has same transformations as bg2
this.lightLayer = new exports.PIXI.Container();
this.lightLayer.z = 50;
this.app.stage.interactive = true;
this.app.stage.mousedown = function (e) {
_this.startSpawn = true;
};
this.app.stage.mouseup = function (e) {
_this.startSpawn = false;
};
this.app.stage.addChild(this.bg);
this.bg.addChild(this.bg2);
this.bg.addChild(this.bg1);
this.app.stage.addChild(this.lightLayer);
};
Main.prototype.processSelectEffect = function () {
var PIXINeutrinoContext = window.PIXINeutrinoContext;
var PIXINeutrinoEffectModel = window.PIXINeutrinoEffectModel;
var PIXINeutrinoEffect = window.PIXINeutrinoEffect;
var neutrinoContext = new PIXINeutrinoContext(exports._.app.renderer);
var effectModel = new PIXINeutrinoEffectModel(neutrinoContext, '../LightingDemo/effects/water_stream.js');
var effect = new PIXINeutrinoEffect(effectModel, [200, 200, 0], // Starting position of effect
0, // (optional) Starting rotation in degrees
[1, 1, 1]);
this.bg.addChild(effect);
setInterval(function () {
effect.update(16);
}, 16);
};
Main.prototype.load = function () {
var _this = this;
this.loader = new this.PIXI.loaders.Loader();
this.assets = GLOBAL_ASSETS;
this.loadingCounter = 0;
this.loader.add(this.assets);
var onAssetsLoaded = function () {
_this.loadingCounter++;
if (_this.loadingCounter == 1)
_this.loadComplete();
};
this.loader.on('complete', onAssetsLoaded);
this.loader.on('progress', function (loader, evt) {
_this.assetsLoaded++;
if (evt.name.indexOf('shaders') > 0) {
var result = evt.name.substring(evt.name.lastIndexOf("/") + 1);
_this.shaders[result] = evt.data;
}
if (evt.name.indexOf('/') > 0 && evt.isXml) {
var result = evt.name.substring(evt.name.lastIndexOf("/") + 1);
result = result.substring(0, result.length - 4);
}
});
this.loader.load();
};
Main.prototype.recursiveMove = function (cont) {
for (var _i = 0, _a = cont.children; _i < _a.length; _i++) {
var x = _a[_i];
if (x instanceof exports.PIXI.Container) {
this.recursiveMove(x);
}
if (x instanceof exports.PIXI.Sprite) {
var dx = exports.SCR_WIDTH / 2 - x.x;
var dy = exports.SCR_HEIGHT / 2 - x.y;
x.x += dx / 1000;
x.y += dy / 1000;
}
}
};
Main.prototype.animate = function () {
this.stats.begin();
this.random = Math.random();
this.time = (new Date()).getTime();
var pos = this.app.renderer.plugins.interaction.mouse.global;
if (this.startSpawn) {
var spr = exports._.cs("bluebonus.png", null);
spr.x = pos.x + 40 * (Math.random() - 0.5);
spr.y = pos.y + 40 * (Math.random() - 0.5);
if (this.random > 0.6) {
this.bg1.addChild(spr);
}
else if (this.random > 0.3) {
// this.bg1.addChild(spr);
} //else
var tf = new exports.PIXI.extras.BitmapText("asdasd dfsdf" + Math.random().toString(), { font: "smallfontx1", alight: "center" });
var mask = new exports.PIXI.Graphics();
mask.clear();
mask.beginFill(0xffffff, 1);
var w = tf.width - 10;
var value = Math.random();
mask.drawRect(-w / 2, w * (1 - value) - w / 2, w, w * (value));
mask.endFill();
tf.mask = mask;
tf.addChild(mask);
tf.x = pos.x;
tf.y = pos.y;
tf.scale.x = Math.random() + 1;
tf.scale.y = Math.random() + 1;
tf.tint = Math.random() * 9999999;
this.bg1.addChild(tf);
this.recursiveMove(this.app.stage);
tf.alpha = Math.random();
if (Math.random() < 0.1)
tf.alpha = 0;
// this.lightLayer.addChild(spr);
}
this.stats.end();
};
Main.prototype.restartScene = function () {
this.resetScene();
for (var x = 0; x < 20; ++x) {
for (var y = 0; y < 20; ++y) {
if (x == 1 && y == 1)
continue;
var s_1 = this.addSprite(x * 90, y * 90);
s_1.scale.x = 50;
s_1.scale.y = 50;
s_1.tint = 0x778899;
this.bg2.addChild(s_1);
}
}
for (var x = 0; x < 20; ++x) {
for (var y = 0; y < 20; ++y) {
if (Math.random() > .6) {
var s_2 = this.addSprite(x * 90, y * 90);
s_2.tint = 0xff000000;
this.bg1.addChild(s_2);
}
}
}
var delta = 140;
var resetAmbient = function (a, obj) {
a.clear();
a.beginFill(91000000 + (0.5 + 0.5 * Math.sin((new Date()).getSeconds() / 100)) * 255, 1);
a.drawRect(obj.x, obj.y, obj.width, obj.height);
a.endFill();
};
var l = {
gfx: new exports.PIXI.Sprite(),
ambient: exports.PIXI.Graphics,
newAmbient: function (col) {
var a = new exports.PIXI.Graphics();
return a;
},
addLight: function (l) {
l.blendMode = exports.PIXI.BLEND_MODES.ADD;
l.tint = 0xff000000;
this.gfx.addChild(l);
},
filterArea: new exports.PIXI.Rectangle(-delta, -delta, exports.SCR_WIDTH + 2 * delta, exports.SCR_HEIGHT + 2 * delta),
};
setInterval(function () {
resetAmbient(l.ambient, l.filterArea);
}, 30);
l.ambient = l.newAmbient(0x556677);
l.gfx.filters = [new exports.PIXI.filters.VoidFilter()];
l.gfx.filters[0].blendMode = exports.PIXI.BLEND_MODES.MULTIPLY;
l.gfx.filterArea = l.filterArea;
this.lightLayer.addChild(l.gfx);
l.gfx.addChild(l.ambient);
//this is front smooth light it shouldnt cut
var s = new exports.PIXI.Sprite(exports.PIXI.Texture.fromFrame("lightship.png"));
s.x = 300;
s.y = 100;
l.addLight(s);
//here's windows, windows should be cutted
s = new exports.PIXI.Sprite(exports.PIXI.Texture.fromFrame("lightsqure.png"));
s.x = -s.width / 2 + 100;
s.y = -s.height / 2 + 120;
var brt = new exports.PIXI.BaseRenderTexture(s.width, s.height, exports.PIXI.SCALE_MODES.LINEAR, 1);
var rt = new exports.PIXI.RenderTexture(brt);
var mask = new exports.PIXI.Sprite(rt);
mask.x = 0;
mask.y = 0;
//bg1.x = - 100;
// bg1.y = - 100;
// bg1.tint = 0x000000;
/* let clr = new PIXI.Graphics();
clr.clear();
clr.beginFill(0x000000, 1);
clr.drawRect(0, 0, 2000, 2000);
clr.endFill();*/
setTimeout(1000, function () {
// this.app.stage.addChild(clr);
// this.renderer.render(clr, rt);
mask.x += 200;
mask.y += 200;
});
this.bg1.x = 12;
this.bg1.y = -20;
// this.app.stage.addChild(mask);
//s.addChild(mask);
//s.mask = mask;
//this.app.stage.addChild(mask);
l.addLight(s);
if (!this.check) {
this.check = true;
this.processSelectEffect();
}
};
Main.prototype.resetScene = function () {
for (var x = this.bg1.children.length - 1; x > 0; x--) {
this.bg1.removeChildAt(0);
}
for (var x = this.bg2.children.length - 1; x > 0; x--) {
this.bg2.removeChildAt(0);
}
for (var x = this.lightLayer.children.length - 1; x > 0; x--) {
this.lightLayer.removeChildAt(0);
}
};
return Main;
}());
exports.Main = Main;
exports._ = new Main();
exports._.start();
exports._.load();
//# sourceMappingURL=main.js.map