-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie.wl
71 lines (59 loc) · 1.64 KB
/
cookie.wl
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
import "libwl/vec.wl"
import "libwl/gl.wl"
import "libwl/mesh.wl"
import "libwl/image.wl"
import "libwl/file.wl"
import "libwl/fmt/mdl.wl"
import "libwl/fmt/tga.wl"
import "libwl/collision.wl"
import "entity.wl"
import "man.wl"
import "drawDevice.wl"
class Cookie : Entity {
static GLMesh mesh
static GLMesh monkey
static GLTexture texture
float tick
bool dead
bool isDead() return .dead
bool areYouCookie() return true
this() {
if(!.mesh) {
Mesh m = loadMdl(new StringFile(pack "res/cookie.mdl"))
.mesh = new GLMesh(m)
m = loadMdl(new StringFile(pack "res/monkey.mdl"))
.monkey = new GLMesh(m)
}
if(!.texture) {
Image i = loadTGA(new StringFile(pack "res/cookie.tga"))
.texture = new GLTexture(i)
}
}
void update(float dt) {
.tick += dt
DuckMan d = DuckMan.getInstance()
Box3 dhit = d.getHitbox()
if(!.dead and dhit.collides(.getHitbox())) {
//WIN
d.eat(this)
.dead = true
}
}
Box3 getHitbox() {
return Box3(.position, vec4(0.25, 0.25, 0.25, 0))
}
void draw(mat4 view) {
GLDrawDevice dev = GLDrawDevice.getInstance()
mat4 mat = mat4()
mat = mat.scale(2, 2, 2)
mat = mat.rotate(0.71, vec4(1, 0, 0, 0))
mat = mat.rotate(.tick * 2, vec4(0, 1, 0, 0))
mat = mat.translate(.position)
mat = view.mul(mat)
if(dev.crazy) {
dev.runMeshProgram(.monkey, .texture, mat)
} else {
dev.runMeshProgram(.mesh, .texture, mat)
}
}
}