-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
50 lines (39 loc) · 1.36 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
'use strict';
import { Game } from "./lib/imports.js";
var game = new Game()
let msPrev = window.performance.now()
const targetFPS = 60
const msPerFrame = 1000 / targetFPS
function gameLoop() {
requestAnimationFrame(gameLoop)
const msNow = window.performance.now()
const msPassed = msNow - msPrev
if (msPassed < msPerFrame) return
const excessTime = msPassed % msPerFrame
msPrev = msNow - excessTime
game.keyMan.update()
game.display.Game()
game.menu.tick()
if(game.State == "game"){
game.player.update()
}
if(game.keyMan.wasKeyJustPressed("KeyW") && game.State == "main"){
game.State = "game"
game.soundMenu.volume = .15
game.menu.loadShop()
if(game.Audios){
game.soundMenu.play()
}
game.player.grow(70)
//}else if(game.keyMan.wasKeyJustPressed("KeyS") && game.State == "main"){
//game.State = "settings"
//}else if(game.keyMan.wasKeyJustPressed("KeyS") && game.State == "settings"){
//game.State = "main"
}else if(game.keyMan.wasKeyJustPressed("KeyE") && game.State == "game"){
game.State = "shop"
}else if(game.keyMan.wasKeyJustPressed("KeyE") && game.State == "shop"){
game.State = "game"
game.display.leave = true
}
}
requestAnimationFrame(gameLoop)