/
main.js
97 lines (79 loc) · 2.96 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
global.Class = require('js-class');
global.THREE = require('three');
global.Physijs = require('physijs-browserify')(THREE);
require('hamsterjs');
require('./RequestAnimationFrame.js');
require('./rubbable.js');
var SuperGif = require('./libgif.js');
var Utils = require('./js/Utils.js');
require('./js/Game.js');
require('./js/Globals.js');
require('./js/ResourceManager.js');
require('./js/PointerLockControls.js');
require('./js/EntityFactory.js');
require('./js/Systems.js');
require('./js/MouseController.js');
require('./js/SoundController.js');
Physijs.scripts.worker = './libs/physijsWorker.js';
Physijs.scripts.ammo = './ammo.js';
// purpose: function as a basic FPS game using an ECS (entity-component system) pattern and behavior trees for AI
//
// requires: RequestAnimationFrame.js, three.js, three-pointerlockcontrols.js, stats.js, js-class.js, physijs, tiny-ecs, Hamster.js
// ./js/*, /js/components/*
//
// author: Cornell Daly
//
// date: November 3, 2015
//
// additional notes: code is separated into multiple files/folders
var game = null;
function init() {
Globals.instance.hudLeftElement = document.getElementById("hudLeft");
Globals.instance.hudRightElement = document.getElementById("hudRight");
Globals.instance.healthElement = document.getElementById("health");
Globals.instance.shieldElement = document.getElementById("shield");
Globals.instance.ammoElement = document.getElementById("ammo");
Globals.instance.scoreElement = document.getElementById("score");
Globals.instance.reloadingElement = document.getElementById("reloading");
Globals.instance.reloadImg = new SuperGif({
gif: document.getElementById("reloadImg")
});
Globals.instance.reloadImg.load();
Globals.instance.weaponSelectorElement = document.getElementById("weaponSelector");
Globals.instance.weaponNameElement = document.getElementById("weaponName");
Globals.instance.weaponIconElement = document.getElementById("weaponIcon");
Globals.instance.waveElement = document.getElementById("wave");
Globals.instance.overlayElement = document.getElementById("overlay");
var gameOptions = {
container: document.getElementById("container"),
loadingContainer: document.getElementById("loadingContainer"),
blocker: document.getElementById("blocker"),
instructions: document.getElementById("instructions"),
modelsToPreload: [
"models/potato.json",
"models/potatoCannon.json",
"models/character.json",
"models/fry.json",
"models/pickupBox.json"
],
soundsToPreload: [
"sfx/arrowlessBow.mp3",
"sfx/hitSplat.wav",
"sfx/hurt1.mp3",
"sfx/hurt2.mp3",
"sfx/hurt3.mp3"
],
texturesToPreload: [
'gfx/brick-floor-tileable_COLOR.jpg',
'gfx/brick-floor-tileable_DISP.jpg',
'gfx/brick-floor-tileable_SPEC.jpg',
'gfx/smoketex.jpg',
'gfx/potatoIcon.png',
'gfx/frenchFriesIcon.png',
'gfx/skyTex2.jpg'
]
};
game = new Game(gameOptions);
game.start();
}
init();