-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (44 loc) · 1.15 KB
/
script.js
File metadata and controls
50 lines (44 loc) · 1.15 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
document.addEventListener('DOMContentLoaded', ()=>{
c = document.getElementById('maincanvas')
ctx = c.getContext('2d')
game.init()
})
let c
let ctx
const game = {
resize:function(){
c.width = window.visualViewport.width - 20
c.height = window.visualViewport.height - 30
},
init:function(){
game.resize()
window.addEventListener('resize', game.resize)
ctx.fillStyle = "#000000"
ctx.fillRect(0,0,c.width,c.height)
balls.init()
player.init()
iterator = setInterval(game.iterate, 16)
},
iterator:null,
lastUpdate:null,
iterate:function(){
let dtime
if(!game.lastUpdate){dtime = 1}else{
dtime = 60*Math.min(Date.now()-game.lastUpdate,1000)/1000
}
game.lastUpdate = Date.now()
balls.iterate(dtime)
lasers.iterate(dtime)
player.iterate(dtime)
fx.iterate(dtime)
game.render()
},
render:function(){
ctx.fillStyle="#00000066"
ctx.fillRect(0,0,c.width,c.height)
balls.render()
lasers.render()
player.render()
fx.render()
}
}