-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (49 loc) · 1.73 KB
/
main.js
File metadata and controls
77 lines (49 loc) · 1.73 KB
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
window.onresize()
loadSprites()
async function initGame(multiplayer=true){
clearTimeout(menuTimer)
pobjects = [];
planets = [];
const angle = Math.random()*360;// angle is in radians
pobjects.push(new Player(500 * Math.cos(angle), 500 * Math.sin(angle)))
pobjects.push(new Dock(700 * Math.cos(angle+0.1), 700 * Math.sin(angle+0.1)))
// combat testing
// pobjects.push(new LocalShield(1000 * Math.cos(angle+0.1), 1000 * Math.sin(angle+0.1), 10))
// pobjects.push(new Turret(1000 * Math.cos(angle+0.1), 1000 * Math.sin(angle+0.1), 'mini'))
// pobjects.push(new Turret(1000 * Math.cos(angle+0.1), 1000 * Math.sin(angle+0.1), 'gun'))
for(var i = 0; i < pobjects.length; i ++){// give the starting objects some random nudges
pobjects[i].vr = 0.01 * (Math.random()-0.5)
pobjects[i].rot = angle
pobjects[i].vx = Math.random()-0.5
pobjects[i].vy = Math.random()-0.5
}
p = pobjects[0]
updateInfo()
if(multiplayer){
chat.system("Joined Multiplayer")
await initSync()
generatePlanets()// this will get overriden if not alone
}else{
chat.system("Joined Singleplayer")
initEmptySync()
generatePlanets()
}
lastFrame = Date.now()
frameTimer = setInterval(runFrame, 16)
}
var frameTimer;
var lastFrame;
function runFrame(){
let dt = Date.now()-lastFrame
if(dt > 100){
console.log('frame stuttering, usability may suffer')
}
for(var i = 0; i < dt / 16 && i < 60; i++){// run additional frames, ensuring no more than 60 (1 second catchup)
iterateFrame()
}
renderFrame()
lastFrame = Date.now()
}
function halt(){clearTimeout(frameTimer)}
loadUserInfo()
initMenu()