forked from loglot/yet-another-2d-platformer-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
97 lines (66 loc) · 2.17 KB
/
main.js
File metadata and controls
97 lines (66 loc) · 2.17 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
'use strict';
import { Game } from "./imports/import.js"
class Main {
game = new Game(this)
currentTime = 1
deltaTime = 1
lastTime
async startGame() {
if(localStorage) {this.game.storage.accessible = false} else {this.game.storage.accessible = true}
this.game.storage.check()
//this.game.autoDebug()
while (true) {
//this.game.updateGame();
this.currentTime = Date.now();
this.game.gameDisplayer.drawGameFrame();
if (this.game.debug.playerHitbox) {
this.game.player.drawHitbox()
}
if (this.game.debug.mapBuilder) {
this.game.mapEdit.drawHitbox()
}
this.game.keys.drawKeys()
if(this.game.menu.check) {
this.updateGame();
} else {
this.game.menu.drawMenu()
if(this.game.keyManager.wasKeyJustPressed("KeyW") && !this.game.menu.checkDos) {
this.game.menu.fade()
}
}/**/
this.game.keyManager.update();
this.lastTime = Date.now()
await this.sleep(1000/60);
}
}
updateGame() {
// Update variables
this.game.player.update();
this.game.debug.update();
this.game.camera.update();
if(this.game.debug.mapBuilder){
this.game.mapEdit.update();
}
this.game.hook.update();
this.game.sword.update()
this.game.storage.update()
this.DeltaTime()
if (this.game.keyManager.wasKeyJustPressed("KeyP") && this.game.menu.checkDos) {
this.game.menu.fade("up")
}
this.deltaTime = (this.currentTime - this.lastTime)/20;
// Update input
}
autoDebug() {
this.game.debug.debugMode = true
this.game.debug.bean = false
this.game.debug.noClip = true
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
DeltaTime(){
}
}
var game = new Main();
game.startGame();