-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.js
93 lines (71 loc) · 2.81 KB
/
game.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
import * as BABYLON from 'babylonjs';
import { scene, engine, canvas, camera, cambox } from './globals';
import Utils from './utils';
import Sounds from './sounds';
import options from './options';
import showAxis from './axis'
import MonsterManager from './MonsterManager';
import ProjectileManager from './ProjectileManager';
import MapEditor from './MapEditor';
import UIManager from './UIManager';
import KeyboardManager from './KeyboardManager';
import ParticleManager from './ParticleManager';
import DecalManager from './DecalManager';
import { MapManager } from './MapManager';
import { vertex } from './MapManager';
import YOUIManager from './YOUIManager';
console.log(YOUIManager);
var game = {
init: function(assets) {
console.log("Initializing the game");
if(options.showAxis) { showAxis(10) }
console.log("Initialzing assets");
var Materials = assets.materials;
console.log("Initializing Monster Manager");
DecalManager.init(assets);
ParticleManager.init(assets);
MonsterManager.init(assets);
MapManager.init(assets);
//UIManager.init(assets);
YOUIManager.init(assets);
MapEditor.init();
KeyboardManager.init();
console.log("Adding beautiful lights");
var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene);
console.log("Adding a beautiful floor");
for(var i = 0; i < 1; i++) {
let Imp = MonsterManager.create('cacodemon');
var mvertex = new vertex(Math.random() * 50, Imp.hitboxProps.height/2, Math.random() * 50);
Imp.hitbox.position = new BABYLON.Vector3(0, Imp.hitboxProps.height/2, 40);
//Imp.sprite.position = Imp.hitbox.position;
}
//var a = MapManager.createWall(new vertex(0, 0, 0), new vertex(10, 0, 0), 10);
//var music = new BABYLON.Sound("Music", "sounds/e2m1.mp3", scene, null, { loop: true, autoplay: true });
var tick = 0;
console.log("Running the engine loop");
var fpsLabel = document.getElementById("fpsLabel");
engine.runRenderLoop(function(){
tick++;
if(tick % 100 == 0) {
if(options.hell) {
let Imp = MonsterManager.create('cacodemon');
var mvertex = new vertex(Math.random() * 50, Imp.hitboxProps.height/2, Math.random() * 50);
Imp.hitbox.position = new BABYLON.Vector3(0, Imp.hitboxProps.height/2, -mvertex.z);
Imp.sprite.position = Imp.hitbox.position;
}
tick = 0;
}
MapEditor.update();
KeyboardManager.update();
MonsterManager.update();
//UIManager.update();
YOUIManager.update();
cambox.position = camera.position;
cambox.rotation = camera.rotation;
ProjectileManager.update();
scene.render();
fpsLabel.innerHTML = engine.getFps().toFixed() + " fps";
});
}
};
export default game;