-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface.moon
More file actions
209 lines (150 loc) · 3.57 KB
/
face.moon
File metadata and controls
209 lines (150 loc) · 3.57 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
{graphics: g} = love
class Tongue
approx_h: 30
sway_w: 40
shake_x: 0
shake_y: 0
new: (@track, @x, @y) =>
@target_x = @x
@target_y = @y - @approx_h
@default_x, @default_y = @target_x, @target_y
@time = 0
@update_shake!
@seq = nil
@lerp = 0
move: (@target_x, @target_y) =>
@seq = Sequence ->
tween @, 0.02, lerp: 1
tween @, 0.2, lerp: 0
@seq = nil
draw: =>
path = CatmullRomPath!
tx, ty = lerp(@default_x, @target_x, @lerp), lerp(@default_y, @target_y, @lerp)
-- pre base point
bx = @x + (@x - tx) * 2
by = @y - @approx_h / 3
path\add bx, by
path\add @x, @y
mx, my = lerp(@x, tx, 0.6), lerp(@y, ty, 0.2)
path\add mx + @shake_x, my + @shake_y
path\add tx, ty
path\add tx, ty - @approx_h / 2
z = 0
segs = [{x,y} for x, y in path\each_pt 0.5]
seg_count = #segs
COLOR\push 195, 124, 94
for {x, y} in *segs
g.push!
g.translate x,y
g.scale lerp(20, 10, z/seg_count), lerp(10, 5, z/seg_count)
c = lerp(100, 255, z/seg_count)
COLOR\push c,c,c
g.circle "fill", 0, 0, 1, 8
COLOR\push 220,220,220
g.circle "fill", 0,0, 0.8, 8
COLOR\pop!
COLOR\pop!
g.pop!
z += 1
COLOR\pop!
update: (dt) =>
@time += dt
@update_shake!
@seq\update dt if @seq
true
update_shake: =>
@shake_x = math.sin(@time * 2 + 9) * 5
@shake_y = math.cos(@time * 5) * 5
b, p = @track\get_beat!
if b
odd = b % 2 == 1
p = 1 - p if odd
else
b = 0
p = 0
-- dx = smoothstep -1, 1, p
dx = lerp -1, 1, cubic_bez 0.17, 0.44, 0.81, 0.56, p
@default_x = @x + dx * @sway_w
@default_y = @y - @approx_h
class Eye extends Box
w: 40
h: 20
flash_a: 0
ox: 0
oy: 0
new: (@x,@y, opts)=>
for k,v in pairs opts
@[k] = v
flash: =>
@seq = Sequence ->
@flash_a = 1
tween @, 0.2, flash_a: 0
@seq = nil
draw: =>
if @flash_a > 0
COLOR\pusha math.floor @flash_a * 255
@sprite\draw @x + @ox, @y + @oy
COLOR\pop!
if DEBUG
g.rectangle "line", @unpack!
update: (dt) =>
@seq\update dt if @seq
true
class Face extends Box
lazy {
sprite: => imgfy "images/adit.png"
pain_sprite: => Spriter "images/adit-pain.png"
}
pain_left: "28,86,29,17"
pain_right: "85,85,32,17"
eye_w: 20
eye_h: 10
eye_y: 50
w: 140
h: 210
new: (@track, ...) =>
super ...
@eyes = {
Eye @x + 23, @y + 84, {
sprite: imgfy "images/eye-left.png"
}
Eye @x + 82, @y + 83, {
sprite: imgfy "images/eye-right.png"
}
}
cx = @center!
@tongue = Tongue @track, cx + 5, @y + 155
hit_eye: (col) =>
eye = @eyes[col]
eye\flash!
@tongue\move eye\center!
eye_offset: (col=1) =>
@eyes[col]\center!
on_eye_pain: (col) =>
name = col == 1 and "left" or "right"
@["#{name}_hurts"] = Sequence ->
wait 0.5
@["#{name}_hurts"] = nil
draw: =>
if DEBUG
g.rectangle "line", @unpack!
g.push!
g.translate @tongue.x, @tongue.y
g.rotate @track\sync_sin! / 10
g.translate -@tongue.x, -@tongue.y
@sprite\draw @x, @y
if @left_hurts
@pain_sprite\draw @pain_left, @x + 28, @y + 86
if @right_hurts
@pain_sprite\draw @pain_right, @x + 85, @y + 85
g.pop!
for eye in *@eyes
eye\draw!
@tongue\draw!
update: (dt) =>
@tongue\update dt
@left_hurts\update dt if @left_hurts
@right_hurts\update dt if @right_hurts
for eye in *@eyes
eye\update dt
{ :Face, :Tongue }