-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.wl
98 lines (81 loc) · 2.25 KB
/
mouse.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
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
98
import "entity.wl"
import "libwl/gl.wl"
import "libwl/mesh.wl"
import "libwl/image.wl"
import "libwl/fmt/tga.wl"
import "libwl/fmt/mdl.wl"
import "libwl/vec.wl"
import "libwl/file.wl"
import "libwl/random.wl"
import "libwl/collision.wl"
import "drawDevice.wl"
import "man.wl"
use "importc"
import(C) "math.h"
class Mouse : Entity {
static const int STATE_ROTATE = 0
static const int STATE_MOVE = 1
static GLMesh mesh
static GLTexture texture
float timer
int spin
bool dead
this() {
.spin = 1
if(!mesh) {
Mesh m = loadMdl(new StringFile(pack "res/mouse.mdl"))
.mesh = new GLMesh(m)
}
if(!texture) {
Image i = loadTGA(new StringFile(pack "res/mouse.tga"))
.texture = new GLTexture(i)
}
.rotation = randomFloat() * 6 // 6 = 2PI (close enough)
.position.v[0] = randomFloat() * 20.0f - 10.0f
.position.v[2] = randomFloat() * 20.0f - 10.0f
}
float nummies() return 0.15
bool isDead() return .dead
void update(float dt) {
.timer -= dt
if(.timer <= 0) {
.spin = -.spin
.timer = randomFloat() * 3
}
DuckMan d = DuckMan.getInstance()
Box3 dhit = d.getHitbox()
if(dhit.collides(.getHitbox())) {
if(d.scale * 2.2 > 1.6) {
d.eat(this)
.dead = true
} else {
d.dead = true
}
}
.rotation += 0.15 * .spin
vec4 dv = vec4(0, 0, -0.10, 0)
mat4 matrix = mat4()
matrix = matrix.rotate(.rotation, vec4(0, 1, 0, 0))
dv = matrix.vmul(dv)
if(.position.v[0] < -9.0f || .position.v[0] > 9.0f ||
.position.v[2] < -9.0f || .position.v[2] > 9.0f) {
if(dv.dot(.position) > 0) {
.timer /= 2.0f
.rotation = .rotation - 3.1415926;
return
}
}
.position = .position.add(dv)
}
Box3 getHitbox() {
vec4 dim = vec4(1.0, 1, 1.0, 0)
return Box3(.position, dim)
}
GLMesh getMesh() return mesh
GLTexture getTexture() return texture
}
void initMice() {
for(int i = 0; i < 2; i++) {
(Entity.add(new Mouse()))
}
}