aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/bluebey-studio/src/animation.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/bluebey-studio/src/animation.js')
-rw-r--r--public/bluebey-studio/src/animation.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/public/bluebey-studio/src/animation.js b/public/bluebey-studio/src/animation.js
index 3233e43..e569d12 100644
--- a/public/bluebey-studio/src/animation.js
+++ b/public/bluebey-studio/src/animation.js
@@ -17,6 +17,7 @@ export class Animator {
this.eyeOpen = 1;
this.look = { x: 0, y: 0 };
this.idleWeight = 0;
+ this.snotScale = 1;
}
reset() {
@@ -25,6 +26,7 @@ export class Animator {
this.blinkPhase = -1;
this.blinkTimer = 2;
this.time = 0;
+ this.snotScale = 1;
}
update(dt) {
@@ -35,11 +37,24 @@ export class Animator {
const moving = (this.state.anim.mode ?? 'off') !== 'off';
this.idleWeight += ((moving ? 1 : 0) - this.idleWeight) * Math.min(1, step * 4);
+ // 鼻ちょうちん: while sleeping, the bubble swells on the out-breath and shrinks
+ // again. It is a real object (see src/main.js), so the motion is published here
+ // as a plain multiplier the render loop applies to the bubble's scale.
+ this.snotScale = (this.state.anim.mode ?? 'off') === 'sleep'
+ ? 0.45 + 0.55 * (0.5 - 0.5 * Math.cos(this.time * 1.3))
+ : 1;
+
this.updateBlink(step);
this.updateLook(step);
}
updateBlink(dt) {
+ if ((this.state.anim.mode ?? 'off') === 'sleep') {
+ // Asleep: the eyes stay shut, whatever the blink setting says.
+ this.eyeOpen = 0;
+ this.blinkPhase = -1;
+ return;
+ }
if (!this.state.anim.blink) {
this.eyeOpen = 1;
this.blinkPhase = -1;
@@ -128,6 +143,17 @@ export class Animator {
return { bones, root };
}
+ if (mode === 'sleep') {
+ // Slow breathing: the body rises and settles, the flippers drift, and the
+ // bubble swells and shrinks (that swell is `snotScale`, read by the loop).
+ const breath = 0.5 - 0.5 * Math.cos(t * 1.3);
+ add('master', Math.sin(t * 0.65) * 1.1, 0, 0);
+ add('arm.l', 0, 0, Math.sin(t * 0.9) * 2.5);
+ add('arm.r', 0, 0, -Math.sin(t * 0.9) * 2.5);
+ root[1] += breath * 0.03;
+ return { bones, root };
+ }
+
// Default: gentle breathing, as if standing there alive.
add('master', Math.sin(t * 1.5) * 1.3, 0, Math.sin(t * 0.81) * 1.6);
add('arm.l', 0, 0, Math.sin(t * 1.28) * 4.5);