-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
147 lines (132 loc) · 6.19 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
function changeControls(index) {
if (index == 0) {
keys = { up: 38, down: 40, right: 39, left: 37, a: 65, s: 83, d: 68, w: 87, shift: 16, r: 82, f: 70 };
}
else if (index == 1) {
keys = { up: 87, down: 83, right: 68, left: 65, a: 37, s: 40, d: 39, w: 38, shift: 16, r: 82, f: 70 };
}
document.getElementById('controls').blur();
}
function createPlayer(x, z, angle) {
MA.createPlayer(x, z, angle);
TH.camera.position.set(MA.player.position.x, 0, MA.player.position.y);
TH.camera.rotation.y = -MA.player.angle + (3 * Math.PI / 2);
}
function addWall(x, z, width, height, depth) {
TH.addWall(x, z, width, height, depth);
MA.addBox(x, z, width, depth);
}
function addSprite(x, y, z, width, height, scale, textureName, tilesX, tilesY, tilesTotal, duration, body, creature) {
var sprite = TH.addSprite(x, y, z, width, height, scale, textureName, tilesX, tilesY, tilesTotal, duration);
if (creature)
MA.addCircle(x, z, 10, sprite);
else if (body)
MA.addCircle(x, z, width * 8);
}
function addTorch (x, z) { addSprite(x, -8, z, 1, 2, 1, 'torch.png', 4, 1, 4, 200, true)}
function addSlug (x, y, z) { addSprite(x, y, z, 2, 1, 0.4, 'slug.png', 4, 1, 4, 200, true, true)}
function addLadder (x, z) { addSprite(x, 0, z, 2, 4, 0.6, 'ladder.png', true)}
function addEKG (x, z) { addSprite(x, -10, z, 2, 4, 0.4, 'ekg.png', 4, 1, 4, 200, true)}
function addGenerator (x, z) { addSprite(x, -14, z, 2, 4, 0.4, 'generator.png', 2, 1, 2, 300, true)}
function addStalagtite (x, y, z) { addSprite(x, y, z, 1, 2, 0.5, 'stalagtite' + (Math.floor(Math.random() * 4) + 1) + '.png')}
function addLamp (x, z) { addSprite(x, -18, z, 1, 2, 0.5, 'lamp.png', 2, 1, 2, 800, true)}
function addScrap (x, z) { addSprite(x, -20, z, 1, 2, 0.5, 'scrap' + (Math.floor(Math.random() * 2) + 1) + '.png', 0, 0, 0, 0, true)}
function addPipe (x, z) { addSprite(x, 0, z, 0.75, 3, 1, 'pipe' + (Math.floor(Math.random() * 4) + 1) + '.png', 0, 0, 0, 0, true)}
function addPebble(x, z) { addSprite(x, -30, z, 1, 1, 1, 'pebble.png')}
function addStruggler(x, z) { addSprite(x, -18, z, 4, 2, 0.5, 'corpse2.png', 2, 1, 2, 800, true)}
function addScaffoldWire(x, z) { addSprite(x, -TH.floorY, z, 0.75, 5, 1, 'wire.png', 0, 0, 0, 0)}
function addTube(x, z) { addSprite(x, 0, z, 4, 8, 0.6, 'tube.png', 2, 1, 2, 800, true)}
function addEmptyTube(x, z) { addSprite(x, 0, z, 4, 8, 0.6, 'empty_tube.png', 0, 0, 0, 0, true)}
function addComputer(x, z) { addSprite(x, -10, z, 4, 4, 0.4, 'computer.png', 2, 1, 2, 400, true)}
function addChair(x, z) { addSprite(x, -10, z, 1, 4, 0.4, 'chair.png', 0, 0, 0, 0, true)}
function addFileCabinet(x, z) { addSprite(x, -16, z, 2, 4, 0.4, 'file_cabinet.png', 0, 0, 0, 0, true)}
function addHiveMind(x, z) { addSprite(x, 0, z, 8, 16, 0.5, 'hivemind.png')}
function addHiveMindInner(x, z) { addSprite(x, 0, z, 4, 4, 0.5, 'hivemind_inner.png', 4, 1, 4, 300)}
function addTentacle(x, y, z) { addSprite(x, y, z, 1, 4, 0.5, 'tentacle.png', 4, 1, 4, 400, true)}
function addTentacle2(x, y, z) { addSprite(x, y, z, 1, 4, 0.5, 'tentacle2.png', 4, 1, 4, 400, true)}
function addHangingScrap(x, y, z) { addSprite(x, y, z, 1, 4, 0.5, 'scrap' + (Math.floor(Math.random() * 3) + 1) + 'hang.png')}
function addOrgan(x, z) { addSprite(x, 0, z, 2, 4, 0.5, 'organ1.png', 4, 1, 4, 300, true)}
function addWart(x, y, z) { addSprite(x, y, z, 1, 1, 0.5, 'wart.png', 4, 1, 4, 300)}
function addArtery(x, z) { addSprite(x, 0, z, 2, 8, 0.5, 'artery.png', 4, 1, 4, 300, true)}
function addEye(x, y, z) { addSprite(x, y, z, 1, 1, 0.5, 'eye.png')}
function addWallShape(x, y, z, width, height, points, textureNames, addBodies, transparent) {
for (key in points) {
var point = points[key];
if (point.next < 0)
continue;
var next = points[points[key].next];
var p1 = {x: point.x + x, y: point.y + z};
var p2 = {x: next.x + x, y: next.y + z};
var textureName = textureNames[Math.floor(Math.random() * textureNames.length)];
TH.addWallPlane(p1, p2, width, height, textureName, y, transparent);
if (addBodies)
MA.addWall(p1, p2);
}
}
function addAnimatedWall(p1, p2, y, height, textureName, tilesX, tilesY, totalTiles, delay, addBody) {
if (addBody)
MA.addWall(p1, p2);
TH.addAnimatedPlane(p1, p2, y, height, textureName, tilesX, tilesY, totalTiles, delay);
}
function rotatePlayer(angle) {
MA.rotatePlayer(-angle);
TH.camera.rotation.y = -MA.player.angle + (3 * Math.PI / 2);
}
function moveForward(moveSpeed) {
var xv = Math.cos(MA.player.angle) * moveSpeed;
var yv = Math.sin(MA.player.angle) * moveSpeed;
Matter.Body.applyForce(MA.player, MA.player.position, {x: xv, y: yv});
}
function moveLeft(moveSpeed) {
var xv = Math.cos(MA.player.angle - Math.PI / 2) * moveSpeed;
var yv = Math.sin(MA.player.angle - Math.PI / 2) * moveSpeed;
Matter.Body.applyForce(MA.player, MA.player.position, {x: xv, y: yv});
}
function moveRight(moveSpeed) {
var xv = Math.cos(MA.player.angle + Math.PI / 2) * moveSpeed;
var yv = Math.sin(MA.player.angle + Math.PI / 2) * moveSpeed;
Matter.Body.applyForce(MA.player, MA.player.position, {x: xv, y: yv});
}
function moveBackward(moveSpeed) {
var xv = -Math.cos(MA.player.angle) * moveSpeed;
var yv = -Math.sin(MA.player.angle) * moveSpeed;
Matter.Body.applyForce(MA.player, MA.player.position, {x: xv, y: yv});
}
function update() {
var moveSpeed = 1;
if (debug && keys.shift in keysDown)
moveSpeed = 8;
TH.camera.position.set(MA.player.position.x, 0, MA.player.position.y);
if (keys.left in keysDown)
rotatePlayer(0.03);
else if (keys.right in keysDown)
rotatePlayer(-0.03);
if (keys.w in keysDown)
moveForward(moveSpeed);
else if (keys.s in keysDown)
moveBackward(moveSpeed);
if (keys.a in keysDown)
moveLeft(moveSpeed);
else if (keys.d in keysDown)
moveRight(moveSpeed);
if (debug) {
MA.updateView();
updateDebug();
}
TH.update();
}
function init() {
MA.init();
TH.init();
//loadLevel1();
//TH.clearScene();
//MA.clearWorld();
loadLevel2();
loadLevel3();
loadLevel4();
loadLevel5();
loadLevel6();
}
init();
MA.run();
TH.run(update);