-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
571 lines (498 loc) · 15.4 KB
/
main.lua
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
local moonshine = require 'moonshine'
require "mic"
function love.load()
-- Setup the window
love.window.setTitle( "FlappingHead" )
love.window.setMode( 750, 780, {resizable=true, vsync=false, minwidth=200, minheight=200} )
icon = love.image.newImageData("icon.png")
love.window.setIcon(icon)
screenHeight = 2000
screenWidth = 2000
--Setup Scaling
startHeight=780
xScale = 1
yScale = 1
--PropList
props = {}
propNames = {}
prop = 1
propToggle = false
mood = "neutral"
rotation = 0
tick = 0
--0.01-0.1 are "normal" values higher = more extreme
bobbleConstant = 0.02
--Default Keybinds
moodUpKey = "up"
moodDownKey = "down"
moodRightKey = "right"
moodLeftKey = "left"
moodResetKey = "r"
nextPropKey = "'"
lastPropKey = ";"
togglePropKey = "/"
--Setting the Background Color
bgRed = 0
bgGreen = 255
bgBlue = 0
bgBrightness = 255
filterMode = "nearest"
anistropy = 0
-- Setting RootDirectory
rootDir = love.filesystem.getSourceBaseDirectory()
success = love.filesystem.mount(rootDir, "Root")
-- find the offsets by moving your mouse over the center of the mouth, and seeing the x and y coordinates in pixels.
mouthXOff = 158
mouthYOff = 395
love.graphics.setBackgroundColor( bgRed,bgGreen,bgBlue,bgBrightness )
love.graphics.setDefaultFilter( filterMode, filterMode, anistropy )
-- loading our defult images into the code
body = love.graphics.newImage("body.png")
face = love.graphics.newImage("face.png")
nose = love.graphics.newImage("nose.png")
hair = love.graphics.newImage("hair.png")
openmouth = love.graphics.newImage("openmouth.png")
neutralMouth = love.graphics.newImage("neutralMouth.png")
happyMouth = love.graphics.newImage("happyMouth.png")
sadMouth = love.graphics.newImage("sadMouth.png")
angryMouth = love.graphics.newImage("angryMouth.png")
scaredMouth = love.graphics.newImage("scaredMouth.png")
neutralEyes = love.graphics.newImage("neutralEyes.png")
happyEyes = love.graphics.newImage("happyEyes.png")
sadEyes = love.graphics.newImage("sadEyes.png")
angryEyes = love.graphics.newImage("angryEyes.png")
scaredEyes = love.graphics.newImage("scaredEyes.png")
--default mouths
staticMouth = neutralMouth
talkMouth = openmouth
moodEyes = neutralEyes
--Set Dimensions of window to the image
local wid,hig = face:getDimensions()
startHeight = hig
love.window.setMode(wid,hig,{resizable=true, vsync=false, minwidth=200, minheight=200})
--Shaders
effect = moonshine(2000,2000, moonshine.effects.filmgrain).chain(moonshine.effects.vignette).chain(moonshine.effects.fog).chain(moonshine.effects.boxblur).chain(moonshine.effects.chromasep).chain(moonshine.effects.colorgradesimple).chain(moonshine.effects.crt).chain(moonshine.effects.desaturate).chain(moonshine.effects.dmg).chain(moonshine.effects.fastgaussianblur).chain(moonshine.effects.gaussianblur).chain(moonshine.effects.glow).chain(moonshine.effects.godsray).chain(moonshine.effects.pixelate).chain(moonshine.effects.posterize).chain(moonshine.effects.scanlines).chain(moonshine.effects.sketch)
--Turn off by default
effect.disable("fog","filmgrain","vignette","boxblur","chromasep","colorgradesimple","crt","desaturate","dmg","fastgaussianblur","gaussianblur","glow","godsray","pixelate","posterize","scanlines","sketch")
--boxblur
effect.boxblur.radius_x = 3
effect.boxblur.radius_y = 3
--chromasep
effect.chromasep.angle = 0
effect.chromasep.radius = 0
--colorgradesimple
effect.colorgradesimple.factors = {1,1,1}
--crt
effect.crt.x = 1.06
effect.crt.y = 1.065
effect.crt.scaleFactor = {1,1}
effect.crt.feather = 0.02
--desaturate
effect.desaturate.tint = {255,255,255}
effect.desaturate.strength = 0.5
--dmg
effect.dmg.palette = "pocket"
--fastgaussianblur
effect.fastgaussianblur.taps = 7
effect.fastgaussianblur.offset = 1
effect.fastgaussianblur.sigma = -1
--filmgrain
effect.filmgrain.opacity = 0.3
effect.filmgrain.size = 1
--gaussianblur
effect.gaussianblur.sigma = 1
--glow
effect.glow.min_luma = 0.1
effect.glow.strength = 10
--godsray
effect.godsray.exposure = 0.5
effect.godsray.decay = 0.95
effect.godsray.density = 0.05
effect.godsray.weight = 0.5
effect.godsray.light_x = 0.5
effect.godsray.light_y = 0.5
effect.godsray.samples = 70
--pixelate
effect.pixelate.size = {5,5}
effect.pixelate.feedback = 0
--posterize
effect.posterize.num_bands = 3
--scanlines
effect.scanlines.width = 2
effect.scanlines.phase = 0
effect.scanlines.thickness = 1
effect.scanlines.opacity = 1
effect.scanlines.color = {0,0,0}
--sketch
effect.sketch.amp = 0.0007
effect.sketch.center = {0,0}
--vignette
effect.vignette.radius = 0.8
effect.vignette.softness = 0.5
effect.vignette.opacity = 0.5
effect.vignette.color = {0,0,0}
--fog
effect.fog.fog_color = {0.35, 0.48, 0.95}
effect.fog.octaves = 4
effect.fog.speed = {0.5,0.5}
-- Only check for custom assets if release build
if love.filesystem.isFused( ) then
loaded = 0
--load config
chunk = love.filesystem.load("Root/config.lua")
chunk()
chunk = love.filesystem.load("Root/shader.lua")
chunk()
else
loaded = 1
end
end
function love.resize(w,h)
yScale = h/startHeight
xScale = (yScale/26)*25
effect.resize(w, h)
screenHeight = h
screenWidth = w
end
function loadProps()
local dir = "Root/Custom/Props"
--assuming that our path is full of lovely files
local files = love.filesystem.getDirectoryItems(dir)
for k, file in ipairs(files) do
props[#props+1] = love.graphics.newImage(dir .."/" ..file)
propNames[#propNames+1] = file
end
end
function love.update(dt)
if loaded == 0 then
if success then
face = love.graphics.newImage("Root/Custom/face.png")
openmouth = love.graphics.newImage("Root/Custom/openmouth.png")
neutralMouth = love.graphics.newImage("Root/Custom/neutralMouth.png")
happyMouth = love.graphics.newImage("Root/Custom/happyMouth.png")
sadMouth = love.graphics.newImage("Root/Custom/sadMouth.png")
angryMouth = love.graphics.newImage("Root/Custom/angryMouth.png")
scaredMouth = love.graphics.newImage("Root/Custom/scaredMouth.png")
neutralEyes = love.graphics.newImage("Root/Custom/neutralEyes.png")
happyEyes = love.graphics.newImage("Root/Custom/happyEyes.png")
sadEyes = love.graphics.newImage("Root/Custom/sadEyes.png")
angryEyes = love.graphics.newImage("Root/Custom/AngryEyes.png")
scaredEyes = love.graphics.newImage("Root/Custom/scaredEyes.png")
--Basics
info = love.filesystem.getInfo("Root/Custom/body.png")
if info ~= nil then
body = love.graphics.newImage("Root/Custom/body.png")
end
info = love.filesystem.getInfo("Root/Custom/nose.png")
if info ~= nil then
nose = love.graphics.newImage("Root/Custom/nose.png")
end
info = love.filesystem.getInfo("Root/Custom/hair.png")
if info ~= nil then
hair = love.graphics.newImage("Root/Custom/hair.png")
end
info = love.filesystem.getInfo("Root/Custom/" ..angryEyes2path)
if info ~= nil then
angryEyes2 = love.graphics.newImage("Root/Custom/" ..angryEyes2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..angryMouth2path)
if info ~= nil then
angryMouth2 = love.graphics.newImage("Root/Custom/" ..angryMouth2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..happyEyes2path)
if info ~= nil then
happyEyes2 = love.graphics.newImage("Root/Custom/" ..happyEyes2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..happyMouth2path)
if info ~= nil then
happyMouth2 = love.graphics.newImage("Root/Custom/" ..happyMouth2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..sadEyes2path)
if info ~= nil then
sadEyes2 = love.graphics.newImage("Root/Custom/" ..sadEyes2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..sadMouth2path)
if info ~= nil then
sadMouth2 = love.graphics.newImage("Root/Custom/" ..sadMouth2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..scaredEyes2path)
if info ~= nil then
scaredEyes2 = love.graphics.newImage("Root/Custom/" ..scaredEyes2path)
end
info = love.filesystem.getInfo("Root/Custom/" ..scaredMouth2path)
if info ~= nil then
scaredMouth2 = love.graphics.newImage("Root/Custom/" ..scaredMouth2path)
end
--Mouth Extras
info = love.filesystem.getInfo("Root/Custom/" ..openangryMouthpath)
if info ~= nil then
openangryMouth = love.graphics.newImage("Root/Custom/" ..openangryMouthpath)
end
info = love.filesystem.getInfo("Root/Custom/" ..openhappyMouthpath)
if info ~= nil then
openhappyMouth = love.graphics.newImage("Root/Custom/" ..openhappyMouthpath)
end
info = love.filesystem.getInfo("Root/Custom/" ..openscaredMouthpath)
if info ~= nil then
openscaredMouth = love.graphics.newImage("Root/Custom/" ..openscaredMouthpath)
end
info = love.filesystem.getInfo("Root/Custom/" ..opensadMouthpath)
if info ~= nil then
opensadMouth = love.graphics.newImage("Root/Custom/" ..opensadMouthpath)
end
--Prop
if enableProp == true then
loadProps()
end
loaded = 1
else
loaded = 2
end
local wid,hig = face:getDimensions()
startHeight = hig
love.window.setMode(wid,hig,{resizable=true, vsync=false, minwidth=200, minheight=200})
end
-- Set up Bobble Animation to only adjust every 40 ticks so as not to overload the cpu
tick = tick + 1
if tick > 20 then
tick = 0
if volume >= noisecap/2 and volume < noisecap then
rotation = rotation + (math.random(-bobbleConstant*100,bobbleConstant*100)/100)
end
--Double the bobble when louder.
if volume >= noisecap then
rotation = rotation + (math.random(-bobbleConstant*200,bobbleConstant*200)/100)
end
-- slowly reset head to default position when not talking.
if volume == 0 then
if rotation > 0 then
rotation = rotation - bobbleConstant
end
if rotation < 0 then
rotation = rotation + bobbleConstant
end
end
end
end
function love.draw()
if recording == 1 then
getSample()
end
local noisediff = noisecap - noisegate
effect(function()
-- Make sure to layer your pieces properly, Bottom layer first.
--Body
love.graphics.draw(body, 0+mouthXOff*xScale, 0+mouthYOff*yScale,0,xScale,yScale, mouthXOff, mouthYOff)
--Face
love.graphics.draw(face, 0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
--Hair
if hair ~= nil then
love.graphics.draw(hair, 0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
end
--Nose
if nose ~= nil then
love.graphics.draw(nose, 0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
end
--Draw a mouth based on mood variable
if mood == "neutral" then
staticMouth = neutralMouth
talkMouth = openmouth
elseif mood == "happy" then
staticMouth = happyMouth
if openhappyMouth ~= nil then
talkMouth = openhappyMouth
else
talkMouth = openmouth
end
elseif mood == "sad" then
staticMouth = sadMouth
if opensadMouth ~= nil then
talkMouth = opensadMouth
else
talkMouth = openmouth
end
elseif mood == "scared" then
staticMouth = scaredMouth
if openscaredMouth ~= nil then
talkMouth = openscaredMouth
else
talkMouth = openmouth
end
elseif mood == "angry" then
staticMouth = angryMouth
if openangryMouth ~= nil then
talkMouth = openangryMouth
else
talkMouth = openmouth
end
elseif mood == "happy2" then
if happyMouth2 ~= nil then
staticMouth = happyMouth2
else
staticMouth = happyMouth
end
if openhappyMouth ~= nil then
talkMouth = openhappyMouth
else
talkMouth = openmouth
end
elseif mood == "sad2" then
if sadMouth2 ~= nil then
staticMouth = sadMouth2
else
staticMouth = sadMouth
end
if opensadMouth ~= nil then
talkMouth = opensadMouth
else
talkMouth = openmouth
end
elseif mood == "scared2" then
if scaredMouth2 ~= nil then
staticMouth = scaredMouth2
else
staticMouth = scaredMouth
end
if openscaredMouth ~= nil then
talkMouth = openscaredMouth
else
talkMouth = openmouth
end
elseif mood == "angry2" then
if angryMouth2 ~= nil then
staticMouth = angryMouth2
else
staticMouth = angryMouth
end
if openangryMouth ~= nil then
talkMouth = openangryMouth
else
talkMouth = openmouth
end
end
if volume == 0 then
love.graphics.draw(staticMouth,0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
-- swap it for an open one when talking, and scale based on the loudness.
elseif volume <= noisecap then
love.graphics.draw(talkMouth, 0+mouthXOff*xScale, 0+mouthYOff*yScale, rotation, (xScale * 1), (yScale * (volume/noisediff)*2), mouthXOff, mouthYOff)
else
love.graphics.draw(talkMouth, 0+mouthXOff*xScale, 0+mouthYOff*yScale, rotation, (xScale * 0.85), (yScale * 2), mouthXOff, mouthYOff)
end
if mood == "neutral" then
moodEyes = neutralEyes
elseif mood == "happy" then
moodEyes = happyEyes
elseif mood == "sad" then
moodEyes = sadEyes
elseif mood == "scared" then
moodEyes = scaredEyes
elseif mood == "angry" then
moodEyes = angryEyes
elseif mood == "happy2" then
moodEyes = happyEyes2
elseif mood == "sad2" then
moodEyes = sadEyes2
elseif mood == "scared2" then
moodEyes = scaredEyes2
elseif mood == "angry2" then
moodEyes = angryEyes2
end
love.graphics.draw(moodEyes,0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
--Draw Prop over everything else
if enableProp == true and propToggle == true then
love.graphics.draw(props[prop],0+mouthXOff*xScale, 0+mouthYOff*yScale,rotation,xScale,yScale, mouthXOff, mouthYOff)
end
end)
if hidden == 0 then
drawMicControls()
if enableProp == true then
love.graphics.print(propNames[prop], 180, 13)
end
end
end
function love.keypressed(key)
--Mood toggling
if key == moodUpKey then
if mood == "sad" then
mood = "neutral"
elseif mood == "sad2" then
mood = "sad"
elseif mood == "neutral" then
mood = "happy"
elseif mood == "happy" and happyEyes2 ~= nil then
mood = "happy2"
elseif mood == "happy2" then
mood = "happy2"
else
mood = "happy"
end
end
if key == moodDownKey then
if mood == "happy" then
mood = "neutral"
elseif mood == "happy2" then
mood = "happy"
elseif mood == "neutral" then
mood = "sad"
elseif mood == "sad" and sadEyes2 ~= nil then
mood = "sad2"
elseif mood == "sad2" then
mood = "sad2"
else
mood = "sad"
end
end
if key == moodRightKey then
if mood == "scared" then
mood = "neutral"
elseif mood == "scared2" then
mood = "scared"
elseif mood == "neutral" then
mood = "angry"
elseif mood == "angry" and angryEyes2 ~= nil then
mood = "angry2"
elseif mood == "angry2" then
mood = "angry2"
else
mood = "angry"
end
end
if key == moodLeftKey then
if mood == "angry" then
mood = "neutral"
elseif mood == "angry2" then
mood = "angry"
elseif mood == "neutral" then
mood = "scared"
elseif mood == "scared" and scaredEyes2 ~= nil then
mood = "scared2"
elseif mood == "scared2" then
mood = "scared2"
else
mood = "scared"
end
end
if key == moodResetKey then
mood = "neutral"
end
if key == nextPropKey then
prop = prop + 1
if prop > #props then
prop = 1
end
end
if key == lastPropKey then
prop = prop - 1
if prop < 1 then
prop = #props
end
end
if key == togglePropKey then
if propToggle == true then
propToggle = false
else
propToggle = true
end
end
micControls(key)
end