-
Notifications
You must be signed in to change notification settings - Fork 0
/
girl.wl
125 lines (103 loc) · 3.21 KB
/
girl.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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"
import(C) "SDL/SDL_mixer.h"
Mix_Chunk^ girlDead
class GirlDuck : Entity {
static const int STATE_ROTATE = 0
static const int STATE_MOVE = 1
static GLMesh mesh
static GLTexture texture
float scale
int state
int spin
bool dead
float timer
bool isDead() return .dead
this() {
.scale = 1.5f
.spin = 1
if(!mesh) {
Mesh m = loadMdl(new StringFile(pack "res/pillduck.mdl"))
.mesh = new GLMesh(m)
}
if(!texture) {
Image i = loadTGA(new StringFile(pack "res/girlduck.tga"))
.texture = new GLTexture(i)
}
if(!girlDead)
girlDead = Mix_LoadWAV_RW(SDL_RWFromFile("res/girldead.wav", "rb"), 1)
.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.07f
void update(float dt) {
static float tick
bool inflection = cos(tick * 20.0f) < 0.0f and cos((tick + dt) * 20.0f) > 0.0f
float targety = fabs(sin(tick * 10.0f)) / 4.0f
tick += dt
.timer -= dt
if(.timer <= 0) {
.state = !.state //swap tween rotate/move
if(randomFloat() > 0.4) .spin = -.spin
if(.state == 0) {
.timer = randomFloat() 1.5f
} else {
.timer = randomFloat() * 3.0f
}
}
DuckMan d = DuckMan.getInstance()
Box3 dhit = d.getHitbox()
if(dhit.collides(.getHitbox())) {
if(d.scale > .scale) {
d.eat(this)
.dead = true
Mix_PlayChannelTimed(-1, girlDead, 0, -1)
} else {
d.dead = true
}
}
if(.state == 0) {
.rotation += 0.25 * .spin
if(randomFloat() > 0.95) .spin = -.spin
} else if(.state == 1) {
.rotation += 0.1 * .spin
if(randomFloat() > 0.96) .spin = -.spin
vec4 dv = vec4(0, 0, -0.05 * sqrt(.scale), 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) {
.state = 0
.timer /= 2.0f
return
}
}
.position = .position.add(dv)
.position.v[1] = (.position.v[1] + (targety - .position.v[1]) * 0.6f)
} else {
.state = 0
}
}
Box3 getHitbox() {
vec4 dim = vec4(1.5, 2.5, 1.5, 0)
dim.mul(.scale)
return Box3(.position, dim)
}
GLMesh getMesh() return mesh
GLTexture getTexture() return texture
}