-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.wren
76 lines (67 loc) · 1.93 KB
/
game.wren
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
import "xs" for Data, Input, Render
import "xs_math"for Math, Bits, Vec2, Color
import "xs_assert" for Assert
import "xs_ec"for Entity, Component
import "xs_components" for Transform, Body, Renderable, Sprite, GridSprite, AnimatedSprite
import "types" for Type
import "directions" for Directions
import "gameplay" for Level
class Game {
static loading { 0 }
static generating { 1 }
static starting { 2 }
static playing { 3 }
static gameover { 4 }
static config() { /* Using a file instead */ }
static init() {
Entity.init()
Level.init()
Tile.init()
Create.init()
Gameplay.init()
__time = 0
__state = generating // Skip loading
__alg = BSP
__genFiber = Fiber.new { __alg.generate() }
}
static update(dt) {
//Gameplay.debugRender()
if(__state == Game.generating) {
genStep(dt)
} else {
Gameplay.update(dt)
}
Entity.update(dt)
//__alg.debugRender()
}
static genStep(dt) {
var visualize = Data.getBool("Visualize Generation", Data.debug)
if(visualize) {
__time = __time - dt
if(__time <= 0.0) {
if(!__genFiber.isDone) {
__time = __genFiber.call()
} else {
__state = Game.playing
__alg.awesomize()
}
}
} else {
while(!__genFiber.isDone) {
__genFiber.call()
}
__state = playing
}
}
static render() {
if(__state == Game.generating) {
// Level.lightUp()
// Level.generationRender()
}
Level.render()
Renderable.render()
}
}
import "create" for Create
import "generators" for BSP
import "gameplay" for Hero, Tile, Gameplay